Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions cbor/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package cbor

import (
"bytes"
"errors"
"fmt"
"math"
"reflect"
Expand Down Expand Up @@ -53,7 +54,7 @@ func DecodeIdFromList(cborData []byte) (int, error) {
return 0, err
}
if listLen == 0 {
return 0, fmt.Errorf("cannot return first item from empty list")
return 0, errors.New("cannot return first item from empty list")
}
if listLen < int(CborMaxUintSimple) {
if cborData[1] <= CborMaxUintSimple {
Expand All @@ -70,7 +71,7 @@ func DecodeIdFromList(cborData []byte) (int, error) {
// The upstream CBOR library uses uint64 by default for numeric values
case uint64:
if v > uint64(math.MaxInt) {
return 0, fmt.Errorf("decoded numeric value too large: uint64 > int")
return 0, errors.New("decoded numeric value too large: uint64 > int")
}
return int(v), nil
default:
Expand Down Expand Up @@ -133,7 +134,7 @@ func DecodeGeneric(cborData []byte, dest interface{}) error {
// destination object
if valueDest.Kind() != reflect.Pointer ||
valueDest.Elem().Kind() != reflect.Struct {
return fmt.Errorf("destination must be a pointer to a struct")
return errors.New("destination must be a pointer to a struct")
}
destTypeFields := []reflect.StructField{}
for i := 0; i < typeDest.NumField(); i++ {
Expand Down
6 changes: 3 additions & 3 deletions cbor/encode.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 Blink Labs Software
// Copyright 2025 Blink Labs Software
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -16,7 +16,7 @@ package cbor

import (
"bytes"
"fmt"
"errors"
"reflect"
"sync"

Expand Down Expand Up @@ -58,7 +58,7 @@ func EncodeGeneric(src interface{}) ([]byte, error) {
// source object
if valueSrc.Kind() != reflect.Pointer ||
valueSrc.Elem().Kind() != reflect.Struct {
return nil, fmt.Errorf("source must be a pointer to a struct")
return nil, errors.New("source must be a pointer to a struct")
}
srcTypeFields := []reflect.StructField{}
for i := 0; i < typeSrc.NumField(); i++ {
Expand Down
7 changes: 4 additions & 3 deletions cbor/tags.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 Blink Labs Software
// Copyright 2025 Blink Labs Software
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -15,6 +15,7 @@
package cbor

import (
"errors"
"fmt"
"math/big"
"reflect"
Expand Down Expand Up @@ -132,15 +133,15 @@ func (r *Rat) MarshalCBOR() ([]byte, error) {
} else if r.Num().IsInt64() {
tmpContent[0] = r.Num().Int64()
} else {
return nil, fmt.Errorf("numerator cannot be represented at int64/uint64")
return nil, errors.New("numerator cannot be represented at int64/uint64")
}
// Denominator
if r.Denom().IsUint64() {
tmpContent[1] = r.Denom().Uint64()
} else if r.Denom().IsInt64() {
tmpContent[1] = r.Denom().Int64()
} else {
return nil, fmt.Errorf("numerator cannot be represented at int64/uint64")
return nil, errors.New("numerator cannot be represented at int64/uint64")
}
tmpData := _cbor.Tag{
Number: CborTagRational,
Expand Down
5 changes: 3 additions & 2 deletions cmd/gouroboros/chainsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package main

import (
"encoding/hex"
"errors"
"flag"
"fmt"
"os"
Expand Down Expand Up @@ -266,7 +267,7 @@ func chainSyncRollForwardHandler(
blockHash, _ := hex.DecodeString(v.Hash())
var err error
if oConn == nil {
return fmt.Errorf("empty ouroboros connection, aborting!")
return errors.New("empty ouroboros connection, aborting!")
}
block, err = oConn.BlockFetch().Client.GetBlock(common.NewPoint(blockSlot, blockHash))
if err != nil {
Expand All @@ -293,7 +294,7 @@ func chainSyncRollForwardHandler(
)
default:
if block == nil {
return fmt.Errorf("block is nil")
return errors.New("block is nil")
}
fmt.Printf(
"era = %s, slot = %d, block_no = %d, id = %s\n",
Expand Down
5 changes: 3 additions & 2 deletions cmd/gouroboros/server.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 Blink Labs Software
// Copyright 2025 Blink Labs Software
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -15,6 +15,7 @@
package main

import (
"errors"
"flag"
"fmt"
"net"
Expand Down Expand Up @@ -55,7 +56,7 @@ func createListenerSocket(f *globalFlags) (net.Listener, error) {
return nil, fmt.Errorf("failed to open listening socket: %w", err)
}
default:
return nil, fmt.Errorf("no listening address or socket specified")
return nil, errors.New("no listening address or socket specified")
}

return listen, nil
Expand Down
4 changes: 2 additions & 2 deletions connection.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 Blink Labs Software
// Copyright 2025 Blink Labs Software
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -158,7 +158,7 @@ func (c *Connection) DialTimeout(
timeout time.Duration,
) error {
if c.conn != nil {
return fmt.Errorf("a connection was already established")
return errors.New("a connection was already established")
}
conn, err := net.DialTimeout(proto, address, timeout)
if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions ledger/allegra/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package allegra

import (
"fmt"
"errors"

"github.com/blinklabs-io/gouroboros/ledger/common"
"github.com/blinklabs-io/gouroboros/ledger/shelley"
Expand Down Expand Up @@ -68,7 +68,7 @@ func UtxoValidateFeeTooSmallUtxo(
) error {
tmpPparams, ok := pp.(*AllegraProtocolParameters)
if !ok {
return fmt.Errorf("pparams are not expected type")
return errors.New("pparams are not expected type")
}
return shelley.UtxoValidateFeeTooSmallUtxo(
tx,
Expand Down Expand Up @@ -113,7 +113,7 @@ func UtxoValidateValueNotConservedUtxo(
) error {
tmpPparams, ok := pp.(*AllegraProtocolParameters)
if !ok {
return fmt.Errorf("pparams are not expected type")
return errors.New("pparams are not expected type")
}
return shelley.UtxoValidateValueNotConservedUtxo(
tx,
Expand All @@ -131,7 +131,7 @@ func UtxoValidateOutputTooSmallUtxo(
) error {
tmpPparams, ok := pp.(*AllegraProtocolParameters)
if !ok {
return fmt.Errorf("pparams are not expected type")
return errors.New("pparams are not expected type")
}
return shelley.UtxoValidateOutputTooSmallUtxo(
tx,
Expand All @@ -158,7 +158,7 @@ func UtxoValidateMaxTxSizeUtxo(
) error {
tmpPparams, ok := pp.(*AllegraProtocolParameters)
if !ok {
return fmt.Errorf("pparams are not expected type")
return errors.New("pparams are not expected type")
}
return shelley.UtxoValidateMaxTxSizeUtxo(
tx,
Expand Down
3 changes: 2 additions & 1 deletion ledger/babbage/babbage.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package babbage
import (
"encoding/hex"
"encoding/json"
"errors"
"fmt"

"github.com/blinklabs-io/gouroboros/cbor"
Expand Down Expand Up @@ -355,7 +356,7 @@ func (d *BabbageTransactionOutputDatumOption) MarshalCBOR() ([]byte, error) {
} else if d.data != nil {
tmpObj = []interface{}{DatumOptionTypeData, cbor.Tag{Number: 24, Content: d.data.Cbor()}}
} else {
return nil, fmt.Errorf("unknown datum option type")
return nil, errors.New("unknown datum option type")
}
return cbor.Encode(&tmpObj)
}
Expand Down
5 changes: 3 additions & 2 deletions ledger/block.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 Blink Labs Software
// Copyright 2025 Blink Labs Software
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -15,6 +15,7 @@
package ledger

import (
"errors"
"fmt"

"github.com/blinklabs-io/gouroboros/ledger/common"
Expand Down Expand Up @@ -86,5 +87,5 @@ func DetermineBlockType(data []byte) (uint, error) {
if _, err := NewConwayBlockFromCbor(data); err == nil {
return BlockTypeConway, nil
}
return 0, fmt.Errorf("unknown block type")
return 0, errors.New("unknown block type")
}
3 changes: 2 additions & 1 deletion ledger/byron/byron.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package byron

import (
"encoding/hex"
"errors"
"fmt"
"math"

Expand Down Expand Up @@ -342,7 +343,7 @@ func (i *ByronTransactionInput) UnmarshalCBOR(data []byte) error {
}
default:
// [u8 .ne 0, encoded-cbor]
return fmt.Errorf("can't parse yet")
return errors.New("can't parse yet")
}
return nil
}
Expand Down
15 changes: 5 additions & 10 deletions ledger/common/address.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 Blink Labs Software
// Copyright 2025 Blink Labs Software
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -15,6 +15,7 @@
package common

import (
"errors"
"fmt"
"hash/crc32"
"strings"
Expand Down Expand Up @@ -182,24 +183,18 @@ func (a *Address) populateFromBytes(data []byte) error {
}
payloadBytes, ok := rawAddr.Payload.Content.([]byte)
if !ok || rawAddr.Payload.Number != 24 {
return fmt.Errorf(
"invalid Byron address data: unexpected payload content",
)
return errors.New("invalid Byron address data: unexpected payload content")
}
payloadChecksum := crc32.ChecksumIEEE(payloadBytes)
if rawAddr.Checksum != payloadChecksum {
return fmt.Errorf(
"invalid Byron address data: checksum does not match",
)
return errors.New("invalid Byron address data: checksum does not match")
}
var byronAddr byronAddressPayload
if _, err := cbor.Decode(payloadBytes, &byronAddr); err != nil {
return err
}
if len(byronAddr.Hash) != AddressHashSize {
return fmt.Errorf(
"invalid Byron address data: hash is not expected length",
)
return errors.New("invalid Byron address data: hash is not expected length")
}
a.byronAddressType = byronAddr.AddrType
a.byronAddressAttr = byronAddr.Attr
Expand Down
3 changes: 2 additions & 1 deletion ledger/common/certs.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package common

import (
"errors"
"fmt"
"net"

Expand Down Expand Up @@ -461,7 +462,7 @@ func (r *MoveInstantaneousRewardsCertificateReward) UnmarshalCBOR(
r.Source = tmpMapData.Source
return nil
}
return fmt.Errorf("failed to decode as known types")
return errors.New("failed to decode as known types")
}

type MoveInstantaneousRewardsCertificate struct {
Expand Down
5 changes: 3 additions & 2 deletions ledger/common/nonce.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 Blink Labs Software
// Copyright 2025 Blink Labs Software
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -16,6 +16,7 @@ package common

import (
"encoding/json"
"errors"
"fmt"
"slices"

Expand Down Expand Up @@ -60,7 +61,7 @@ func (n *Nonce) UnmarshalJSON(data []byte) error {
}
tag, ok := tmpData["tag"]
if !ok {
return fmt.Errorf("did not find expected key 'tag' for nonce")
return errors.New("did not find expected key 'tag' for nonce")
}
switch tag {
case "NeutralNonce":
Expand Down
Loading