diff --git a/.golangci.yml b/.golangci.yml index 03aeef86..87667c0b 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -4,6 +4,11 @@ issues: max-issues-per-linter: 0 max-same-issues: 0 linters: + disable: + - asasalint + - depguard + - recvcheck + - unparam enable: - errcheck - gosimple @@ -12,12 +17,15 @@ linters: - staticcheck - unused # Defaults above ours below - disable: - - asasalint - - recvcheck + - copyloopvar + - usestdlibvars + - whitespace presets: - bugs + - format + - import - performance + - unused #linters-settings: # errcheck: # check-type-assertions: true diff --git a/cbor/cbor.go b/cbor/cbor.go index 9dcf5df9..c341b587 100644 --- a/cbor/cbor.go +++ b/cbor/cbor.go @@ -36,8 +36,10 @@ const ( type RawMessage = _cbor.RawMessage // Alias for Tag for convenience -type Tag = _cbor.Tag -type RawTag = _cbor.RawTag +type ( + Tag = _cbor.Tag + RawTag = _cbor.RawTag +) // Useful for embedding and easier to remember type StructAsArray struct { diff --git a/cbor/decode.go b/cbor/decode.go index 4e31b91d..09d21e61 100644 --- a/cbor/decode.go +++ b/cbor/decode.go @@ -115,8 +115,10 @@ func DecodeById( return ret, nil } -var decodeGenericTypeCache = map[reflect.Type]reflect.Type{} -var decodeGenericTypeCacheMutex sync.RWMutex +var ( + decodeGenericTypeCache = map[reflect.Type]reflect.Type{} + decodeGenericTypeCacheMutex sync.RWMutex +) // DecodeGeneric decodes the specified CBOR into the destination object without using the // destination object's UnmarshalCBOR() function diff --git a/cbor/encode.go b/cbor/encode.go index a664c996..1913b73c 100644 --- a/cbor/encode.go +++ b/cbor/encode.go @@ -39,8 +39,10 @@ func Encode(data interface{}) ([]byte, error) { return buf.Bytes(), err } -var encodeGenericTypeCache = map[reflect.Type]reflect.Type{} -var encodeGenericTypeCacheMutex sync.RWMutex +var ( + encodeGenericTypeCache = map[reflect.Type]reflect.Type{} + encodeGenericTypeCacheMutex sync.RWMutex +) // EncodeGeneric encodes the specified object to CBOR without using the source object's // MarshalCBOR() function diff --git a/cbor/value.go b/cbor/value.go index 776febd7..0c0528a0 100644 --- a/cbor/value.go +++ b/cbor/value.go @@ -248,7 +248,6 @@ func generateAstJsonMap[T map[any]any | Map](v T) ([]byte, error) { strings.Join(tmpItems, ","), ) return []byte(tmpJson), nil - } type Constructor struct { diff --git a/cmd/gouroboros/mem_usage.go b/cmd/gouroboros/mem_usage.go index e415cf8e..e2042041 100644 --- a/cmd/gouroboros/mem_usage.go +++ b/cmd/gouroboros/mem_usage.go @@ -19,14 +19,13 @@ import ( "fmt" "log" "net/http" + // #nosec G108 + _ "net/http/pprof" "os" "runtime" "runtime/pprof" "time" - // #nosec G108 - _ "net/http/pprof" - ouroboros "github.com/blinklabs-io/gouroboros" ) diff --git a/cmd/gouroboros/server.go b/cmd/gouroboros/server.go index 93f82ccc..413bc5c5 100644 --- a/cmd/gouroboros/server.go +++ b/cmd/gouroboros/server.go @@ -26,14 +26,14 @@ import ( type serverFlags struct { flagset *flag.FlagSet - //txFile string + // txFile string } func newServerFlags() *serverFlags { f := &serverFlags{ flagset: flag.NewFlagSet("server", flag.ExitOnError), } - //f.flagset.StringVar(&f.txFile, "tx-file", "", "path to the transaction file to submit") + // f.flagset.StringVar(&f.txFile, "tx-file", "", "path to the transaction file to submit") return f } diff --git a/cmd/tx-submission/main.go b/cmd/tx-submission/main.go index 000d5d9d..7d3ab247 100644 --- a/cmd/tx-submission/main.go +++ b/cmd/tx-submission/main.go @@ -33,10 +33,12 @@ type txSubmissionFlags struct { rawTxFile string } -var txBytes []byte -var txHash [32]byte -var sentTx bool -var doneChan chan any +var ( + txBytes []byte + txHash [32]byte + sentTx bool + doneChan chan any +) func main() { // Parse commandline diff --git a/ledger/allegra.go b/ledger/allegra.go index 141ad1ee..331c67f1 100644 --- a/ledger/allegra.go +++ b/ledger/allegra.go @@ -20,11 +20,13 @@ import "github.com/blinklabs-io/gouroboros/ledger/allegra" // to keep existing code working after a refactor of the ledger package // Allegra types -type AllegraBlock = allegra.AllegraBlock -type AllegraTransaction = allegra.AllegraTransaction -type AllegraTransactionBody = allegra.AllegraTransactionBody -type AllegraProtocolParameters = allegra.AllegraProtocolParameters -type AllegraProtocolParameterUpdate = allegra.AllegraProtocolParameterUpdate +type ( + AllegraBlock = allegra.AllegraBlock + AllegraTransaction = allegra.AllegraTransaction + AllegraTransactionBody = allegra.AllegraTransactionBody + AllegraProtocolParameters = allegra.AllegraProtocolParameters + AllegraProtocolParameterUpdate = allegra.AllegraProtocolParameterUpdate +) // Allegra constants const ( diff --git a/ledger/allegra/allegra.go b/ledger/allegra/allegra.go index 2438cf50..725e190f 100644 --- a/ledger/allegra/allegra.go +++ b/ledger/allegra/allegra.go @@ -21,7 +21,6 @@ import ( "github.com/blinklabs-io/gouroboros/cbor" "github.com/blinklabs-io/gouroboros/ledger/common" "github.com/blinklabs-io/gouroboros/ledger/shelley" - utxorpc "github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano" ) @@ -36,12 +35,10 @@ const ( TxTypeAllegra = 2 ) -var ( - EraAllegra = common.Era{ - Id: EraIdAllegra, - Name: EraNameAllegra, - } -) +var EraAllegra = common.Era{ + Id: EraIdAllegra, + Name: EraNameAllegra, +} func init() { common.RegisterEra(EraAllegra) diff --git a/ledger/alonzo.go b/ledger/alonzo.go index 6a06f1bb..d93f1787 100644 --- a/ledger/alonzo.go +++ b/ledger/alonzo.go @@ -20,14 +20,16 @@ import "github.com/blinklabs-io/gouroboros/ledger/alonzo" // to keep existing code working after a refactor of the ledger package // Alonzo types -type AlonzoBlock = alonzo.AlonzoBlock -type AlonzoBlockHeader = alonzo.AlonzoBlockHeader -type AlonzoTransaction = alonzo.AlonzoTransaction -type AlonzoTransactionBody = alonzo.AlonzoTransactionBody -type AlonzoTransactionOutput = alonzo.AlonzoTransactionOutput -type AlonzoTransactionWitnessSet = alonzo.AlonzoTransactionWitnessSet -type AlonzoProtocolParameters = alonzo.AlonzoProtocolParameters -type AlonzoProtocolParameterUpdate = alonzo.AlonzoProtocolParameterUpdate +type ( + AlonzoBlock = alonzo.AlonzoBlock + AlonzoBlockHeader = alonzo.AlonzoBlockHeader + AlonzoTransaction = alonzo.AlonzoTransaction + AlonzoTransactionBody = alonzo.AlonzoTransactionBody + AlonzoTransactionOutput = alonzo.AlonzoTransactionOutput + AlonzoTransactionWitnessSet = alonzo.AlonzoTransactionWitnessSet + AlonzoProtocolParameters = alonzo.AlonzoProtocolParameters + AlonzoProtocolParameterUpdate = alonzo.AlonzoProtocolParameterUpdate +) // Alonzo constants const ( diff --git a/ledger/alonzo/alonzo.go b/ledger/alonzo/alonzo.go index 00343acc..a5edec85 100644 --- a/ledger/alonzo/alonzo.go +++ b/ledger/alonzo/alonzo.go @@ -23,7 +23,6 @@ import ( "github.com/blinklabs-io/gouroboros/ledger/common" "github.com/blinklabs-io/gouroboros/ledger/mary" "github.com/blinklabs-io/gouroboros/ledger/shelley" - utxorpc "github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano" ) @@ -38,12 +37,10 @@ const ( TxTypeAlonzo = 4 ) -var ( - EraAlonzo = common.Era{ - Id: EraIdAlonzo, - Name: EraNameAlonzo, - } -) +var EraAlonzo = common.Era{ + Id: EraIdAlonzo, + Name: EraNameAlonzo, +} func init() { common.RegisterEra(EraAlonzo) @@ -169,7 +166,6 @@ func (b *AlonzoTransactionBody) UnmarshalCBOR(cborData []byte) error { func (b *AlonzoTransactionBody) Outputs() []common.TransactionOutput { ret := []common.TransactionOutput{} for _, output := range b.TxOutputs { - ret = append(ret, &output) } return ret @@ -277,7 +273,7 @@ func (o AlonzoTransactionOutput) Utxorpc() *utxorpc.TxOutput { if o.Assets() != nil { tmpAssets := o.Assets() for _, policyId := range tmpAssets.Policies() { - var ma = &utxorpc.Multiasset{ + ma := &utxorpc.Multiasset{ PolicyId: policyId.Bytes(), } for _, assetName := range tmpAssets.Assets(policyId) { diff --git a/ledger/alonzo/pparams.go b/ledger/alonzo/pparams.go index 39fe10d6..6e1d438c 100644 --- a/ledger/alonzo/pparams.go +++ b/ledger/alonzo/pparams.go @@ -17,11 +17,10 @@ package alonzo import ( "math" - cardano "github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano" - "github.com/blinklabs-io/gouroboros/cbor" "github.com/blinklabs-io/gouroboros/ledger/common" "github.com/blinklabs-io/gouroboros/ledger/mary" + cardano "github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano" ) type AlonzoProtocolParameters struct { diff --git a/ledger/babbage.go b/ledger/babbage.go index 8cb57bf4..1501f622 100644 --- a/ledger/babbage.go +++ b/ledger/babbage.go @@ -20,14 +20,16 @@ import "github.com/blinklabs-io/gouroboros/ledger/babbage" // to keep existing code working after a refactor of the ledger package // Babbage types -type BabbageBlock = babbage.BabbageBlock -type BabbageBlockHeader = babbage.BabbageBlockHeader -type BabbageTransaction = babbage.BabbageTransaction -type BabbageTransactionBody = babbage.BabbageTransactionBody -type BabbageTransactionOutput = babbage.BabbageTransactionOutput -type BabbageTransactionWitnessSet = babbage.BabbageTransactionWitnessSet -type BabbageProtocolParameters = babbage.BabbageProtocolParameters -type BabbageProtocolParameterUpdate = babbage.BabbageProtocolParameterUpdate +type ( + BabbageBlock = babbage.BabbageBlock + BabbageBlockHeader = babbage.BabbageBlockHeader + BabbageTransaction = babbage.BabbageTransaction + BabbageTransactionBody = babbage.BabbageTransactionBody + BabbageTransactionOutput = babbage.BabbageTransactionOutput + BabbageTransactionWitnessSet = babbage.BabbageTransactionWitnessSet + BabbageProtocolParameters = babbage.BabbageProtocolParameters + BabbageProtocolParameterUpdate = babbage.BabbageProtocolParameterUpdate +) // Babbage constants const ( diff --git a/ledger/babbage/babbage.go b/ledger/babbage/babbage.go index 90d00d6b..5d09c555 100644 --- a/ledger/babbage/babbage.go +++ b/ledger/babbage/babbage.go @@ -25,7 +25,6 @@ import ( "github.com/blinklabs-io/gouroboros/ledger/common" "github.com/blinklabs-io/gouroboros/ledger/mary" "github.com/blinklabs-io/gouroboros/ledger/shelley" - utxorpc "github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano" ) @@ -40,12 +39,10 @@ const ( TxTypeBabbage = 5 ) -var ( - EraBabbage = common.Era{ - Id: EraIdBabbage, - Name: EraNameBabbage, - } -) +var EraBabbage = common.Era{ + Id: EraIdBabbage, + Name: EraNameBabbage, +} func init() { common.RegisterEra(EraBabbage) @@ -228,7 +225,6 @@ func (b *BabbageTransactionBody) UnmarshalCBOR(cborData []byte) error { func (b *BabbageTransactionBody) Outputs() []common.TransactionOutput { ret := []common.TransactionOutput{} for _, output := range b.TxOutputs { - ret = append(ret, &output) } return ret @@ -245,7 +241,6 @@ func (b *BabbageTransactionBody) ProtocolParameterUpdates() (uint64, map[common. func (b *BabbageTransactionBody) ReferenceInputs() []common.TransactionInput { ret := []common.TransactionInput{} for _, input := range b.TxReferenceInputs { - ret = append(ret, &input) } return ret @@ -458,7 +453,7 @@ func (o BabbageTransactionOutput) Utxorpc() *utxorpc.TxOutput { if o.Assets() != nil { tmpAssets := o.Assets() for _, policyId := range tmpAssets.Policies() { - var ma = &utxorpc.Multiasset{ + ma := &utxorpc.Multiasset{ PolicyId: policyId.Bytes(), } for _, assetName := range tmpAssets.Assets(policyId) { diff --git a/ledger/babbage/pparams.go b/ledger/babbage/pparams.go index 2a2e6959..a49f6d1f 100644 --- a/ledger/babbage/pparams.go +++ b/ledger/babbage/pparams.go @@ -17,11 +17,10 @@ package babbage import ( "math" - cardano "github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano" - "github.com/blinklabs-io/gouroboros/cbor" "github.com/blinklabs-io/gouroboros/ledger/alonzo" "github.com/blinklabs-io/gouroboros/ledger/common" + cardano "github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano" ) // BabbageProtocolParameters represents the current Babbage protocol parameters as seen in local-state-query diff --git a/ledger/babbage/rules.go b/ledger/babbage/rules.go index 3c3f7f0d..87785cac 100644 --- a/ledger/babbage/rules.go +++ b/ledger/babbage/rules.go @@ -142,7 +142,8 @@ func UtxoValidateCollateralContainsNonAda( } totalCollateral += utxo.Output.Amount() totalAssets.Add(utxo.Output.Assets()) - if utxo.Output.Assets() == nil || len(utxo.Output.Assets().Policies()) == 0 { + if utxo.Output.Assets() == nil || + len(utxo.Output.Assets().Policies()) == 0 { continue } badOutputs = append(badOutputs, utxo.Output) diff --git a/ledger/babbage/rules_test.go b/ledger/babbage/rules_test.go index a2a01be8..1c32dfd7 100644 --- a/ledger/babbage/rules_test.go +++ b/ledger/babbage/rules_test.go @@ -1113,14 +1113,14 @@ func TestUtxoValidateCollateralContainsNonAda(t *testing.T) { } tmpMultiAsset := common.NewMultiAsset[common.MultiAssetTypeOutput]( map[common.Blake2b224]map[cbor.ByteString]uint64{ - common.Blake2b224Hash([]byte("abcd")): map[cbor.ByteString]uint64{ + common.Blake2b224Hash([]byte("abcd")): { cbor.NewByteString([]byte("efgh")): 123, }, }, ) tmpZeroMultiAsset := common.NewMultiAsset[common.MultiAssetTypeOutput]( map[common.Blake2b224]map[cbor.ByteString]uint64{ - common.Blake2b224Hash([]byte("abcd")): map[cbor.ByteString]uint64{ + common.Blake2b224Hash([]byte("abcd")): { cbor.NewByteString([]byte("efgh")): 0, }, }, diff --git a/ledger/block.go b/ledger/block.go index 0bee4623..70f3fd0b 100644 --- a/ledger/block.go +++ b/ledger/block.go @@ -22,8 +22,10 @@ import ( ) // Compatibility aliases -type Block = common.Block -type BlockHeader = common.BlockHeader +type ( + Block = common.Block + BlockHeader = common.BlockHeader +) func NewBlockFromCbor(blockType uint, data []byte) (Block, error) { switch blockType { diff --git a/ledger/byron.go b/ledger/byron.go index 35095511..83648404 100644 --- a/ledger/byron.go +++ b/ledger/byron.go @@ -20,13 +20,15 @@ import "github.com/blinklabs-io/gouroboros/ledger/byron" // to keep existing code working after a refactor of the ledger package // Byron types -type ByronEpochBoundaryBlock = byron.ByronEpochBoundaryBlock -type ByronMainBlock = byron.ByronMainBlock -type ByronEpochBounaryBlockHeader = byron.ByronEpochBoundaryBlockHeader -type ByronMainBlockHeader = byron.ByronMainBlockHeader -type ByronTransaction = byron.ByronTransaction -type ByronTransactionInput = byron.ByronTransactionInput -type ByronTransactionOutput = byron.ByronTransactionOutput +type ( + ByronEpochBoundaryBlock = byron.ByronEpochBoundaryBlock + ByronMainBlock = byron.ByronMainBlock + ByronEpochBounaryBlockHeader = byron.ByronEpochBoundaryBlockHeader + ByronMainBlockHeader = byron.ByronMainBlockHeader + ByronTransaction = byron.ByronTransaction + ByronTransactionInput = byron.ByronTransactionInput + ByronTransactionOutput = byron.ByronTransactionOutput +) // Byron constants const ( diff --git a/ledger/byron/byron.go b/ledger/byron/byron.go index 00562fa2..84e5e956 100644 --- a/ledger/byron/byron.go +++ b/ledger/byron/byron.go @@ -22,7 +22,6 @@ import ( "github.com/blinklabs-io/gouroboros/cbor" "github.com/blinklabs-io/gouroboros/ledger/common" - utxorpc "github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano" ) @@ -40,12 +39,10 @@ const ( ByronSlotsPerEpoch = 21600 ) -var ( - EraByron = common.Era{ - Id: EraIdByron, - Name: EraNameByron, - } -) +var EraByron = common.Era{ + Id: EraIdByron, + Name: EraNameByron, +} func init() { common.RegisterEra(EraByron) @@ -169,7 +166,6 @@ func (t *ByronTransaction) Inputs() []common.TransactionInput { func (t *ByronTransaction) Outputs() []common.TransactionOutput { ret := []common.TransactionOutput{} for _, output := range t.TxOutputs { - ret = append(ret, &output) } return ret @@ -616,7 +612,6 @@ func (b *ByronMainBlock) Era() common.Era { func (b *ByronMainBlock) Transactions() []common.Transaction { ret := make([]common.Transaction, len(b.Body.TxPayload)) for idx, payload := range b.Body.TxPayload { - ret[idx] = &payload.Transaction } return ret diff --git a/ledger/common/address.go b/ledger/common/address.go index bfbd0309..2e54a181 100644 --- a/ledger/common/address.go +++ b/ledger/common/address.go @@ -20,10 +20,9 @@ import ( "hash/crc32" "strings" + "github.com/blinklabs-io/gouroboros/cbor" "github.com/btcsuite/btcd/btcutil/base58" "github.com/btcsuite/btcd/btcutil/bech32" - - "github.com/blinklabs-io/gouroboros/cbor" "golang.org/x/crypto/sha3" ) diff --git a/ledger/common/certs.go b/ledger/common/certs.go index 6bdacc1e..650e608b 100644 --- a/ledger/common/certs.go +++ b/ledger/common/certs.go @@ -223,9 +223,11 @@ func (c *StakeDelegationCertificate) Utxorpc() *utxorpc.Certificate { } } -type PoolKeyHash Blake2b224 -type PoolMetadataHash Blake2b256 -type VrfKeyHash Blake2b256 +type ( + PoolKeyHash Blake2b224 + PoolMetadataHash Blake2b256 + VrfKeyHash Blake2b256 +) type PoolMetadata struct { cbor.StructAsArray diff --git a/ledger/common/common.go b/ledger/common/common.go index e40ca5c0..43137a05 100644 --- a/ledger/common/common.go +++ b/ledger/common/common.go @@ -19,10 +19,9 @@ import ( "encoding/json" "fmt" + "github.com/blinklabs-io/gouroboros/cbor" "github.com/btcsuite/btcd/btcutil/bech32" "golang.org/x/crypto/blake2b" - - "github.com/blinklabs-io/gouroboros/cbor" ) const ( @@ -128,8 +127,10 @@ func Blake2b160Hash(data []byte) Blake2b160 { return Blake2b160(tmpHash.Sum(nil)) } -type MultiAssetTypeOutput = uint64 -type MultiAssetTypeMint = int64 +type ( + MultiAssetTypeOutput = uint64 + MultiAssetTypeMint = int64 +) // MultiAsset represents a collection of policies, assets, and quantities. It's used for // TX outputs (uint64) and TX asset minting (int64 to allow for negative values for burning) diff --git a/ledger/common/common_test.go b/ledger/common/common_test.go index 5b7a03a4..ffc152e6 100644 --- a/ledger/common/common_test.go +++ b/ledger/common/common_test.go @@ -199,7 +199,11 @@ func TestMultiAssetCompare(t *testing.T) { for _, testDef := range testDefs { tmpResult := testDef.asset1.Compare(testDef.asset2) if tmpResult != testDef.expectedResult { - t.Errorf("did not get expected result: got %v, wanted %v", tmpResult, testDef.expectedResult) + t.Errorf( + "did not get expected result: got %v, wanted %v", + tmpResult, + testDef.expectedResult, + ) } } } diff --git a/ledger/common/credentials.go b/ledger/common/credentials.go index 2d94f6c4..89b63449 100644 --- a/ledger/common/credentials.go +++ b/ledger/common/credentials.go @@ -18,7 +18,6 @@ import ( "fmt" "github.com/blinklabs-io/gouroboros/cbor" - utxorpc "github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano" "golang.org/x/crypto/blake2b" ) diff --git a/ledger/common/tx.go b/ledger/common/tx.go index 4671cc2f..6595fa2c 100644 --- a/ledger/common/tx.go +++ b/ledger/common/tx.go @@ -16,7 +16,6 @@ package common import ( "github.com/blinklabs-io/gouroboros/cbor" - utxorpc "github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano" ) diff --git a/ledger/compat.go b/ledger/compat.go index 0253c982..cdab35a9 100644 --- a/ledger/compat.go +++ b/ledger/compat.go @@ -22,8 +22,10 @@ import ( // after a refactor of the ledger package // Hash types -type Blake2b224 = common.Blake2b224 -type Blake2b256 = common.Blake2b256 +type ( + Blake2b224 = common.Blake2b224 + Blake2b256 = common.Blake2b256 +) func NewBlake2b224(data []byte) Blake2b224 { return common.NewBlake2b224(data) @@ -34,8 +36,10 @@ func NewBlake2b256(data []byte) Blake2b256 { } // Address -type Address = common.Address -type AddrKeyHash = common.AddrKeyHash +type ( + Address = common.Address + AddrKeyHash = common.AddrKeyHash +) const ( AddressTypeScriptNone = common.AddressTypeScriptNone @@ -49,32 +53,40 @@ var ( ) // Governance types -type VotingProcedure = common.VotingProcedure -type VotingProcedures = common.VotingProcedures -type ProposalProcedure = common.ProposalProcedure +type ( + VotingProcedure = common.VotingProcedure + VotingProcedures = common.VotingProcedures + ProposalProcedure = common.ProposalProcedure +) // Certificates -type Certificate = common.Certificate -type CertificateWrapper = common.CertificateWrapper -type PoolRetirementCertificate = common.PoolRetirementCertificate -type PoolRegistrationCertificate = common.PoolRegistrationCertificate -type StakeDelegationCertificate = common.StakeDelegationCertificate +type ( + Certificate = common.Certificate + CertificateWrapper = common.CertificateWrapper + PoolRetirementCertificate = common.PoolRetirementCertificate + PoolRegistrationCertificate = common.PoolRegistrationCertificate + StakeDelegationCertificate = common.StakeDelegationCertificate +) // Other types type IssuerVkey = common.IssuerVkey // Pools -type PoolRelay = common.PoolRelay -type PoolId = common.PoolId +type ( + PoolRelay = common.PoolRelay + PoolId = common.PoolId +) func NewPoolIdFromBech32(poolId string) (PoolId, error) { return common.NewPoolIdFromBech32(poolId) } // Assets -type MultiAssetTypeMint = common.MultiAssetTypeMint -type MultiAssetTypeOutput = common.MultiAssetTypeOutput -type AssetFingerprint = common.AssetFingerprint +type ( + MultiAssetTypeMint = common.MultiAssetTypeMint + MultiAssetTypeOutput = common.MultiAssetTypeOutput + AssetFingerprint = common.AssetFingerprint +) func NewAssetFingerprint(policyId []byte, assetName []byte) AssetFingerprint { return common.NewAssetFingerprint(policyId, assetName) diff --git a/ledger/conway.go b/ledger/conway.go index 61d94354..a1524a2e 100644 --- a/ledger/conway.go +++ b/ledger/conway.go @@ -20,13 +20,15 @@ import "github.com/blinklabs-io/gouroboros/ledger/conway" // to keep existing code working after a refactor of the ledger package // Conway types -type ConwayBlock = conway.ConwayBlock -type ConwayBlockHeader = conway.ConwayBlockHeader -type ConwayTransaction = conway.ConwayTransaction -type ConwayTransactionBody = conway.ConwayTransactionBody -type ConwayTransactionWitnessSet = conway.ConwayTransactionWitnessSet -type ConwayProtocolParameters = conway.ConwayProtocolParameters -type ConwayProtocolParameterUpdate = conway.ConwayProtocolParameterUpdate +type ( + ConwayBlock = conway.ConwayBlock + ConwayBlockHeader = conway.ConwayBlockHeader + ConwayTransaction = conway.ConwayTransaction + ConwayTransactionBody = conway.ConwayTransactionBody + ConwayTransactionWitnessSet = conway.ConwayTransactionWitnessSet + ConwayProtocolParameters = conway.ConwayProtocolParameters + ConwayProtocolParameterUpdate = conway.ConwayProtocolParameterUpdate +) // Conway constants const ( diff --git a/ledger/conway/conway.go b/ledger/conway/conway.go index 26d3075a..2c93de33 100644 --- a/ledger/conway/conway.go +++ b/ledger/conway/conway.go @@ -23,7 +23,6 @@ import ( "github.com/blinklabs-io/gouroboros/ledger/babbage" "github.com/blinklabs-io/gouroboros/ledger/common" "github.com/blinklabs-io/gouroboros/ledger/shelley" - utxorpc "github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano" ) @@ -38,12 +37,10 @@ const ( TxTypeConway = 6 ) -var ( - EraConway = common.Era{ - Id: EraIdConway, - Name: EraNameConway, - } -) +var EraConway = common.Era{ + Id: EraIdConway, + Name: EraNameConway, +} func init() { common.RegisterEra(EraConway) diff --git a/ledger/conway/pparams.go b/ledger/conway/pparams.go index 3495caa2..ba5a4db1 100644 --- a/ledger/conway/pparams.go +++ b/ledger/conway/pparams.go @@ -17,11 +17,10 @@ package conway import ( "math" - cardano "github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano" - "github.com/blinklabs-io/gouroboros/cbor" "github.com/blinklabs-io/gouroboros/ledger/babbage" "github.com/blinklabs-io/gouroboros/ledger/common" + cardano "github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano" ) type ConwayProtocolParameters struct { diff --git a/ledger/conway/rules.go b/ledger/conway/rules.go index de12c639..d29aed2d 100644 --- a/ledger/conway/rules.go +++ b/ledger/conway/rules.go @@ -167,7 +167,8 @@ func UtxoValidateCollateralContainsNonAda( } totalCollateral += utxo.Output.Amount() totalAssets.Add(utxo.Output.Assets()) - if utxo.Output.Assets() == nil || len(utxo.Output.Assets().Policies()) == 0 { + if utxo.Output.Assets() == nil || + len(utxo.Output.Assets().Policies()) == 0 { continue } badOutputs = append(badOutputs, utxo.Output) diff --git a/ledger/conway/rules_test.go b/ledger/conway/rules_test.go index ee1aad61..35be4607 100644 --- a/ledger/conway/rules_test.go +++ b/ledger/conway/rules_test.go @@ -1123,14 +1123,14 @@ func TestUtxoValidateCollateralContainsNonAda(t *testing.T) { } tmpMultiAsset := common.NewMultiAsset[common.MultiAssetTypeOutput]( map[common.Blake2b224]map[cbor.ByteString]uint64{ - common.Blake2b224Hash([]byte("abcd")): map[cbor.ByteString]uint64{ + common.Blake2b224Hash([]byte("abcd")): { cbor.NewByteString([]byte("efgh")): 123, }, }, ) tmpZeroMultiAsset := common.NewMultiAsset[common.MultiAssetTypeOutput]( map[common.Blake2b224]map[cbor.ByteString]uint64{ - common.Blake2b224Hash([]byte("abcd")): map[cbor.ByteString]uint64{ + common.Blake2b224Hash([]byte("abcd")): { cbor.NewByteString([]byte("efgh")): 0, }, }, diff --git a/ledger/error.go b/ledger/error.go index 640bc95c..406cea03 100644 --- a/ledger/error.go +++ b/ledger/error.go @@ -510,7 +510,6 @@ func (e *OutputTooBigUtxo) Error() string { } ret = ret + "])" return ret - } type InsufficientCollateral struct { diff --git a/ledger/mary.go b/ledger/mary.go index 58c5b216..614dd113 100644 --- a/ledger/mary.go +++ b/ledger/mary.go @@ -20,14 +20,16 @@ import "github.com/blinklabs-io/gouroboros/ledger/mary" // to keep existing code working after a refactor of the ledger package // Mary types -type MaryBlock = mary.MaryBlock -type MaryBlockHeader = mary.MaryBlockHeader -type MaryTransaction = mary.MaryTransaction -type MaryTransactionBody = mary.MaryTransactionBody -type MaryTransactionOutput = mary.MaryTransactionOutput -type MaryTransactionOutputValue = mary.MaryTransactionOutputValue -type MaryProtocolParameters = mary.MaryProtocolParameters -type MaryProtocolParameterUpdate = mary.MaryProtocolParameterUpdate +type ( + MaryBlock = mary.MaryBlock + MaryBlockHeader = mary.MaryBlockHeader + MaryTransaction = mary.MaryTransaction + MaryTransactionBody = mary.MaryTransactionBody + MaryTransactionOutput = mary.MaryTransactionOutput + MaryTransactionOutputValue = mary.MaryTransactionOutputValue + MaryProtocolParameters = mary.MaryProtocolParameters + MaryProtocolParameterUpdate = mary.MaryProtocolParameterUpdate +) // Mary constants const ( diff --git a/ledger/mary/mary.go b/ledger/mary/mary.go index fc63c41e..6d91d2f4 100644 --- a/ledger/mary/mary.go +++ b/ledger/mary/mary.go @@ -23,7 +23,6 @@ import ( "github.com/blinklabs-io/gouroboros/ledger/allegra" "github.com/blinklabs-io/gouroboros/ledger/common" "github.com/blinklabs-io/gouroboros/ledger/shelley" - utxorpc "github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano" ) @@ -38,12 +37,10 @@ const ( TxTypeMary = 3 ) -var ( - EraMary = common.Era{ - Id: EraIdMary, - Name: EraNameMary, - } -) +var EraMary = common.Era{ + Id: EraIdMary, + Name: EraNameMary, +} func init() { common.RegisterEra(EraMary) @@ -159,7 +156,6 @@ func (b *MaryTransactionBody) UnmarshalCBOR(cborData []byte) error { func (b *MaryTransactionBody) Outputs() []common.TransactionOutput { ret := []common.TransactionOutput{} for _, output := range b.TxOutputs { - ret = append(ret, &output) } return ret diff --git a/ledger/shelley.go b/ledger/shelley.go index c9957d71..2e53ed6b 100644 --- a/ledger/shelley.go +++ b/ledger/shelley.go @@ -20,15 +20,17 @@ import "github.com/blinklabs-io/gouroboros/ledger/shelley" // to keep existing code working after a refactor of the ledger package // Shelley types -type ShelleyBlock = shelley.ShelleyBlock -type ShelleyBlockHeader = shelley.ShelleyBlockHeader -type ShelleyTransaction = shelley.ShelleyTransaction -type ShelleyTransactionBody = shelley.ShelleyTransactionBody -type ShelleyTransactionInput = shelley.ShelleyTransactionInput -type ShelleyTransactionOutput = shelley.ShelleyTransactionOutput -type ShelleyTransactionWitnessSet = shelley.ShelleyTransactionWitnessSet -type ShelleyProtocolParameters = shelley.ShelleyProtocolParameters -type ShelleyProtocolParameterUpdate = shelley.ShelleyProtocolParameterUpdate +type ( + ShelleyBlock = shelley.ShelleyBlock + ShelleyBlockHeader = shelley.ShelleyBlockHeader + ShelleyTransaction = shelley.ShelleyTransaction + ShelleyTransactionBody = shelley.ShelleyTransactionBody + ShelleyTransactionInput = shelley.ShelleyTransactionInput + ShelleyTransactionOutput = shelley.ShelleyTransactionOutput + ShelleyTransactionWitnessSet = shelley.ShelleyTransactionWitnessSet + ShelleyProtocolParameters = shelley.ShelleyProtocolParameters + ShelleyProtocolParameterUpdate = shelley.ShelleyProtocolParameterUpdate +) // Shelley constants const ( diff --git a/ledger/shelley/pparams.go b/ledger/shelley/pparams.go index 46c1f1da..e2af007f 100644 --- a/ledger/shelley/pparams.go +++ b/ledger/shelley/pparams.go @@ -18,10 +18,9 @@ import ( "math" "math/big" - cardano "github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano" - "github.com/blinklabs-io/gouroboros/cbor" "github.com/blinklabs-io/gouroboros/ledger/common" + cardano "github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano" ) type ShelleyProtocolParameters struct { diff --git a/ledger/shelley/shelley.go b/ledger/shelley/shelley.go index e15da7b7..87f42d1f 100644 --- a/ledger/shelley/shelley.go +++ b/ledger/shelley/shelley.go @@ -20,10 +20,9 @@ import ( "fmt" "math" - utxorpc "github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano" - "github.com/blinklabs-io/gouroboros/cbor" "github.com/blinklabs-io/gouroboros/ledger/common" + utxorpc "github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano" ) const ( @@ -37,12 +36,10 @@ const ( TxTypeShelley = 1 ) -var ( - EraShelley = common.Era{ - Id: EraIdShelley, - Name: EraNameShelley, - } -) +var EraShelley = common.Era{ + Id: EraIdShelley, + Name: EraNameShelley, +} func init() { common.RegisterEra(EraShelley) @@ -233,7 +230,6 @@ func (b *ShelleyTransactionBody) Inputs() []common.TransactionInput { func (b *ShelleyTransactionBody) Outputs() []common.TransactionOutput { ret := []common.TransactionOutput{} for _, output := range b.TxOutputs { - ret = append(ret, &output) } return ret diff --git a/ledger/tx.go b/ledger/tx.go index c39c94a8..93b5fe1b 100644 --- a/ledger/tx.go +++ b/ledger/tx.go @@ -22,11 +22,13 @@ import ( ) // Compatibility aliases -type Transaction = common.Transaction -type TransactionBody = common.TransactionBody -type TransactionInput = common.TransactionInput -type TransactionOutput = common.TransactionOutput -type Utxo = common.Utxo +type ( + Transaction = common.Transaction + TransactionBody = common.TransactionBody + TransactionInput = common.TransactionInput + TransactionOutput = common.TransactionOutput + Utxo = common.Utxo +) func NewTransactionFromCbor(txType uint, data []byte) (Transaction, error) { switch txType { diff --git a/ledger/verify_block_body.go b/ledger/verify_block_body.go index cf39d793..4cb23d0f 100644 --- a/ledger/verify_block_body.go +++ b/ledger/verify_block_body.go @@ -23,12 +23,13 @@ import ( "encoding/binary" "encoding/hex" "fmt" - "github.com/blinklabs-io/gouroboros/cbor" - _cbor "github.com/fxamacker/cbor/v2" - "golang.org/x/crypto/blake2b" "math" "reflect" "strconv" + + "github.com/blinklabs-io/gouroboros/cbor" + _cbor "github.com/fxamacker/cbor/v2" + "golang.org/x/crypto/blake2b" ) const ( @@ -474,7 +475,6 @@ func GetBlockOutput( }) } } - } return outputs, regisCerts, deRegisCerts, nil diff --git a/ledger/verify_kes.go b/ledger/verify_kes.go index b90abf90..5d576e88 100644 --- a/ledger/verify_kes.go +++ b/ledger/verify_kes.go @@ -25,7 +25,6 @@ import ( "math" "github.com/blinklabs-io/gouroboros/cbor" - "golang.org/x/crypto/blake2b" ) diff --git a/ledger/verify_vrf.go b/ledger/verify_vrf.go index 2f4dea50..b6c422b0 100644 --- a/ledger/verify_vrf.go +++ b/ledger/verify_vrf.go @@ -156,7 +156,6 @@ func vrfHashPoints(P1, P2, P3, P4 *edwards25519.Point) *edwards25519.Scalar { panic(err) } return r - } func cryptoVrfIetfdraft03ProofToHash(pi []byte) ([]byte, error) { @@ -212,6 +211,7 @@ func vrfHashToCurveElligator225519( _, _ = result.SetBytes(hBytes[:]) // ge25519_frombytes(&H_point, h_string); return result, nil } + func ge25519FromUniform(r []byte) ([]byte, error) { s := make([]byte, 32) var e, negx, rr2, x, x2, x3 *field.Element diff --git a/protocol/blockfetch/blockfetch.go b/protocol/blockfetch/blockfetch.go index 6ca34ea3..dab95c12 100644 --- a/protocol/blockfetch/blockfetch.go +++ b/protocol/blockfetch/blockfetch.go @@ -18,10 +18,9 @@ import ( "time" "github.com/blinklabs-io/gouroboros/connection" + "github.com/blinklabs-io/gouroboros/ledger" "github.com/blinklabs-io/gouroboros/protocol" "github.com/blinklabs-io/gouroboros/protocol/common" - - "github.com/blinklabs-io/gouroboros/ledger" ) const ( @@ -103,10 +102,12 @@ type CallbackContext struct { } // Callback function types -type BlockFunc func(CallbackContext, uint, ledger.Block) error -type BlockRawFunc func(CallbackContext, uint, []byte) error -type BatchDoneFunc func(CallbackContext) error -type RequestRangeFunc func(CallbackContext, common.Point, common.Point) error +type ( + BlockFunc func(CallbackContext, uint, ledger.Block) error + BlockRawFunc func(CallbackContext, uint, []byte) error + BatchDoneFunc func(CallbackContext) error + RequestRangeFunc func(CallbackContext, common.Point, common.Point) error +) func New(protoOptions protocol.ProtocolOptions, cfg *Config) *BlockFetch { b := &BlockFetch{ diff --git a/protocol/blockfetch/client.go b/protocol/blockfetch/client.go index 23b1cb0e..832f9b1e 100644 --- a/protocol/blockfetch/client.go +++ b/protocol/blockfetch/client.go @@ -20,10 +20,9 @@ import ( "sync" "github.com/blinklabs-io/gouroboros/cbor" + "github.com/blinklabs-io/gouroboros/ledger" "github.com/blinklabs-io/gouroboros/protocol" "github.com/blinklabs-io/gouroboros/protocol/common" - - "github.com/blinklabs-io/gouroboros/ledger" ) type Client struct { diff --git a/protocol/chainsync/chainsync.go b/protocol/chainsync/chainsync.go index dbbbb0cf..52227087 100644 --- a/protocol/chainsync/chainsync.go +++ b/protocol/chainsync/chainsync.go @@ -216,12 +216,16 @@ type CallbackContext struct { } // Callback function types -type RollBackwardFunc func(CallbackContext, common.Point, Tip) error -type RollForwardFunc func(CallbackContext, uint, interface{}, Tip) error -type RollForwardRawFunc func(CallbackContext, uint, []byte, Tip) error +type ( + RollBackwardFunc func(CallbackContext, common.Point, Tip) error + RollForwardFunc func(CallbackContext, uint, interface{}, Tip) error + RollForwardRawFunc func(CallbackContext, uint, []byte, Tip) error +) -type FindIntersectFunc func(CallbackContext, []common.Point) (common.Point, Tip, error) -type RequestNextFunc func(CallbackContext) error +type ( + FindIntersectFunc func(CallbackContext, []common.Point) (common.Point, Tip, error) + RequestNextFunc func(CallbackContext) error +) // New returns a new ChainSync object func New(protoOptions protocol.ProtocolOptions, cfg *Config) *ChainSync { diff --git a/protocol/chainsync/server.go b/protocol/chainsync/server.go index f70923dc..e20f4739 100644 --- a/protocol/chainsync/server.go +++ b/protocol/chainsync/server.go @@ -173,7 +173,7 @@ func (s *Server) messageHandler(msg protocol.Message) error { func (s *Server) handleRequestNext() error { // TODO: figure out why this one log message causes a panic (and only this one) // during tests (#857) - //s.Protocol.Logger(). + // s.Protocol.Logger(). // Debug("request next", // "component", "network", // "protocol", ProtocolName, diff --git a/protocol/keepalive/keepalive.go b/protocol/keepalive/keepalive.go index 681ebf82..7f0db465 100644 --- a/protocol/keepalive/keepalive.go +++ b/protocol/keepalive/keepalive.go @@ -88,9 +88,11 @@ type CallbackContext struct { } // Callback function types -type KeepAliveFunc func(CallbackContext, uint16) error -type KeepAliveResponseFunc func(CallbackContext, uint16) error -type DoneFunc func(CallbackContext) error +type ( + KeepAliveFunc func(CallbackContext, uint16) error + KeepAliveResponseFunc func(CallbackContext, uint16) error + DoneFunc func(CallbackContext) error +) func New(protoOptions protocol.ProtocolOptions, cfg *Config) *KeepAlive { k := &KeepAlive{ diff --git a/protocol/keepalive/messages.go b/protocol/keepalive/messages.go index b748bd74..73d90bcc 100644 --- a/protocol/keepalive/messages.go +++ b/protocol/keepalive/messages.go @@ -16,6 +16,7 @@ package keepalive import ( "fmt" + "github.com/blinklabs-io/gouroboros/cbor" "github.com/blinklabs-io/gouroboros/protocol" ) diff --git a/protocol/localstatequery/client.go b/protocol/localstatequery/client.go index fc56cf9d..155bb582 100644 --- a/protocol/localstatequery/client.go +++ b/protocol/localstatequery/client.go @@ -419,7 +419,6 @@ func (c *Client) GetProposedProtocolParamsUpdates() (*ProposedProtocolParamsUpda return nil, err } return &result, nil - } // GetStakeDistribution returns the stake distribution diff --git a/protocol/localstatequery/localstatequery.go b/protocol/localstatequery/localstatequery.go index f13d97a5..ff0cc08e 100644 --- a/protocol/localstatequery/localstatequery.go +++ b/protocol/localstatequery/localstatequery.go @@ -154,9 +154,11 @@ type CallbackContext struct { } // Callback function types -type AcquireFunc func(CallbackContext, AcquireTarget, bool) error -type QueryFunc func(CallbackContext, QueryWrapper) (any, error) -type ReleaseFunc func(CallbackContext) error +type ( + AcquireFunc func(CallbackContext, AcquireTarget, bool) error + QueryFunc func(CallbackContext, QueryWrapper) (any, error) + ReleaseFunc func(CallbackContext) error +) // New returns a new LocalStateQuery object func New(protoOptions protocol.ProtocolOptions, cfg *Config) *LocalStateQuery { diff --git a/protocol/txsubmission/txsubmission.go b/protocol/txsubmission/txsubmission.go index daf577c1..6744296a 100644 --- a/protocol/txsubmission/txsubmission.go +++ b/protocol/txsubmission/txsubmission.go @@ -133,9 +133,11 @@ type CallbackContext struct { } // Callback function types -type RequestTxIdsFunc func(CallbackContext, bool, uint16, uint16) ([]TxIdAndSize, error) -type RequestTxsFunc func(CallbackContext, []TxId) ([]TxBody, error) -type InitFunc func(CallbackContext) error +type ( + RequestTxIdsFunc func(CallbackContext, bool, uint16, uint16) ([]TxIdAndSize, error) + RequestTxsFunc func(CallbackContext, []TxId) ([]TxBody, error) + InitFunc func(CallbackContext) error +) // New returns a new TxSubmission object func New(protoOptions protocol.ProtocolOptions, cfg *Config) *TxSubmission { diff --git a/protocol/versiondata.go b/protocol/versiondata.go index e8706711..133c0491 100644 --- a/protocol/versiondata.go +++ b/protocol/versiondata.go @@ -39,7 +39,7 @@ const ( type VersionData interface { NetworkMagic() uint32 - //Query() bool + // Query() bool // NtN only DiffusionMode() bool PeerSharing() bool diff --git a/protocol/versions.go b/protocol/versions.go index 63a52c11..0910f831 100644 --- a/protocol/versions.go +++ b/protocol/versions.go @@ -305,7 +305,6 @@ func GetProtocolVersionMap( CborNetworkMagic: networkMagic, CborInitiatorAndResponderDiffusionMode: diffusionMode, } - } } }