diff --git a/cbor/decode.go b/cbor/decode.go index 09d21e61..34c6552c 100644 --- a/cbor/decode.go +++ b/cbor/decode.go @@ -26,7 +26,7 @@ import ( "github.com/jinzhu/copier" ) -func Decode(dataBytes []byte, dest interface{}) (int, error) { +func Decode(dataBytes []byte, dest any) (int, error) { data := bytes.NewReader(dataBytes) // Create a custom decoder that returns an error on unknown fields decOptions := _cbor.DecOptions{ @@ -67,7 +67,7 @@ func DecodeIdFromList(cborData []byte) (int, error) { return 0, err } // Make sure that the value is actually numeric - switch v := tmp.Value().([]interface{})[0].(type) { + switch v := tmp.Value().([]any)[0].(type) { // The upstream CBOR library uses uint64 by default for numeric values case uint64: if v > uint64(math.MaxInt) { @@ -99,8 +99,8 @@ func ListLength(cborData []byte) (int, error) { // a map of numbers to object pointers to decode into func DecodeById( cborData []byte, - idMap map[int]interface{}, -) (interface{}, error) { + idMap map[int]any, +) (any, error) { id, err := DecodeIdFromList(cborData) if err != nil { return nil, err @@ -122,7 +122,7 @@ var ( // DecodeGeneric decodes the specified CBOR into the destination object without using the // destination object's UnmarshalCBOR() function -func DecodeGeneric(cborData []byte, dest interface{}) error { +func DecodeGeneric(cborData []byte, dest any) error { // Get destination type valueDest := reflect.ValueOf(dest) typeDest := valueDest.Elem().Type() diff --git a/cbor/decode_test.go b/cbor/decode_test.go index 8544edbf..e2490859 100644 --- a/cbor/decode_test.go +++ b/cbor/decode_test.go @@ -25,7 +25,7 @@ import ( type decodeTestDefinition struct { CborHex string - Object interface{} + Object any BytesRead int } @@ -33,12 +33,12 @@ var decodeTests = []decodeTestDefinition{ // Simple list of numbers { CborHex: "83010203", - Object: []interface{}{uint64(1), uint64(2), uint64(3)}, + Object: []any{uint64(1), uint64(2), uint64(3)}, }, // Multiple CBOR objects { CborHex: "81018102", - Object: []interface{}{uint64(1)}, + Object: []any{uint64(1)}, BytesRead: 2, }, } @@ -49,7 +49,7 @@ func TestDecode(t *testing.T) { if err != nil { t.Fatalf("failed to decode CBOR hex: %s", err) } - var dest interface{} + var dest any bytesRead, err := cbor.Decode(cborData, &dest) if err != nil { t.Fatalf("failed to decode CBOR: %s", err) @@ -205,7 +205,7 @@ type decodeByIdObjectC struct { type decodeByIdTestDefinition struct { CborHex string - Object interface{} + Object any Error error } @@ -245,7 +245,7 @@ var decodeByIdTests = []decodeByIdTestDefinition{ func TestDecodeById(t *testing.T) { for _, test := range decodeByIdTests { // We define this inside the loop to make sure to get fresh objects each time - var decodeByIdObjectMap = map[int]interface{}{ + var decodeByIdObjectMap = map[int]any{ 1: &decodeByIdObjectA{}, 2: &decodeByIdObjectB{}, 3: &decodeByIdObjectC{}, diff --git a/cbor/encode.go b/cbor/encode.go index 1913b73c..7d5ff1e0 100644 --- a/cbor/encode.go +++ b/cbor/encode.go @@ -24,7 +24,7 @@ import ( "github.com/jinzhu/copier" ) -func Encode(data interface{}) ([]byte, error) { +func Encode(data any) ([]byte, error) { buf := bytes.NewBuffer(nil) opts := _cbor.EncOptions{ // Make sure that maps have ordered keys @@ -46,7 +46,7 @@ var ( // EncodeGeneric encodes the specified object to CBOR without using the source object's // MarshalCBOR() function -func EncodeGeneric(src interface{}) ([]byte, error) { +func EncodeGeneric(src any) ([]byte, error) { // Get source type valueSrc := reflect.ValueOf(src) typeSrc := valueSrc.Elem().Type() diff --git a/cbor/encode_test.go b/cbor/encode_test.go index eab9c7ea..90ba4bee 100644 --- a/cbor/encode_test.go +++ b/cbor/encode_test.go @@ -23,14 +23,14 @@ import ( type encodeTestDefinition struct { CborHex string - Object interface{} + Object any } var encodeTests = []encodeTestDefinition{ // Simple list of numbers { CborHex: "83010203", - Object: []interface{}{1, 2, 3}, + Object: []any{1, 2, 3}, }, } diff --git a/cbor/value.go b/cbor/value.go index 0c0528a0..8ac41387 100644 --- a/cbor/value.go +++ b/cbor/value.go @@ -27,7 +27,7 @@ import ( // Helpful wrapper for parsing arbitrary CBOR data which may contain types that // cannot be easily represented in Go (such as maps with bytestring keys) type Value struct { - value interface{} + value any // We store this as a string so that the type is still hashable for use as map keys cborData string } @@ -78,7 +78,7 @@ func (v *Value) UnmarshalCBOR(data []byte) error { v.value = tmpTagDecode } default: - var tmpValue interface{} + var tmpValue any if _, err := Decode(data, &tmpValue); err != nil { return err } @@ -91,7 +91,7 @@ func (v Value) Cbor() []byte { return []byte(v.cborData) } -func (v Value) Value() interface{} { +func (v Value) Value() any { return v.value } @@ -160,8 +160,8 @@ func (v *Value) processArray(data []byte) error { return nil } -func generateAstJson(obj interface{}) ([]byte, error) { - tmpJsonObj := map[string]interface{}{} +func generateAstJson(obj any) ([]byte, error) { + tmpJsonObj := map[string]any{} switch v := obj.(type) { case []byte: tmpJsonObj["bytes"] = hex.EncodeToString(v) @@ -169,11 +169,11 @@ func generateAstJson(obj interface{}) ([]byte, error) { tmpJsonObj["bytes"] = hex.EncodeToString(v.Bytes()) case WrappedCbor: tmpJsonObj["bytes"] = hex.EncodeToString(v.Bytes()) - case []interface{}: + case []any: return generateAstJsonList[[]any](v) case Set: return generateAstJsonList[Set](v) - case map[interface{}]interface{}: + case map[any]any: return generateAstJsonMap[map[any]any](v) case Map: return generateAstJsonMap[Map](v) @@ -376,12 +376,12 @@ func (l *LazyValue) MarshalJSON() ([]byte, error) { return l.value.MarshalJSON() } -func (l *LazyValue) Decode() (interface{}, error) { +func (l *LazyValue) Decode() (any, error) { err := l.value.UnmarshalCBOR([]byte(l.value.cborData)) return l.Value(), err } -func (l *LazyValue) Value() interface{} { +func (l *LazyValue) Value() any { return l.value.Value() } diff --git a/cbor/value_test.go b/cbor/value_test.go index 12651e94..168c68b2 100644 --- a/cbor/value_test.go +++ b/cbor/value_test.go @@ -30,7 +30,7 @@ import ( var testDefs = []struct { cborHex string - expectedObject interface{} + expectedObject any expectedAstJson string expectedDecodeError error }{ diff --git a/cmd/gouroboros/chainsync.go b/cmd/gouroboros/chainsync.go index 07a755fe..797ef3e7 100644 --- a/cmd/gouroboros/chainsync.go +++ b/cmd/gouroboros/chainsync.go @@ -70,7 +70,7 @@ func newChainSyncFlags() *chainSyncFlags { } // Intersect points (last block of previous era) for each era on testnet/mainnet -var eraIntersect = map[string]map[string][]interface{}{ +var eraIntersect = map[string]map[string][]any{ "unknown": { "genesis": {}, }, @@ -145,7 +145,7 @@ func testChainSync(f *globalFlags) { os.Exit(1) } - var intersectPoint []interface{} + var intersectPoint []any if _, ok := eraIntersect[f.network]; !ok { if chainSyncFlags.startEra != "genesis" { fmt.Printf( @@ -255,7 +255,7 @@ func chainSyncRollBackwardHandler( func chainSyncRollForwardHandler( ctx chainsync.CallbackContext, blockType uint, - blockData interface{}, + blockData any, tip chainsync.Tip, ) error { var block ledger.Block diff --git a/connection.go b/connection.go index 95851a0a..32689da0 100644 --- a/connection.go +++ b/connection.go @@ -64,10 +64,10 @@ type Connection struct { muxer *muxer.Muxer errorChan chan error protoErrorChan chan error - handshakeFinishedChan chan interface{} + handshakeFinishedChan chan any handshakeVersion uint16 handshakeVersionData protocol.VersionData - doneChan chan interface{} + doneChan chan any connClosedChan chan struct{} waitGroup sync.WaitGroup onceClose sync.Once @@ -101,7 +101,7 @@ type Connection struct { func NewConnection(options ...ConnectionOptionFunc) (*Connection, error) { c := &Connection{ protoErrorChan: make(chan error, 10), - handshakeFinishedChan: make(chan interface{}), + handshakeFinishedChan: make(chan any), connClosedChan: make(chan struct{}), // Create a discard logger to throw away logs. We do this so // we don't have to add guards around every log operation if @@ -261,7 +261,7 @@ func (c *Connection) setupConnection() error { ) } // Start Goroutine to shutdown when doneChan is closed - c.doneChan = make(chan interface{}) + c.doneChan = make(chan any) go func() { <-c.doneChan c.shutdown() diff --git a/internal/test/helpers.go b/internal/test/helpers.go index 64c4c965..5eb3f308 100644 --- a/internal/test/helpers.go +++ b/internal/test/helpers.go @@ -30,11 +30,11 @@ func JsonStringsEqual(jsonData1 []byte, jsonData2 []byte) bool { return true } // Decode provided JSON strings - var tmpObj1 interface{} + var tmpObj1 any if err := json.Unmarshal(jsonData1, &tmpObj1); err != nil { return false } - var tmpObj2 interface{} + var tmpObj2 any if err := json.Unmarshal(jsonData2, &tmpObj2); err != nil { return false } diff --git a/ledger/babbage/babbage.go b/ledger/babbage/babbage.go index e0b171c3..c1386b25 100644 --- a/ledger/babbage/babbage.go +++ b/ledger/babbage/babbage.go @@ -404,11 +404,11 @@ func (d *BabbageTransactionOutputDatumOption) UnmarshalCBOR(data []byte) error { } func (d *BabbageTransactionOutputDatumOption) MarshalCBOR() ([]byte, error) { - var tmpObj []interface{} + var tmpObj []any if d.hash != nil { - tmpObj = []interface{}{DatumOptionTypeHash, d.hash} + tmpObj = []any{DatumOptionTypeHash, d.hash} } else if d.data != nil { - tmpObj = []interface{}{DatumOptionTypeData, cbor.Tag{Number: 24, Content: d.data.Cbor()}} + tmpObj = []any{DatumOptionTypeData, cbor.Tag{Number: 24, Content: d.data.Cbor()}} } else { return nil, errors.New("unknown datum option type") } diff --git a/ledger/byron/byron.go b/ledger/byron/byron.go index 4ed6dae5..c40247fe 100644 --- a/ledger/byron/byron.go +++ b/ledger/byron/byron.go @@ -54,7 +54,7 @@ type ByronMainBlockHeader struct { hash *common.Blake2b256 ProtocolMagic uint32 PrevBlock common.Blake2b256 - BodyProof interface{} + BodyProof any ConsensusData struct { cbor.StructAsArray // [slotid, pubkey, difficulty, blocksig] @@ -68,13 +68,13 @@ type ByronMainBlockHeader struct { cbor.StructAsArray Value uint64 } - BlockSig []interface{} + BlockSig []any } ExtraData struct { cbor.StructAsArray BlockVersion ByronBlockVersion SoftwareVersion ByronSoftwareVersion - Attributes interface{} + Attributes any ExtraProof common.Blake2b256 } } @@ -508,7 +508,7 @@ type ByronMainBlockBody struct { Twit []cbor.Value } SscPayload cbor.Value - DlgPayload []interface{} + DlgPayload []any UpdPayload ByronUpdatePayload } @@ -529,7 +529,7 @@ type ByronEpochBoundaryBlockHeader struct { hash *common.Blake2b256 ProtocolMagic uint32 PrevBlock common.Blake2b256 - BodyProof interface{} + BodyProof any ConsensusData struct { cbor.StructAsArray Epoch uint64 @@ -538,7 +538,7 @@ type ByronEpochBoundaryBlockHeader struct { Value uint64 } } - ExtraData interface{} + ExtraData any } func (h *ByronEpochBoundaryBlockHeader) UnmarshalCBOR(cborData []byte) error { @@ -599,7 +599,7 @@ type ByronMainBlock struct { cbor.DecodeStoreCbor BlockHeader *ByronMainBlockHeader Body ByronMainBlockBody - Extra []interface{} + Extra []any } func (b *ByronMainBlock) UnmarshalCBOR(cborData []byte) error { @@ -666,7 +666,7 @@ type ByronEpochBoundaryBlock struct { cbor.DecodeStoreCbor BlockHeader *ByronEpochBoundaryBlockHeader Body []common.Blake2b224 - Extra []interface{} + Extra []any } func (b *ByronEpochBoundaryBlock) UnmarshalCBOR(cborData []byte) error { diff --git a/ledger/common/common_test.go b/ledger/common/common_test.go index 7279a995..1bc45e61 100644 --- a/ledger/common/common_test.go +++ b/ledger/common/common_test.go @@ -68,7 +68,7 @@ func TestAssetFingerprint(t *testing.T) { func TestMultiAssetJson(t *testing.T) { testDefs := []struct { - multiAssetObj interface{} + multiAssetObj any expectedJson string }{ { diff --git a/ledger/error.go b/ledger/error.go index 406cea03..deb3567e 100644 --- a/ledger/error.go +++ b/ledger/error.go @@ -63,7 +63,7 @@ func NewGenericErrorFromCbor(cborData []byte) (error, error) { } type GenericError struct { - Value interface{} + Value any Cbor []byte } @@ -261,7 +261,7 @@ func (e *UtxoFailure) UnmarshalCBOR(data []byte) error { e.Era = tmpData.Era newErr, err := cbor.DecodeById( tmpData.Err, - map[int]interface{}{ + map[int]any{ UtxoFailureBadInputsUtxo: &BadInputsUtxo{}, UtxoFailureOutsideValidityIntervalUtxo: &OutsideValidityIntervalUtxo{}, UtxoFailureMaxTxSizeUtxo: &MaxTxSizeUtxo{}, @@ -339,7 +339,7 @@ type OutsideValidityIntervalUtxo struct { } func (e *OutsideValidityIntervalUtxo) Error() string { - validityInterval := e.ValidityInterval.Value().([]interface{}) + validityInterval := e.ValidityInterval.Value().([]any) return fmt.Sprintf( "OutsideValidityIntervalUtxo (ValidityInterval { invalidBefore = %v, invalidHereafter = %v }, Slot %d)", validityInterval[0], diff --git a/ledger/mary/mary_test.go b/ledger/mary/mary_test.go index 720ca1ed..6bbf4f3f 100644 --- a/ledger/mary/mary_test.go +++ b/ledger/mary/mary_test.go @@ -43,7 +43,7 @@ func createMaryTransactionOutputValueAssets( func TestMaryTransactionOutputValueEncodeDecode(t *testing.T) { var tests = []struct { CborHex string - Object interface{} + Object any }{ { CborHex: "1a02d71996", diff --git a/ledger/verify_block_body.go b/ledger/verify_block_body.go index e3949c61..f36a17dd 100644 --- a/ledger/verify_block_body.go +++ b/ledger/verify_block_body.go @@ -255,7 +255,7 @@ func encodeHead(e *bytes.Buffer, t byte, n uint64) int { func EncodeCborMap(data []AuxData) ([]byte, error) { dataLen := len(data) if dataLen == 0 { - txSeqMetadata := make(map[uint64]interface{}) + txSeqMetadata := make(map[uint64]any) return cbor.Encode(txSeqMetadata) } var dataBuffer bytes.Buffer diff --git a/ledger/verify_kes.go b/ledger/verify_kes.go index 5d576e88..9f424345 100644 --- a/ledger/verify_kes.go +++ b/ledger/verify_kes.go @@ -39,7 +39,7 @@ const ( type SumXKesSig struct { Depth uint64 - Sigma interface{} + Sigma any LeftHandSidePublicKey ed25519.PublicKey RightHandSidePublicKey ed25519.PublicKey } @@ -53,7 +53,7 @@ func NewSumKesFromByte(depth uint64, fromByte []byte) SumXKesSig { panic("length not match") } nextKesSize := SIGMA_SIZE + (depth-1)*(PUBLIC_KEY_SIZE*2) - var sigma interface{} + var sigma any if depth == 1 { sigma = Sum0KesSigFromByte(fromByte) } else { diff --git a/protocol/chainsync/chainsync.go b/protocol/chainsync/chainsync.go index bfc313f3..2f7443cc 100644 --- a/protocol/chainsync/chainsync.go +++ b/protocol/chainsync/chainsync.go @@ -141,7 +141,7 @@ type StateContext struct { pipelineCount int } -var IncrementPipelineCount = func(context interface{}, msg protocol.Message) bool { +var IncrementPipelineCount = func(context any, msg protocol.Message) bool { s := context.(*StateContext) s.mu.Lock() defer s.mu.Unlock() @@ -150,7 +150,7 @@ var IncrementPipelineCount = func(context interface{}, msg protocol.Message) boo return true } -var DecrementPipelineCountAndIsEmpty = func(context interface{}, msg protocol.Message) bool { +var DecrementPipelineCountAndIsEmpty = func(context any, msg protocol.Message) bool { s := context.(*StateContext) s.mu.Lock() defer s.mu.Unlock() @@ -162,7 +162,7 @@ var DecrementPipelineCountAndIsEmpty = func(context interface{}, msg protocol.Me return false } -var DecrementPipelineCountAndIsNotEmpty = func(context interface{}, msg protocol.Message) bool { +var DecrementPipelineCountAndIsNotEmpty = func(context any, msg protocol.Message) bool { s := context.(*StateContext) s.mu.Lock() defer s.mu.Unlock() @@ -174,7 +174,7 @@ var DecrementPipelineCountAndIsNotEmpty = func(context interface{}, msg protocol return false } -var PipelineIsEmtpy = func(context interface{}, msg protocol.Message) bool { +var PipelineIsEmtpy = func(context any, msg protocol.Message) bool { s := context.(*StateContext) s.mu.Lock() defer s.mu.Unlock() @@ -182,7 +182,7 @@ var PipelineIsEmtpy = func(context interface{}, msg protocol.Message) bool { return s.pipelineCount == 0 } -var PipelineIsNotEmpty = func(context interface{}, msg protocol.Message) bool { +var PipelineIsNotEmpty = func(context any, msg protocol.Message) bool { s := context.(*StateContext) s.mu.Lock() defer s.mu.Unlock() @@ -219,7 +219,7 @@ type CallbackContext struct { // Callback function types type ( RollBackwardFunc func(CallbackContext, common.Point, Tip) error - RollForwardFunc func(CallbackContext, uint, interface{}, Tip) error + RollForwardFunc func(CallbackContext, uint, any, Tip) error RollForwardRawFunc func(CallbackContext, uint, []byte, Tip) error ) diff --git a/protocol/chainsync/client.go b/protocol/chainsync/client.go index f0a328ca..d42afd87 100644 --- a/protocol/chainsync/client.go +++ b/protocol/chainsync/client.go @@ -55,7 +55,7 @@ type clientPointResult struct { // NewClient returns a new ChainSync client object func NewClient( - stateContext interface{}, + stateContext any, protoOptions protocol.ProtocolOptions, cfg *Config, ) *Client { diff --git a/protocol/chainsync/server.go b/protocol/chainsync/server.go index 12664564..fb964bfc 100644 --- a/protocol/chainsync/server.go +++ b/protocol/chainsync/server.go @@ -34,7 +34,7 @@ type Server struct { // NewServer returns a new ChainSync server object func NewServer( - stateContext interface{}, + stateContext any, protoOptions protocol.ProtocolOptions, cfg *Config, ) *Server { diff --git a/protocol/chainsync/wrappers.go b/protocol/chainsync/wrappers.go index dccdde6b..a70a6b1d 100644 --- a/protocol/chainsync/wrappers.go +++ b/protocol/chainsync/wrappers.go @@ -111,13 +111,13 @@ func (w *WrappedHeader) UnmarshalCBOR(data []byte) error { } func (w *WrappedHeader) MarshalCBOR() ([]byte, error) { - ret := []interface{}{ + ret := []any{ w.Era, } switch w.Era { case ledger.BlockHeaderTypeByron: - tmp := []interface{}{ - []interface{}{ + tmp := []any{ + []any{ w.byronType, w.byronSize, }, diff --git a/protocol/common/types.go b/protocol/common/types.go index 0b92cb49..21f03f6b 100644 --- a/protocol/common/types.go +++ b/protocol/common/types.go @@ -43,7 +43,7 @@ func NewPointOrigin() Point { // UnmarshalCBOR is a helper function for decoding a Point object from CBOR. The object content can vary, // so we need to do some special handling when decoding. It is not intended to be called directly. func (p *Point) UnmarshalCBOR(data []byte) error { - var tmp []interface{} + var tmp []any if _, err := cbor.Decode(data, &tmp); err != nil { return err } @@ -57,12 +57,12 @@ func (p *Point) UnmarshalCBOR(data []byte) error { // MarshalCBOR is a helper function for encoding a Point object to CBOR. The object content can vary, so we // need to do some special handling when encoding. It is not intended to be called directly. func (p *Point) MarshalCBOR() ([]byte, error) { - var data []interface{} + var data []any if p.Slot == 0 && p.Hash == nil { // Return an empty list if values are zero - data = make([]interface{}, 0) + data = make([]any, 0) } else { - data = []interface{}{p.Slot, p.Hash} + data = []any{p.Slot, p.Hash} } return cbor.Encode(data) } diff --git a/protocol/handshake/messages.go b/protocol/handshake/messages.go index 369aae2f..cba21348 100644 --- a/protocol/handshake/messages.go +++ b/protocol/handshake/messages.go @@ -103,10 +103,10 @@ func NewMsgAcceptVersion( type MsgRefuse struct { protocol.MessageBase - Reason []interface{} + Reason []any } -func NewMsgRefuse(reason []interface{}) *MsgRefuse { +func NewMsgRefuse(reason []any) *MsgRefuse { m := &MsgRefuse{ MessageBase: protocol.MessageBase{ MessageType: MessageTypeRefuse, diff --git a/protocol/handshake/messages_test.go b/protocol/handshake/messages_test.go index 2afcdf83..44c3e814 100644 --- a/protocol/handshake/messages_test.go +++ b/protocol/handshake/messages_test.go @@ -69,9 +69,9 @@ var tests = []testDefinition{ CborHex: "82028200840708090a", MessageType: MessageTypeRefuse, Message: NewMsgRefuse( - []interface{}{ + []any{ uint64(RefuseReasonVersionMismatch), - []interface{}{ + []any{ uint64(7), uint64(8), uint64(9), diff --git a/protocol/localstatequery/client.go b/protocol/localstatequery/client.go index dbbba9c4..14cd73fc 100644 --- a/protocol/localstatequery/client.go +++ b/protocol/localstatequery/client.go @@ -532,7 +532,7 @@ func (c *Client) DebugEpochState() (*DebugEpochStateResult, error) { query [10 #6.258([ *rwdr ])] */ func (c *Client) GetFilteredDelegationsAndRewardAccounts( - creds []interface{}, + creds []any, ) (*FilteredDelegationsAndRewardAccountsResult, error) { c.Protocol.Logger(). Debug(fmt.Sprintf("calling GetFilteredDelegationsAndRewardAccounts(creds: %+v)", creds), @@ -768,7 +768,7 @@ func (c *Client) GetRewardInfoPools() (*RewardInfoPoolsResult, error) { return &result, nil } -func (c *Client) GetPoolState(poolIds []interface{}) (*PoolStateResult, error) { +func (c *Client) GetPoolState(poolIds []any) (*PoolStateResult, error) { c.Protocol.Logger(). Debug(fmt.Sprintf("calling GetPoolState(poolIds: %+v)", poolIds), "component", "network", @@ -795,7 +795,7 @@ func (c *Client) GetPoolState(poolIds []interface{}) (*PoolStateResult, error) { } func (c *Client) GetStakeSnapshots( - poolId interface{}, + poolId any, ) (*StakeSnapshotsResult, error) { c.Protocol.Logger(). Debug(fmt.Sprintf("calling GetStakeSnapshots(poolId: %+v)", poolId), @@ -822,7 +822,7 @@ func (c *Client) GetStakeSnapshots( return &result, nil } -func (c *Client) GetPoolDistr(poolIds []interface{}) (*PoolDistrResult, error) { +func (c *Client) GetPoolDistr(poolIds []any) (*PoolDistrResult, error) { c.Protocol.Logger(). Debug(fmt.Sprintf("calling GetPoolDistr(poolIds: %+v)", poolIds), "component", "network", @@ -977,7 +977,7 @@ func (c *Client) release() error { return nil } -func (c *Client) runQuery(query interface{}, result interface{}) error { +func (c *Client) runQuery(query any, result any) error { msg := NewMsgQuery(query) if !c.acquired { if err := c.acquire(AcquireVolatileTip{}); err != nil { diff --git a/protocol/localstatequery/client_test.go b/protocol/localstatequery/client_test.go index 563b16e8..5135d76b 100644 --- a/protocol/localstatequery/client_test.go +++ b/protocol/localstatequery/client_test.go @@ -297,7 +297,7 @@ func TestGenesisConfigJSON(t *testing.T) { }, NetworkMagic: 764824073, NetworkId: 1, - ActiveSlotsCoeff: []interface{}{0.1, 0.2}, + ActiveSlotsCoeff: []any{0.1, 0.2}, SecurityParam: 2160, EpochLength: 432000, SlotsPerKESPeriod: 129600, diff --git a/protocol/localstatequery/messages.go b/protocol/localstatequery/messages.go index 4c83dbf4..69757d3d 100644 --- a/protocol/localstatequery/messages.go +++ b/protocol/localstatequery/messages.go @@ -157,7 +157,7 @@ type MsgQuery struct { Query QueryWrapper } -func NewMsgQuery(query interface{}) *MsgQuery { +func NewMsgQuery(query any) *MsgQuery { m := &MsgQuery{ MessageBase: protocol.MessageBase{ MessageType: MessageTypeQuery, diff --git a/protocol/localstatequery/messages_test.go b/protocol/localstatequery/messages_test.go index 5570fef3..9a57004c 100644 --- a/protocol/localstatequery/messages_test.go +++ b/protocol/localstatequery/messages_test.go @@ -31,7 +31,7 @@ type testDefinition struct { CborHex string Message protocol.Message MessageType uint - Result interface{} + Result any } var tests = []testDefinition{ @@ -178,7 +178,7 @@ func TestEncode(t *testing.T) { } // Helper function to encode to cbor or panic -func unsafeCbor(data interface{}) []byte { +func unsafeCbor(data any) []byte { cborData, err := cbor.Encode(data) if err != nil { panic(fmt.Sprintf("error encoding to CBOR: %s", err)) diff --git a/protocol/localstatequery/queries.go b/protocol/localstatequery/queries.go index d4e1489d..9ef825c1 100644 --- a/protocol/localstatequery/queries.go +++ b/protocol/localstatequery/queries.go @@ -368,15 +368,15 @@ func decodeQuery( return tmpQuery, nil } -func buildQuery(queryType int, params ...interface{}) []interface{} { - ret := []interface{}{queryType} +func buildQuery(queryType int, params ...any) []any { + ret := []any{queryType} if len(params) > 0 { ret = append(ret, params...) } return ret } -func buildHardForkQuery(queryType int, params ...interface{}) []interface{} { +func buildHardForkQuery(queryType int, params ...any) []any { ret := buildQuery( QueryTypeBlock, buildQuery( @@ -393,8 +393,8 @@ func buildHardForkQuery(queryType int, params ...interface{}) []interface{} { func buildShelleyQuery( era int, queryType int, - params ...interface{}, -) []interface{} { + params ...any, +) []any { ret := buildQuery( QueryTypeBlock, buildQuery( @@ -481,7 +481,7 @@ type EraHistoryResult struct { type eraHistoryResultBeginEnd struct { // Tells the CBOR decoder to convert to/from a struct and a CBOR array _ struct{} `cbor:",toarray"` - Timespan interface{} + Timespan any SlotNo int EpochNo int } @@ -506,7 +506,7 @@ type eraHistoryResultParams struct { result [{ *[0 int] => non_myopic_rewards }] for each stake display reward non_myopic_rewards { *poolid => int } int is the amount of lovelaces each pool would reward */ -type NonMyopicMemberRewardsResult interface{} +type NonMyopicMemberRewardsResult any type CurrentProtocolParamsResult interface { ledger.AlonzoProtocolParameters | @@ -517,7 +517,7 @@ type CurrentProtocolParamsResult interface { } // TODO (#861) -type ProposedProtocolParamsUpdatesResult interface{} +type ProposedProtocolParamsUpdatesResult any type StakeDistributionResult struct { cbor.StructAsArray @@ -591,10 +591,10 @@ func (u *UtxoId) MarshalCBOR() ([]byte, error) { /* result [{* utxo => value }] */ -type UTxOWholeResult interface{} +type UTxOWholeResult any // TODO (#863) -type DebugEpochStateResult interface{} +type DebugEpochStateResult any // TODO (#858) /* @@ -605,7 +605,7 @@ delegation { * rwdr => poolid } poolid is a bytestring rewards { * rwdr => int } It seems to be a requirement to sort the reward addresses on the query. Scripthash addresses come first, then within a group the bytestring being a network order integer sort ascending. */ -type FilteredDelegationsAndRewardAccountsResult interface{} +type FilteredDelegationsAndRewardAccountsResult any type GenesisConfigResult struct { // Tells the CBOR decoder to convert to/from a struct and a CBOR array @@ -613,7 +613,7 @@ type GenesisConfigResult struct { Start SystemStartResult NetworkMagic int NetworkId uint8 - ActiveSlotsCoeff []interface{} + ActiveSlotsCoeff []any SecurityParam int EpochLength int SlotsPerKESPeriod int @@ -624,8 +624,8 @@ type GenesisConfigResult struct { ProtocolParams GenesisConfigResultProtocolParameters // This value contains maps with bytestring keys, which we can't parse yet GenDelegs cbor.RawMessage - Unknown1 interface{} - Unknown2 interface{} + Unknown1 any + Unknown2 any } type GenesisConfigResultProtocolParameters struct { @@ -643,7 +643,7 @@ type GenesisConfigResultProtocolParameters struct { Rho []int Tau []int DecentralizationParam []int - ExtraEntropy interface{} + ExtraEntropy any ProtocolVersionMajor int ProtocolVersionMinor int MinUTxOValue int @@ -651,10 +651,10 @@ type GenesisConfigResultProtocolParameters struct { } // TODO (#864) -type DebugNewEpochStateResult interface{} +type DebugNewEpochStateResult any // TODO (#865) -type DebugChainDepStateResult interface{} +type DebugChainDepStateResult any // TODO (#866) /* @@ -677,7 +677,7 @@ activeStakeGo nil nil */ -type RewardProvenanceResult interface{} +type RewardProvenanceResult any type UTxOByTxInResult struct { cbor.StructAsArray @@ -710,13 +710,13 @@ type StakePoolParamsResult struct { } // TODO (#867) -type RewardInfoPoolsResult interface{} +type RewardInfoPoolsResult any // TODO (#868) -type PoolStateResult interface{} +type PoolStateResult any // TODO (#869) -type StakeSnapshotsResult interface{} +type StakeSnapshotsResult any // TODO (#870) -type PoolDistrResult interface{} +type PoolDistrResult any diff --git a/protocol/localtxmonitor/messages.go b/protocol/localtxmonitor/messages.go index 9fd1f4af..d70f89af 100644 --- a/protocol/localtxmonitor/messages.go +++ b/protocol/localtxmonitor/messages.go @@ -165,7 +165,7 @@ func NewMsgReplyNextTx(eraId uint8, tx []byte) *MsgReplyNextTx { } func (m *MsgReplyNextTx) UnmarshalCBOR(data []byte) error { - var tmp []interface{} + var tmp []any if _, err := cbor.Decode(data, &tmp); err != nil { return err } @@ -180,7 +180,7 @@ func (m *MsgReplyNextTx) UnmarshalCBOR(data []byte) error { m.MessageType = uint8(messageType64) // The ReplyNextTx message has a variable number of arguments if len(tmp) > 1 { - txWrapper := tmp[1].([]interface{}) + txWrapper := tmp[1].([]any) eraId64 := txWrapper[0].(uint64) if eraId64 > math.MaxUint8 { return errors.New("era id integer overflow") @@ -194,7 +194,7 @@ func (m *MsgReplyNextTx) UnmarshalCBOR(data []byte) error { } func (m *MsgReplyNextTx) MarshalCBOR() ([]byte, error) { - tmp := []interface{}{m.MessageType} + tmp := []any{m.MessageType} if m.Transaction.Tx != nil { type tmpTxObj struct { // Tells the CBOR decoder to convert to/from a struct and a CBOR array diff --git a/protocol/protocol.go b/protocol/protocol.go index 75705657..75a5cb0e 100644 --- a/protocol/protocol.go +++ b/protocol/protocol.go @@ -65,7 +65,7 @@ type ProtocolConfig struct { MessageHandlerFunc MessageHandlerFunc MessageFromCborFunc MessageFromCborFunc StateMap StateMap - StateContext interface{} + StateContext any InitialState State RecvQueueSize int } diff --git a/protocol/state.go b/protocol/state.go index 2d8373a8..cf3fa956 100644 --- a/protocol/state.go +++ b/protocol/state.go @@ -55,7 +55,7 @@ type StateTransition struct { // StateTransitionMatchFunc represents a function that will take a Message and return a bool // that indicates whether the message is a match for the state transition rule -type StateTransitionMatchFunc func(interface{}, Message) bool +type StateTransitionMatchFunc func(any, Message) bool // StateMapEntry represents a protocol state, it's possible state transitions, and an optional timeout type StateMapEntry struct { diff --git a/protocol/txsubmission/txsubmission.go b/protocol/txsubmission/txsubmission.go index 6744296a..9eb0f3b4 100644 --- a/protocol/txsubmission/txsubmission.go +++ b/protocol/txsubmission/txsubmission.go @@ -55,7 +55,7 @@ var StateMap = protocol.StateMap{ MsgType: MessageTypeRequestTxIds, NewState: stateTxIdsBlocking, // Match if blocking - MatchFunc: func(context interface{}, msg protocol.Message) bool { + MatchFunc: func(context any, msg protocol.Message) bool { msgRequestTxIds := msg.(*MsgRequestTxIds) return msgRequestTxIds.Blocking }, @@ -64,7 +64,7 @@ var StateMap = protocol.StateMap{ MsgType: MessageTypeRequestTxIds, NewState: stateTxIdsNonblocking, // Metch if non-blocking - MatchFunc: func(context interface{}, msg protocol.Message) bool { + MatchFunc: func(context any, msg protocol.Message) bool { msgRequestTxIds := msg.(*MsgRequestTxIds) return !msgRequestTxIds.Blocking }, diff --git a/utils/debug.go b/utils/debug.go index d5842f4e..65c238f9 100644 --- a/utils/debug.go +++ b/utils/debug.go @@ -20,14 +20,14 @@ import ( ) // DumpCborStructure generates an indented string representing an arbitrary data structure for debugging purposes -func DumpCborStructure(data interface{}, prefix string) string { +func DumpCborStructure(data any, prefix string) string { var ret bytes.Buffer switch v := data.(type) { case int, uint, int16, uint16, int32, uint32, int64, uint64: return fmt.Sprintf("%s0x%x (%d),\n", prefix, v, v) case []uint8: return fmt.Sprintf("%s (length %d),\n", prefix, len(v)) - case []interface{}: + case []any: ret.WriteString(prefix + "[\n") newPrefix := prefix // Override original user-provided prefix @@ -59,7 +59,7 @@ func DumpCborStructure(data interface{}, prefix string) string { ret.WriteString(tmp) } ret.WriteString(prefix + "],\n") - case map[interface{}]interface{}: + case map[any]any: ret.WriteString(prefix + "{\n") newPrefix := prefix // Override original user-provided prefix