diff --git a/chain/consts.go b/chain/consts.go index 816ef9f307..4dba91a246 100644 --- a/chain/consts.go +++ b/chain/consts.go @@ -6,8 +6,6 @@ package chain import ( "time" - "github.com/ava-labs/avalanchego/utils/units" - "github.com/ava-labs/hypersdk/keys" ) diff --git a/chain/transaction.go b/chain/transaction.go index a281b75d4c..c6ff3b4488 100644 --- a/chain/transaction.go +++ b/chain/transaction.go @@ -308,7 +308,7 @@ func (t *Transaction) Execute( // are set when this function is defined. If any of them are // modified later, they will not be used here. ts.Rollback(ctx, actionStart) - return &Result{false, utils.ErrBytes(rerr), maxUnits, maxFee, nil}, nil + return &Result{false, utils.ErrBytes(rerr), maxUnits, maxFee}, nil } success, actionCUs, output, err := t.Action.Execute(ctx, r, ts, timestamp, t.Auth.Actor(), t.id) if err != nil { diff --git a/codec/type_parser.go b/codec/type_parser.go index 0614c7b151..74f975cfec 100644 --- a/codec/type_parser.go +++ b/codec/type_parser.go @@ -7,42 +7,42 @@ import ( "github.com/ava-labs/hypersdk/consts" ) -type decoder[T any, X any, Y any] struct { - f func(*Packer, X) (T, error) +type decoder[T any, Y any] struct { + f func(*Packer) (T, error) y Y } // The number of types is limited to 255. -type TypeParser[T any, X any, Y any] struct { +type TypeParser[T any, Y any] struct { typeToIndex map[string]uint8 - indexToDecoder map[uint8]*decoder[T, X, Y] + indexToDecoder map[uint8]*decoder[T, Y] } // NewTypeParser returns an instance of a Typeparser with generic type [T]. -func NewTypeParser[T any, X any, Y bool]() *TypeParser[T, X, Y] { - return &TypeParser[T, X, Y]{ +func NewTypeParser[T any, Y bool]() *TypeParser[T, Y] { + return &TypeParser[T, Y]{ typeToIndex: map[string]uint8{}, - indexToDecoder: map[uint8]*decoder[T, X, Y]{}, + indexToDecoder: map[uint8]*decoder[T, Y]{}, } } // Register registers a new type into TypeParser [p]. Registers the type by using // the string representation of [o], and sets the decoder of that index to [f]. // Returns an error if [o] has already been registered or the TypeParser is full. -func (p *TypeParser[T, X, Y]) Register(id uint8, f func(*Packer, X) (T, error), y Y) error { +func (p *TypeParser[T, Y]) Register(id uint8, f func(*Packer) (T, error), y Y) error { if len(p.indexToDecoder) == int(consts.MaxUint8)+1 { return ErrTooManyItems } if _, ok := p.indexToDecoder[id]; ok { return ErrDuplicateItem } - p.indexToDecoder[id] = &decoder[T, X, Y]{f, y} + p.indexToDecoder[id] = &decoder[T, Y]{f, y} return nil } // LookupIndex returns the decoder function and success of lookup of [index] // from Typeparser [p]. -func (p *TypeParser[T, X, Y]) LookupIndex(index uint8) (func(*Packer, X) (T, error), Y, bool) { +func (p *TypeParser[T, Y]) LookupIndex(index uint8) (func(*Packer) (T, error), Y, bool) { d, ok := p.indexToDecoder[index] if ok { return d.f, d.y, true diff --git a/codec/type_parser_test.go b/codec/type_parser_test.go index 76f6b04ad7..1cbb71b4fa 100644 --- a/codec/type_parser_test.go +++ b/codec/type_parser_test.go @@ -34,7 +34,7 @@ func (*Blah3) Bark() string { return "blah3" } func (*Blah3) GetTypeID() uint8 { return 2 } func TestTypeParser(t *testing.T) { - tp := NewTypeParser[Blah, any, bool]() + tp := NewTypeParser[Blah, bool]() t.Run("empty parser", func(t *testing.T) { require := require.New(t) @@ -54,14 +54,14 @@ func TestTypeParser(t *testing.T) { require.NoError( tp.Register( blah1.GetTypeID(), - func(*Packer, any) (Blah, error) { return nil, errBlah1 }, + func(*Packer) (Blah, error) { return nil, errBlah1 }, true, ), ) require.NoError( tp.Register( blah2.GetTypeID(), - func(*Packer, any) (Blah, error) { return nil, errBlah2 }, + func(*Packer) (Blah, error) { return nil, errBlah2 }, false, ), ) @@ -69,14 +69,14 @@ func TestTypeParser(t *testing.T) { f, b, ok := tp.LookupIndex(blah1.GetTypeID()) require.True(ok) require.True(b) - res, err := f(nil, nil) + res, err := f(nil) require.Nil(res) require.ErrorIs(err, errBlah1) f, b, ok = tp.LookupIndex(blah2.GetTypeID()) require.True(ok) require.False(b) - res, err = f(nil, nil) + res, err = f(nil) require.Nil(res) require.ErrorIs(err, errBlah2) }) diff --git a/examples/tokenvm/actions/burn_asset.go b/examples/tokenvm/actions/burn_asset.go index 8eb18e6bab..bffc8290fb 100644 --- a/examples/tokenvm/actions/burn_asset.go +++ b/examples/tokenvm/actions/burn_asset.go @@ -52,26 +52,26 @@ func (b *BurnAsset) Execute( _ bool, ) (bool, uint64, []byte, error) { if b.Value == 0 { - return false, BurnComputeUnits, OutputValueZero, nil, nil + return false, BurnComputeUnits, OutputValueZero, nil } if err := storage.SubBalance(ctx, mu, actor, b.Asset, b.Value); err != nil { - return false, BurnComputeUnits, utils.ErrBytes(err), nil, nil + return false, BurnComputeUnits, utils.ErrBytes(err), nil } exists, symbol, decimals, metadata, supply, owner, err := storage.GetAsset(ctx, mu, b.Asset) if err != nil { - return false, BurnComputeUnits, utils.ErrBytes(err), nil, nil + return false, BurnComputeUnits, utils.ErrBytes(err), nil } if !exists { - return false, BurnComputeUnits, OutputAssetMissing, nil, nil + return false, BurnComputeUnits, OutputAssetMissing, nil } newSupply, err := smath.Sub(supply, b.Value) if err != nil { - return false, BurnComputeUnits, utils.ErrBytes(err), nil, nil + return false, BurnComputeUnits, utils.ErrBytes(err), nil } if err := storage.SetAsset(ctx, mu, b.Asset, symbol, decimals, metadata, newSupply, owner); err != nil { - return false, BurnComputeUnits, utils.ErrBytes(err), nil, nil + return false, BurnComputeUnits, utils.ErrBytes(err), nil } - return true, BurnComputeUnits, nil, nil, nil + return true, BurnComputeUnits, nil, nil } func (*BurnAsset) MaxComputeUnits(chain.Rules) uint64 {