diff --git a/cbor/decode.go b/cbor/decode.go index a41f54cc..4e31b91d 100644 --- a/cbor/decode.go +++ b/cbor/decode.go @@ -16,6 +16,7 @@ package cbor import ( "bytes" + "errors" "fmt" "math" "reflect" @@ -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 { @@ -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: @@ -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++ { diff --git a/cbor/encode.go b/cbor/encode.go index 74484f96..a664c996 100644 --- a/cbor/encode.go +++ b/cbor/encode.go @@ -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. @@ -16,7 +16,7 @@ package cbor import ( "bytes" - "fmt" + "errors" "reflect" "sync" @@ -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++ { diff --git a/cbor/tags.go b/cbor/tags.go index 02e9310e..6d4cca59 100644 --- a/cbor/tags.go +++ b/cbor/tags.go @@ -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. @@ -15,6 +15,7 @@ package cbor import ( + "errors" "fmt" "math/big" "reflect" @@ -132,7 +133,7 @@ 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() { @@ -140,7 +141,7 @@ func (r *Rat) MarshalCBOR() ([]byte, error) { } 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, diff --git a/cmd/gouroboros/chainsync.go b/cmd/gouroboros/chainsync.go index 33f91153..6e6b8236 100644 --- a/cmd/gouroboros/chainsync.go +++ b/cmd/gouroboros/chainsync.go @@ -16,6 +16,7 @@ package main import ( "encoding/hex" + "errors" "flag" "fmt" "os" @@ -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 { @@ -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", diff --git a/cmd/gouroboros/server.go b/cmd/gouroboros/server.go index 901465b9..93f82ccc 100644 --- a/cmd/gouroboros/server.go +++ b/cmd/gouroboros/server.go @@ -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. @@ -15,6 +15,7 @@ package main import ( + "errors" "flag" "fmt" "net" @@ -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 diff --git a/connection.go b/connection.go index ca5314ce..e73cc709 100644 --- a/connection.go +++ b/connection.go @@ -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. @@ -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 { diff --git a/ledger/allegra/rules.go b/ledger/allegra/rules.go index 5af2b6bf..a53000d2 100644 --- a/ledger/allegra/rules.go +++ b/ledger/allegra/rules.go @@ -15,7 +15,7 @@ package allegra import ( - "fmt" + "errors" "github.com/blinklabs-io/gouroboros/ledger/common" "github.com/blinklabs-io/gouroboros/ledger/shelley" @@ -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, @@ -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, @@ -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, @@ -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, diff --git a/ledger/babbage/babbage.go b/ledger/babbage/babbage.go index 7cf62c38..90d00d6b 100644 --- a/ledger/babbage/babbage.go +++ b/ledger/babbage/babbage.go @@ -17,6 +17,7 @@ package babbage import ( "encoding/hex" "encoding/json" + "errors" "fmt" "github.com/blinklabs-io/gouroboros/cbor" @@ -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) } diff --git a/ledger/block.go b/ledger/block.go index 3c80fa26..0bee4623 100644 --- a/ledger/block.go +++ b/ledger/block.go @@ -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. @@ -15,6 +15,7 @@ package ledger import ( + "errors" "fmt" "github.com/blinklabs-io/gouroboros/ledger/common" @@ -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") } diff --git a/ledger/byron/byron.go b/ledger/byron/byron.go index 77ca9177..00562fa2 100644 --- a/ledger/byron/byron.go +++ b/ledger/byron/byron.go @@ -16,6 +16,7 @@ package byron import ( "encoding/hex" + "errors" "fmt" "math" @@ -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 } diff --git a/ledger/common/address.go b/ledger/common/address.go index 9967d64a..f7ac3adc 100644 --- a/ledger/common/address.go +++ b/ledger/common/address.go @@ -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. @@ -15,6 +15,7 @@ package common import ( + "errors" "fmt" "hash/crc32" "strings" @@ -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 diff --git a/ledger/common/certs.go b/ledger/common/certs.go index fb99a9c7..6bdacc1e 100644 --- a/ledger/common/certs.go +++ b/ledger/common/certs.go @@ -15,6 +15,7 @@ package common import ( + "errors" "fmt" "net" @@ -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 { diff --git a/ledger/common/nonce.go b/ledger/common/nonce.go index 481c65e8..453375b6 100644 --- a/ledger/common/nonce.go +++ b/ledger/common/nonce.go @@ -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. @@ -16,6 +16,7 @@ package common import ( "encoding/json" + "errors" "fmt" "slices" @@ -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": diff --git a/ledger/error.go b/ledger/error.go index 3677550e..640bc95c 100644 --- a/ledger/error.go +++ b/ledger/error.go @@ -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. @@ -15,6 +15,7 @@ package ledger import ( + "errors" "fmt" "github.com/blinklabs-io/gouroboros/cbor" @@ -115,7 +116,7 @@ func NewTxSubmitErrorFromCbor(cborData []byte) (error, error) { return newErr, nil } } - return nil, fmt.Errorf("failed to parse error as any known types") + return nil, errors.New("failed to parse error as any known types") } func NewShelleyTxValidationErrorFromCbor(cborData []byte) (error, error) { @@ -199,10 +200,10 @@ func (e *ApplyTxError) Error() string { for idx, failure := range e.Failures { ret = fmt.Sprintf("%s%s", ret, failure) if idx < (len(e.Failures) - 1) { - ret = fmt.Sprintf("%s, ", ret) + ret = ret + ", " } } - ret = fmt.Sprintf("%s])", ret) + ret = ret + "])" return ret } @@ -314,10 +315,10 @@ func (e *BadInputsUtxo) Error() string { for idx, input := range e.Inputs { ret = fmt.Sprintf("%s%s", ret, input.String()) if idx < (len(e.Inputs) - 1) { - ret = fmt.Sprintf("%s, ", ret) + ret = ret + ", " } } - ret = fmt.Sprintf("%s])", ret) + ret = ret + "])" return ret } @@ -407,10 +408,10 @@ func (e *OutputTooSmallUtxo) Error() string { for idx, output := range e.Outputs { ret = fmt.Sprintf("%s%s", ret, output.String()) if idx < (len(e.Outputs) - 1) { - ret = fmt.Sprintf("%s, ", ret) + ret = ret + ", " } } - ret = fmt.Sprintf("%s])", ret) + ret = ret + "])" return ret } @@ -469,10 +470,10 @@ func (e *OutputBootAddrAttrsTooBig) Error() string { for idx, output := range e.Outputs { ret = fmt.Sprintf("%s%s", ret, output.String()) if idx < (len(e.Outputs) - 1) { - ret = fmt.Sprintf("%s, ", ret) + ret = ret + ", " } } - ret = fmt.Sprintf("%s])", ret) + ret = ret + "])" return ret } @@ -504,10 +505,10 @@ func (e *OutputTooBigUtxo) Error() string { output.Output.String(), ) if idx < (len(e.Outputs) - 1) { - ret = fmt.Sprintf("%s, ", ret) + ret = ret + ", " } } - ret = fmt.Sprintf("%s])", ret) + ret = ret + "])" return ret } diff --git a/ledger/mary/errors.go b/ledger/mary/errors.go index aaca09f0..e25554a1 100644 --- a/ledger/mary/errors.go +++ b/ledger/mary/errors.go @@ -30,8 +30,5 @@ func (e OutputTooBigUtxoError) Error() string { for idx, tmpOutput := range e.Outputs { tmpOutputs[idx] = fmt.Sprintf("%#v", tmpOutput) } - return fmt.Sprintf( - "output value too large: %s", - strings.Join(tmpOutputs, ", "), - ) + return "output value too large: " + strings.Join(tmpOutputs, ", ") } diff --git a/ledger/mary/rules.go b/ledger/mary/rules.go index 8635cdbc..7a79800e 100644 --- a/ledger/mary/rules.go +++ b/ledger/mary/rules.go @@ -15,7 +15,7 @@ package mary import ( - "fmt" + "errors" "github.com/blinklabs-io/gouroboros/cbor" "github.com/blinklabs-io/gouroboros/ledger/allegra" @@ -52,7 +52,7 @@ func UtxoValidateOutputTooBigUtxo( for _, txOutput := range tx.Outputs() { tmpOutput, ok := txOutput.(*MaryTransactionOutput) if !ok { - return fmt.Errorf("transaction output is not expected type") + return errors.New("transaction output is not expected type") } outputValBytes, err := cbor.Encode(tmpOutput.OutputAmount) if err != nil { @@ -97,7 +97,7 @@ func UtxoValidateFeeTooSmallUtxo( ) error { tmpPparams, ok := pp.(*MaryProtocolParameters) if !ok { - return fmt.Errorf("pparams are not expected type") + return errors.New("pparams are not expected type") } return shelley.UtxoValidateFeeTooSmallUtxo( tx, @@ -142,7 +142,7 @@ func UtxoValidateValueNotConservedUtxo( ) error { tmpPparams, ok := pp.(*MaryProtocolParameters) if !ok { - return fmt.Errorf("pparams are not expected type") + return errors.New("pparams are not expected type") } return shelley.UtxoValidateValueNotConservedUtxo( tx, @@ -160,7 +160,7 @@ func UtxoValidateOutputTooSmallUtxo( ) error { tmpPparams, ok := pp.(*MaryProtocolParameters) if !ok { - return fmt.Errorf("pparams are not expected type") + return errors.New("pparams are not expected type") } return shelley.UtxoValidateOutputTooSmallUtxo( tx, @@ -187,7 +187,7 @@ func UtxoValidateMaxTxSizeUtxo( ) error { tmpPparams, ok := pp.(*MaryProtocolParameters) if !ok { - return fmt.Errorf("pparams are not expected type") + return errors.New("pparams are not expected type") } return shelley.UtxoValidateMaxTxSizeUtxo( tx, diff --git a/ledger/shelley/errors.go b/ledger/shelley/errors.go index a21457c6..0e69c6f7 100644 --- a/ledger/shelley/errors.go +++ b/ledger/shelley/errors.go @@ -62,10 +62,7 @@ func (e BadInputsUtxoError) Error() string { for idx, tmpInput := range e.Inputs { tmpInputs[idx] = tmpInput.String() } - return fmt.Sprintf( - "bad input(s): %s", - strings.Join(tmpInputs, ", "), - ) + return "bad input(s): " + strings.Join(tmpInputs, ", ") } type WrongNetworkError struct { @@ -78,10 +75,7 @@ func (e WrongNetworkError) Error() string { for idx, tmpAddr := range e.Addrs { tmpAddrs[idx] = tmpAddr.String() } - return fmt.Sprintf( - "wrong network: %s", - strings.Join(tmpAddrs, ", "), - ) + return "wrong network: " + strings.Join(tmpAddrs, ", ") } type WrongNetworkWithdrawalError struct { @@ -94,10 +88,7 @@ func (e WrongNetworkWithdrawalError) Error() string { for idx, tmpAddr := range e.Addrs { tmpAddrs[idx] = tmpAddr.String() } - return fmt.Sprintf( - "wrong network withdrawals: %s", - strings.Join(tmpAddrs, ", "), - ) + return "wrong network withdrawals: " + strings.Join(tmpAddrs, ", ") } type ValueNotConservedUtxoError struct { @@ -122,10 +113,7 @@ func (e OutputTooSmallUtxoError) Error() string { for idx, tmpOutput := range e.Outputs { tmpOutputs[idx] = fmt.Sprintf("%#v", tmpOutput) } - return fmt.Sprintf( - "output too small: %s", - strings.Join(tmpOutputs, ", "), - ) + return "output too small: " + strings.Join(tmpOutputs, ", ") } type OutputBootAddrAttrsTooBigError struct { @@ -137,10 +125,7 @@ func (e OutputBootAddrAttrsTooBigError) Error() string { for idx, tmpOutput := range e.Outputs { tmpOutputs[idx] = fmt.Sprintf("%#v", tmpOutput) } - return fmt.Sprintf( - "output bootstrap address attributes too big: %s", - strings.Join(tmpOutputs, ", "), - ) + return "output bootstrap address attributes too big: " + strings.Join(tmpOutputs, ", ") } type MaxTxSizeUtxoError struct { diff --git a/ledger/shelley/rules.go b/ledger/shelley/rules.go index 17621c72..ef924eb3 100644 --- a/ledger/shelley/rules.go +++ b/ledger/shelley/rules.go @@ -15,7 +15,7 @@ package shelley import ( - "fmt" + "errors" "github.com/blinklabs-io/gouroboros/cbor" common "github.com/blinklabs-io/gouroboros/ledger/common" @@ -257,7 +257,7 @@ func UtxoValidateMaxTxSizeUtxo( ) error { tmpPparams, ok := pp.(*ShelleyProtocolParameters) if !ok { - return fmt.Errorf("pparams are not expected type") + return errors.New("pparams are not expected type") } txBytes, err := cbor.Encode(tx) if err != nil { @@ -279,7 +279,7 @@ func MinFeeTx( ) (uint64, error) { tmpPparams, ok := pparams.(*ShelleyProtocolParameters) if !ok { - return 0, fmt.Errorf("pparams are not expected type") + return 0, errors.New("pparams are not expected type") } txBytes := tx.Cbor() minFee := uint64( @@ -295,7 +295,7 @@ func MinCoinTxOut( ) (uint64, error) { tmpPparams, ok := pparams.(*ShelleyProtocolParameters) if !ok { - return 0, fmt.Errorf("pparams are not expected type") + return 0, errors.New("pparams are not expected type") } minCoinTxOut := uint64(tmpPparams.MinUtxoValue) return minCoinTxOut, nil diff --git a/ledger/shelley/shelley.go b/ledger/shelley/shelley.go index 8a923700..e15da7b7 100644 --- a/ledger/shelley/shelley.go +++ b/ledger/shelley/shelley.go @@ -16,6 +16,7 @@ package shelley import ( "encoding/hex" + "errors" "fmt" "math" @@ -377,7 +378,7 @@ func (s *ShelleyTransactionInputSet) UnmarshalCBOR(data []byte) error { // This is needed to prevent Conway+ TXs from being decoded as an earlier type var tmpTag cbor.RawTag if _, err := cbor.Decode(data, &tmpTag); err == nil { - return fmt.Errorf("did not expect CBOR tag") + return errors.New("did not expect CBOR tag") } var tmpData []ShelleyTransactionInput if _, err := cbor.Decode(data, &tmpData); err != nil { diff --git a/ledger/tx.go b/ledger/tx.go index a9f77c8a..c39c94a8 100644 --- a/ledger/tx.go +++ b/ledger/tx.go @@ -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. @@ -15,6 +15,7 @@ package ledger import ( + "errors" "fmt" "github.com/blinklabs-io/gouroboros/ledger/common" @@ -53,7 +54,7 @@ func NewTransactionBodyFromCbor( ) (TransactionBody, error) { switch txType { case TxTypeByron: - return nil, fmt.Errorf("Byron transactions do not contain a body") + return nil, errors.New("Byron transactions do not contain a body") case TxTypeShelley: return NewShelleyTransactionBodyFromCbor(data) case TxTypeAllegra: @@ -86,7 +87,7 @@ func NewTransactionOutputFromCbor(data []byte) (TransactionOutput, error) { if txOut, err := NewBabbageTransactionOutputFromCbor(data); err == nil { return txOut, nil } - return nil, fmt.Errorf("unknown transaction output type") + return nil, errors.New("unknown transaction output type") } func DetermineTransactionType(data []byte) (uint, error) { @@ -115,5 +116,5 @@ func DetermineTransactionType(data []byte) (uint, error) { if _, err := NewConwayTransactionFromCbor(data); err == nil { return TxTypeConway, nil } - return 0, fmt.Errorf("unknown transaction type") + return 0, errors.New("unknown transaction type") } diff --git a/ledger/verify_block.go b/ledger/verify_block.go index 25d9978d..c5d349be 100644 --- a/ledger/verify_block.go +++ b/ledger/verify_block.go @@ -21,6 +21,7 @@ package ledger import ( "bytes" "encoding/hex" + "errors" "fmt" "github.com/blinklabs-io/gouroboros/cbor" @@ -53,9 +54,7 @@ func VerifyBlock(block BlockHexCbor) (error, bool, string, uint64, uint64) { ), false, "", 0, 0 } if header == nil { - return fmt.Errorf( - "VerifyBlock: header returned empty", - ), false, "", 0, 0 + return errors.New("VerifyBlock: header returned empty"), false, "", 0, 0 } isKesValid, errKes := VerifyKes(header, slotPerKesPeriod) if errKes != nil { diff --git a/ledger/verify_vrf.go b/ledger/verify_vrf.go index 2a77748a..2f4dea50 100644 --- a/ledger/verify_vrf.go +++ b/ledger/verify_vrf.go @@ -22,6 +22,7 @@ import ( "crypto/sha512" "crypto/subtle" "encoding/binary" + "errors" "fmt" "filippo.io/edwards25519" @@ -67,7 +68,7 @@ func VrfVerifyAndHash( Equal(edwards25519.NewIdentityPoint()) == 1 if isSmallOrder { - return nil, fmt.Errorf("public key is a small order point") + return nil, errors.New("public key is a small order point") } // vrf_verify ok, err := vrfVerify(Y, proof, msg) @@ -75,7 +76,7 @@ func VrfVerifyAndHash( return nil, err } if !ok { - return nil, fmt.Errorf("issue verifying proof") + return nil, errors.New("issue verifying proof") } // proof to hash return cryptoVrfIetfdraft03ProofToHash(proof) @@ -178,7 +179,7 @@ func vrfIetfdraft03DecodeProof( pi []byte, ) (gamma *edwards25519.Point, c []byte, s []byte, err error) { if len(pi) != 80 { - return nil, nil, nil, fmt.Errorf("unexpected length of pi (must be 80)") + return nil, nil, nil, errors.New("unexpected length of pi (must be 80)") } /* gamma = decode_point(pi[0:32]) */ gamma = &edwards25519.Point{} diff --git a/muxer/muxer.go b/muxer/muxer.go index 31382361..e3d03055 100644 --- a/muxer/muxer.go +++ b/muxer/muxer.go @@ -218,7 +218,7 @@ func (m *Muxer) Send(msg *Segment) error { // Immediately return if we're already shutting down select { case <-m.doneChan: - return fmt.Errorf("shutting down") + return errors.New("shutting down") default: } // We use a mutex to make sure only one protocol can send at a time @@ -286,18 +286,14 @@ func (m *Muxer) readLoop() { // Check for message from initiator when we're not configured as a responder if m.diffusionMode == DiffusionModeInitiator && !msg.IsResponse() { m.sendError( - fmt.Errorf( - "received message from initiator when not configured as a responder", - ), + errors.New("received message from initiator when not configured as a responder"), ) return } // Check for message from responder when we're not configured as an initiator if m.diffusionMode == DiffusionModeResponder && msg.IsResponse() { m.sendError( - fmt.Errorf( - "received message from responder when not configured as an initiator", - ), + errors.New("received message from responder when not configured as an initiator"), ) return } diff --git a/protocol/blockfetch/client.go b/protocol/blockfetch/client.go index b3d2949f..23b1cb0e 100644 --- a/protocol/blockfetch/client.go +++ b/protocol/blockfetch/client.go @@ -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. @@ -15,6 +15,7 @@ package blockfetch import ( + "errors" "fmt" "sync" @@ -235,7 +236,7 @@ func (c *Client) handleNoBlocks() error { return protocol.ProtocolShuttingDownError default: } - err := fmt.Errorf("block(s) not found") + err := errors.New("block(s) not found") c.startBatchResultChan <- err return nil } @@ -282,9 +283,7 @@ func (c *Client) handleBlock(msgGeneric protocol.Message) error { return err } } else { - return fmt.Errorf( - "received block-fetch Block message but no callback function is defined", - ) + return errors.New("received block-fetch Block message but no callback function is defined") } } else { c.blockChan <- block diff --git a/protocol/blockfetch/server.go b/protocol/blockfetch/server.go index bd7d2f67..9f63023b 100644 --- a/protocol/blockfetch/server.go +++ b/protocol/blockfetch/server.go @@ -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. @@ -15,6 +15,7 @@ package blockfetch import ( + "errors" "fmt" "github.com/blinklabs-io/gouroboros/cbor" @@ -142,9 +143,7 @@ func (s *Server) handleRequestRange(msg protocol.Message) error { "connection_id", s.callbackContext.ConnectionId.String(), ) if s.config == nil || s.config.RequestRangeFunc == nil { - return fmt.Errorf( - "received block-fetch RequestRange message but no callback function is defined", - ) + return errors.New("received block-fetch RequestRange message but no callback function is defined") } msgRequestRange := msg.(*MsgRequestRange) return s.config.RequestRangeFunc( diff --git a/protocol/chainsync/client.go b/protocol/chainsync/client.go index 3e474564..cb8f2b61 100644 --- a/protocol/chainsync/client.go +++ b/protocol/chainsync/client.go @@ -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. @@ -16,6 +16,7 @@ package chainsync import ( "encoding/hex" + "errors" "fmt" "sync" "sync/atomic" @@ -606,9 +607,7 @@ func (c *Client) handleRollForward(msgGeneric protocol.Message) error { }() if firstBlockChan == nil && (c.config == nil || (c.config.RollForwardFunc == nil && c.config.RollForwardRawFunc == nil)) { - return fmt.Errorf( - "received chain-sync RollForward message but no callback function is defined", - ) + return errors.New("received chain-sync RollForward message but no callback function is defined") } var callbackErr error if c.Mode() == protocol.ProtocolModeNodeToNode { @@ -645,7 +644,7 @@ func (c *Client) handleRollForward(msgGeneric protocol.Message) error { } if firstBlockChan != nil { if blockHeader == nil { - err := fmt.Errorf("missing block header") + err := errors.New("missing block header") firstBlockChan <- clientPointResult{error: err} return err } @@ -692,7 +691,7 @@ func (c *Client) handleRollForward(msgGeneric protocol.Message) error { } if firstBlockChan != nil { if block == nil { - err := fmt.Errorf("missing block") + err := errors.New("missing block") firstBlockChan <- clientPointResult{error: err} return err } @@ -748,9 +747,7 @@ func (c *Client) handleRollBackward(msg protocol.Message) error { c.sendCurrentTip(msgRollBackward.Tip) if len(c.wantFirstBlockChan) == 0 { if c.config.RollBackwardFunc == nil { - return fmt.Errorf( - "received chain-sync RollBackward message but no callback function is defined", - ) + return errors.New("received chain-sync RollBackward message but no callback function is defined") } // Call the user callback function if callbackErr := c.config.RollBackwardFunc(c.callbackContext, msgRollBackward.Point, msgRollBackward.Tip); callbackErr != nil { diff --git a/protocol/chainsync/server.go b/protocol/chainsync/server.go index 311a81a0..4a9dfe0d 100644 --- a/protocol/chainsync/server.go +++ b/protocol/chainsync/server.go @@ -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. @@ -15,6 +15,7 @@ package chainsync import ( + "errors" "fmt" "github.com/blinklabs-io/gouroboros/ledger" @@ -144,7 +145,7 @@ func (s *Server) RollForward(blockType uint, blockData []byte, tip Tip) error { "role", "server", "connection_id", s.callbackContext.ConnectionId.String(), ) - return fmt.Errorf("failed to create roll forward message") + return errors.New("failed to create roll forward message") } return s.SendMessage(msg) } @@ -180,9 +181,7 @@ func (s *Server) handleRequestNext() error { // "connection_id", s.callbackContext.ConnectionId.String(), // ) if s.config == nil || s.config.RequestNextFunc == nil { - return fmt.Errorf( - "received chain-sync RequestNext message but no callback function is defined", - ) + return errors.New("received chain-sync RequestNext message but no callback function is defined") } return s.config.RequestNextFunc(s.callbackContext) } @@ -196,9 +195,7 @@ func (s *Server) handleFindIntersect(msg protocol.Message) error { "connection_id", s.callbackContext.ConnectionId.String(), ) if s.config == nil || s.config.FindIntersectFunc == nil { - return fmt.Errorf( - "received chain-sync FindIntersect message but no callback function is defined", - ) + return errors.New("received chain-sync FindIntersect message but no callback function is defined") } msgFindIntersect := msg.(*MsgFindIntersect) point, tip, err := s.config.FindIntersectFunc( diff --git a/protocol/error.go b/protocol/error.go index 97387544..08a0606e 100644 --- a/protocol/error.go +++ b/protocol/error.go @@ -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. @@ -14,8 +14,6 @@ package protocol -import ( - "fmt" -) +import "errors" -var ProtocolShuttingDownError = fmt.Errorf("protocol is shutting down") +var ProtocolShuttingDownError = errors.New("protocol is shutting down") diff --git a/protocol/handshake/client.go b/protocol/handshake/client.go index 77c5487b..61f8c75d 100644 --- a/protocol/handshake/client.go +++ b/protocol/handshake/client.go @@ -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. @@ -15,6 +15,7 @@ package handshake import ( + "errors" "fmt" "sync" @@ -108,9 +109,7 @@ func (c *Client) handleAcceptVersion(msg protocol.Message) error { "connection_id", c.callbackContext.ConnectionId.String(), ) if c.config.FinishedFunc == nil { - return fmt.Errorf( - "received handshake AcceptVersion message but no callback function is defined", - ) + return errors.New("received handshake AcceptVersion message but no callback function is defined") } msgAcceptVersion := msg.(*MsgAcceptVersion) protoVersion := protocol.GetProtocolVersion(msgAcceptVersion.Version) diff --git a/protocol/handshake/server.go b/protocol/handshake/server.go index 648500f8..0c02373f 100644 --- a/protocol/handshake/server.go +++ b/protocol/handshake/server.go @@ -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. @@ -15,6 +15,7 @@ package handshake import ( + "errors" "fmt" "sort" @@ -84,9 +85,7 @@ func (s *Server) handleProposeVersions(msg protocol.Message) error { "connection_id", s.callbackContext.ConnectionId.String(), ) if s.config.FinishedFunc == nil { - return fmt.Errorf( - "received handshake ProposeVersions message but no callback function is defined", - ) + return errors.New("received handshake ProposeVersions message but no callback function is defined") } msgProposeVersions := msg.(*MsgProposeVersions) // Compute intersection of supported and proposed protocol versions @@ -117,7 +116,7 @@ func (s *Server) handleProposeVersions(msg protocol.Message) error { if err := s.SendMessage(msgRefuse); err != nil { return err } - return fmt.Errorf("handshake failed: refused due to version mismatch") + return errors.New("handshake failed: refused due to version mismatch") } // Compute highest version from intersection var proposedVersion uint16 @@ -134,17 +133,13 @@ func (s *Server) handleProposeVersions(msg protocol.Message) error { []any{ RefuseReasonDecodeError, proposedVersion, - fmt.Errorf( - "handshake failed: refused due to empty version data", - ), + errors.New("handshake failed: refused due to empty version data"), }, ) if err := s.SendMessage(msgRefuse); err != nil { return err } - return fmt.Errorf( - "handshake failed: refused due to empty version data", - ) + return errors.New("handshake failed: refused due to empty version data") } proposedVersionData, err := versionInfo.NewVersionDataFromCborFunc( msgProposeVersions.VersionMap[proposedVersion], @@ -170,17 +165,13 @@ func (s *Server) handleProposeVersions(msg protocol.Message) error { []any{ RefuseReasonDecodeError, proposedVersion, - fmt.Errorf( - "handshake failed: refused due to empty version map", - ), + errors.New("handshake failed: refused due to empty version map"), }, ) if err := s.SendMessage(msgRefuse); err != nil { return err } - return fmt.Errorf( - "handshake failed: refused due to empty version map", - ) + return errors.New("handshake failed: refused due to empty version map") } // Check network magic diff --git a/protocol/localstatequery/client.go b/protocol/localstatequery/client.go index 6a4858ef..fc56cf9d 100644 --- a/protocol/localstatequery/client.go +++ b/protocol/localstatequery/client.go @@ -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. @@ -15,6 +15,7 @@ package localstatequery import ( + "errors" "fmt" "sync" @@ -943,7 +944,7 @@ func (c *Client) acquire(acquireTarget AcquireTarget) error { case AcquireImmutableTip: msg = NewMsgReAcquireImmutableTip() default: - return fmt.Errorf("invalid acquire point provided") + return errors.New("invalid acquire point provided") } } else { switch t := acquireTarget.(type) { @@ -954,7 +955,7 @@ func (c *Client) acquire(acquireTarget AcquireTarget) error { case AcquireImmutableTip: msg = NewMsgAcquireImmutableTip() default: - return fmt.Errorf("invalid acquire point provided") + return errors.New("invalid acquire point provided") } } if err := c.SendMessage(msg); err != nil { diff --git a/protocol/localstatequery/server.go b/protocol/localstatequery/server.go index a1eaa8c6..17b23da4 100644 --- a/protocol/localstatequery/server.go +++ b/protocol/localstatequery/server.go @@ -102,9 +102,7 @@ func (s *Server) handleAcquire(msg protocol.Message) error { "connection_id", s.callbackContext.ConnectionId.String(), ) if s.config.AcquireFunc == nil { - return fmt.Errorf( - "received local-state-query Acquire message but no callback function is defined", - ) + return errors.New("received local-state-query Acquire message but no callback function is defined") } var acquireTarget AcquireTarget switch msgAcquire := msg.(type) { @@ -150,9 +148,7 @@ func (s *Server) handleQuery(msg protocol.Message) error { "connection_id", s.callbackContext.ConnectionId.String(), ) if s.config.QueryFunc == nil { - return fmt.Errorf( - "received local-state-query Query message but no callback function is defined", - ) + return errors.New("received local-state-query Query message but no callback function is defined") } msgQuery := msg.(*MsgQuery) // Call the user callback function @@ -181,9 +177,7 @@ func (s *Server) handleRelease() error { "connection_id", s.callbackContext.ConnectionId.String(), ) if s.config.ReleaseFunc == nil { - return fmt.Errorf( - "received local-state-query Release message but no callback function is defined", - ) + return errors.New("received local-state-query Release message but no callback function is defined") } // Call the user callback function return s.config.ReleaseFunc(s.callbackContext) @@ -198,9 +192,7 @@ func (s *Server) handleReAcquire(msg protocol.Message) error { "connection_id", s.callbackContext.ConnectionId.String(), ) if s.config.AcquireFunc == nil { - return fmt.Errorf( - "received local-state-query ReAcquire message but no callback function is defined", - ) + return errors.New("received local-state-query ReAcquire message but no callback function is defined") } var acquireTarget AcquireTarget switch msgReAcquire := msg.(type) { diff --git a/protocol/localtxmonitor/messages.go b/protocol/localtxmonitor/messages.go index eb61fb3d..9fd1f4af 100644 --- a/protocol/localtxmonitor/messages.go +++ b/protocol/localtxmonitor/messages.go @@ -15,6 +15,7 @@ package localtxmonitor import ( + "errors" "fmt" "math" @@ -173,7 +174,7 @@ func (m *MsgReplyNextTx) UnmarshalCBOR(data []byte) error { } messageType64 := tmp[0].(uint64) if messageType64 > math.MaxUint8 { - return fmt.Errorf("message type integer overflow") + return errors.New("message type integer overflow") } // We know what the value will be, but it doesn't hurt to use the actual value from the message m.MessageType = uint8(messageType64) @@ -182,7 +183,7 @@ func (m *MsgReplyNextTx) UnmarshalCBOR(data []byte) error { txWrapper := tmp[1].([]interface{}) eraId64 := txWrapper[0].(uint64) if eraId64 > math.MaxUint8 { - return fmt.Errorf("era id integer overflow") + return errors.New("era id integer overflow") } m.Transaction = MsgReplyNextTxTransaction{ EraId: uint8(eraId64), diff --git a/protocol/localtxmonitor/server.go b/protocol/localtxmonitor/server.go index 5341708f..3511e5f7 100644 --- a/protocol/localtxmonitor/server.go +++ b/protocol/localtxmonitor/server.go @@ -16,6 +16,7 @@ package localtxmonitor import ( "encoding/hex" + "errors" "fmt" "math" @@ -93,9 +94,7 @@ func (s *Server) handleAcquire() error { "connection_id", s.callbackContext.ConnectionId.String(), ) if s.config.GetMempoolFunc == nil { - return fmt.Errorf( - "received local-tx-monitor Acquire message but no GetMempool callback function is defined", - ) + return errors.New("received local-tx-monitor Acquire message but no GetMempool callback function is defined") } // Call the user callback function to get mempool information mempoolSlotNumber, mempoolCapacity, mempoolTxs, err := s.config.GetMempoolFunc( @@ -195,7 +194,7 @@ func (s *Server) handleNextTx() error { } mempoolTx := s.mempoolTxs[s.mempoolNextTxIdx] if mempoolTx.EraId > math.MaxUint8 { - return fmt.Errorf("integer overflow in era id") + return errors.New("integer overflow in era id") } newMsg := NewMsgReplyNextTx(uint8(mempoolTx.EraId), mempoolTx.Tx) if err := s.SendMessage(newMsg); err != nil { @@ -220,10 +219,10 @@ func (s *Server) handleGetSizes() error { numTxs := len(s.mempoolTxs) // check for over/underflows if totalTxSize < 0 || totalTxSize > math.MaxUint32 { - return fmt.Errorf("integrer overflow in total tx size") + return errors.New("integrer overflow in total tx size") } if numTxs < 0 || numTxs > math.MaxUint32 { - return fmt.Errorf("integrer overflow in tx count") + return errors.New("integrer overflow in tx count") } newMsg := NewMsgReplyGetSizes( s.mempoolCapacity, diff --git a/protocol/localtxsubmission/server.go b/protocol/localtxsubmission/server.go index c2d75024..d68490e1 100644 --- a/protocol/localtxsubmission/server.go +++ b/protocol/localtxsubmission/server.go @@ -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. @@ -15,6 +15,7 @@ package localtxsubmission import ( + "errors" "fmt" "github.com/blinklabs-io/gouroboros/cbor" @@ -80,9 +81,7 @@ func (s *Server) handleSubmitTx(msg protocol.Message) error { "connection_id", s.callbackContext.ConnectionId.String(), ) if s.config.SubmitTxFunc == nil { - return fmt.Errorf( - "received local-tx-submission SubmitTx message but no callback function is defined", - ) + return errors.New("received local-tx-submission SubmitTx message but no callback function is defined") } msgSubmitTx := msg.(*MsgSubmitTx) // Call the user callback function and send Accept/RejectTx based on result diff --git a/protocol/peersharing/server.go b/protocol/peersharing/server.go index 9592709c..e05dcb72 100644 --- a/protocol/peersharing/server.go +++ b/protocol/peersharing/server.go @@ -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. @@ -15,6 +15,7 @@ package peersharing import ( + "errors" "fmt" "github.com/blinklabs-io/gouroboros/protocol" @@ -86,9 +87,7 @@ func (s *Server) handleShareRequest(msg protocol.Message) error { "connection_id", s.callbackContext.ConnectionId.String(), ) if s.config == nil || s.config.ShareRequestFunc == nil { - return fmt.Errorf( - "received peer-sharing ShareRequest message but no callback function is defined", - ) + return errors.New("received peer-sharing ShareRequest message but no callback function is defined") } msgShareRequest := msg.(*MsgShareRequest) peers, err := s.config.ShareRequestFunc( diff --git a/protocol/protocol.go b/protocol/protocol.go index 948c3331..88c564df 100644 --- a/protocol/protocol.go +++ b/protocol/protocol.go @@ -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. @@ -17,6 +17,7 @@ package protocol import ( "bytes" + "errors" "fmt" "io" "log/slog" @@ -130,7 +131,7 @@ func (p *Protocol) Start() { muxerProtocolRole, ) if p.muxerDoneChan == nil { - p.SendError(fmt.Errorf("could not register protocol with muxer")) + p.SendError(errors.New("could not register protocol with muxer")) return } diff --git a/protocol/txsubmission/client.go b/protocol/txsubmission/client.go index 1fb8f083..80587c51 100644 --- a/protocol/txsubmission/client.go +++ b/protocol/txsubmission/client.go @@ -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. @@ -15,6 +15,7 @@ package txsubmission import ( + "errors" "fmt" "sync" @@ -110,9 +111,7 @@ func (c *Client) handleRequestTxIds(msg protocol.Message) error { "connection_id", c.callbackContext.ConnectionId.String(), ) if c.config.RequestTxIdsFunc == nil { - return fmt.Errorf( - "received tx-submission RequestTxIds message but no callback function is defined", - ) + return errors.New("received tx-submission RequestTxIds message but no callback function is defined") } msgRequestTxIds := msg.(*MsgRequestTxIds) // Call the user callback function @@ -141,9 +140,7 @@ func (c *Client) handleRequestTxs(msg protocol.Message) error { "connection_id", c.callbackContext.ConnectionId.String(), ) if c.config.RequestTxsFunc == nil { - return fmt.Errorf( - "received tx-submission RequestTxs message but no callback function is defined", - ) + return errors.New("received tx-submission RequestTxs message but no callback function is defined") } msgRequestTxs := msg.(*MsgRequestTxs) // Call the user callback function diff --git a/protocol/txsubmission/server.go b/protocol/txsubmission/server.go index 23a52889..197a483a 100644 --- a/protocol/txsubmission/server.go +++ b/protocol/txsubmission/server.go @@ -15,6 +15,7 @@ package txsubmission import ( + "errors" "fmt" "math" "sync" @@ -224,9 +225,7 @@ func (s *Server) handleInit() error { "connection_id", s.callbackContext.ConnectionId.String(), ) if s.config == nil || s.config.InitFunc == nil { - return fmt.Errorf( - "received tx-submission Init message but no callback function is defined", - ) + return errors.New("received tx-submission Init message but no callback function is defined") } // Call the user callback function return s.config.InitFunc(s.callbackContext) diff --git a/utils/debug.go b/utils/debug.go index fa676f50..d5842f4e 100644 --- a/utils/debug.go +++ b/utils/debug.go @@ -28,7 +28,7 @@ func DumpCborStructure(data interface{}, prefix string) string { case []uint8: return fmt.Sprintf("%s (length %d),\n", prefix, len(v)) case []interface{}: - ret.WriteString(fmt.Sprintf("%s[\n", prefix)) + ret.WriteString(prefix + "[\n") newPrefix := prefix // Override original user-provided prefix // This assumes the original prefix won't start with a space @@ -36,7 +36,7 @@ func DumpCborStructure(data interface{}, prefix string) string { newPrefix = "" } // Add 2 more spaces to the new prefix - newPrefix = fmt.Sprintf(" %s", newPrefix) + newPrefix = " " + newPrefix /* var lastOutput string var lastOutputCount uint32 @@ -58,9 +58,9 @@ func DumpCborStructure(data interface{}, prefix string) string { */ ret.WriteString(tmp) } - ret.WriteString(fmt.Sprintf("%s],\n", prefix)) + ret.WriteString(prefix + "],\n") case map[interface{}]interface{}: - ret.WriteString(fmt.Sprintf("%s{\n", prefix)) + ret.WriteString(prefix + "{\n") newPrefix := prefix // Override original user-provided prefix // This assumes the original prefix won't start with a space @@ -68,11 +68,11 @@ func DumpCborStructure(data interface{}, prefix string) string { newPrefix = "" } // Add 2 more spaces to the new prefix - newPrefix = fmt.Sprintf(" %s", newPrefix) + newPrefix = " " + newPrefix for key, val := range v { ret.WriteString(fmt.Sprintf("%s%#v => %#v,\n", newPrefix, key, val)) } - ret.WriteString(fmt.Sprintf("%s}\n", prefix)) + ret.WriteString(prefix + "}\n") default: return fmt.Sprintf("%s%#v,\n", prefix, v) }