Skip to content

Commit

Permalink
Remove marshaling from transfer action (#1647)
Browse files Browse the repository at this point in the history
  • Loading branch information
samliok authored Oct 10, 2024
1 parent b934dbd commit 5d8c590
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 23 deletions.
22 changes: 0 additions & 22 deletions examples/morpheusvm/actions/transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (

"github.com/ava-labs/hypersdk/chain"
"github.com/ava-labs/hypersdk/codec"
"github.com/ava-labs/hypersdk/consts"
"github.com/ava-labs/hypersdk/examples/morpheusvm/storage"
"github.com/ava-labs/hypersdk/state"

Expand Down Expand Up @@ -89,27 +88,6 @@ func (*Transfer) ValidRange(chain.Rules) (int64, int64) {
return -1, -1
}

// Implementing chain.Marshaler is optional but can be used to optimize performance when hitting TPS limits
var _ chain.Marshaler = (*Transfer)(nil)

func (t *Transfer) Size() int {
return codec.AddressLen + consts.Uint64Len + codec.BytesLen(t.Memo)
}

func (t *Transfer) Marshal(p *codec.Packer) {
p.PackAddress(t.To)
p.PackLong(t.Value)
p.PackBytes(t.Memo)
}

func UnmarshalTransfer(p *codec.Packer) (chain.Action, error) {
var transfer Transfer
p.UnpackAddress(&transfer.To)
transfer.Value = p.UnpackUint64(true)
p.UnpackBytes(MaxMemoSize, false, &transfer.Memo)
return &transfer, p.Err()
}

var _ codec.Typed = (*TransferResult)(nil)

type TransferResult struct {
Expand Down
2 changes: 1 addition & 1 deletion examples/morpheusvm/vm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func init() {
errs.Add(
// When registering new actions, ALWAYS make sure to append at the end.
// Pass nil as second argument if manual marshalling isn't needed (if in doubt, you probably don't)
ActionParser.Register(&actions.Transfer{}, actions.UnmarshalTransfer),
ActionParser.Register(&actions.Transfer{}, nil),

// When registering new auth, ALWAYS make sure to append at the end.
AuthParser.Register(&auth.ED25519{}, auth.UnmarshalED25519),
Expand Down

0 comments on commit 5d8c590

Please sign in to comment.