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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions cbor/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand All @@ -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()
Expand Down
12 changes: 6 additions & 6 deletions cbor/decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,20 @@ import (

type decodeTestDefinition struct {
CborHex string
Object interface{}
Object any
BytesRead int
}

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,
},
}
Expand All @@ -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)
Expand Down Expand Up @@ -205,7 +205,7 @@ type decodeByIdObjectC struct {

type decodeByIdTestDefinition struct {
CborHex string
Object interface{}
Object any
Error error
}

Expand Down Expand Up @@ -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{},
Expand Down
4 changes: 2 additions & 2 deletions cbor/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions cbor/encode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
},
}

Expand Down
18 changes: 9 additions & 9 deletions cbor/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}

Expand Down Expand Up @@ -160,20 +160,20 @@ 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)
case ByteString:
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)
Expand Down Expand Up @@ -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()
}

Expand Down
2 changes: 1 addition & 1 deletion cbor/value_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (

var testDefs = []struct {
cborHex string
expectedObject interface{}
expectedObject any
expectedAstJson string
expectedDecodeError error
}{
Expand Down
6 changes: 3 additions & 3 deletions cmd/gouroboros/chainsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -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": {},
},
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions internal/test/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions ledger/babbage/babbage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
16 changes: 8 additions & 8 deletions ledger/byron/byron.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
}
}
Expand Down Expand Up @@ -508,7 +508,7 @@ type ByronMainBlockBody struct {
Twit []cbor.Value
}
SscPayload cbor.Value
DlgPayload []interface{}
DlgPayload []any
UpdPayload ByronUpdatePayload
}

Expand All @@ -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
Expand All @@ -538,7 +538,7 @@ type ByronEpochBoundaryBlockHeader struct {
Value uint64
}
}
ExtraData interface{}
ExtraData any
}

func (h *ByronEpochBoundaryBlockHeader) UnmarshalCBOR(cborData []byte) error {
Expand Down Expand Up @@ -599,7 +599,7 @@ type ByronMainBlock struct {
cbor.DecodeStoreCbor
BlockHeader *ByronMainBlockHeader
Body ByronMainBlockBody
Extra []interface{}
Extra []any
}

func (b *ByronMainBlock) UnmarshalCBOR(cborData []byte) error {
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion ledger/common/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func TestAssetFingerprint(t *testing.T) {

func TestMultiAssetJson(t *testing.T) {
testDefs := []struct {
multiAssetObj interface{}
multiAssetObj any
expectedJson string
}{
{
Expand Down
6 changes: 3 additions & 3 deletions ledger/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func NewGenericErrorFromCbor(cborData []byte) (error, error) {
}

type GenericError struct {
Value interface{}
Value any
Cbor []byte
}

Expand Down Expand Up @@ -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{},
Expand Down Expand Up @@ -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],
Expand Down
Loading
Loading