Skip to content

Commit

Permalink
Move action and auth registry to registry package (#1258)
Browse files Browse the repository at this point in the history
* move {Action,Auth}Registry to registry package

* gci
  • Loading branch information
iFrostizz authored Aug 9, 2024
1 parent 5fc21a1 commit 3fcfd4f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
5 changes: 3 additions & 2 deletions examples/morpheusvm/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/ava-labs/hypersdk/chain"
"github.com/ava-labs/hypersdk/examples/morpheusvm/consts"
"github.com/ava-labs/hypersdk/examples/morpheusvm/genesis"
"github.com/ava-labs/hypersdk/examples/morpheusvm/registry"
"github.com/ava-labs/hypersdk/examples/morpheusvm/rpc"
"github.com/ava-labs/hypersdk/examples/morpheusvm/storage"
"github.com/ava-labs/hypersdk/extension/indexer"
Expand All @@ -37,8 +38,8 @@ func New(options ...vm.Option) (*vm.VM, error) {
return vm.New(
&factory{},
consts.Version,
consts.ActionRegistry,
consts.AuthRegistry,
registry.Action,
registry.Auth,
auth.Engines(),
options...,
)
Expand Down
18 changes: 11 additions & 7 deletions examples/morpheusvm/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,27 @@ import (
"github.com/ava-labs/hypersdk/chain"
"github.com/ava-labs/hypersdk/codec"
"github.com/ava-labs/hypersdk/examples/morpheusvm/actions"
"github.com/ava-labs/hypersdk/examples/morpheusvm/consts"
)

var (
Action *codec.TypeParser[chain.Action]
Auth *codec.TypeParser[chain.Auth]
)

// Setup types
func init() {
consts.ActionRegistry = codec.NewTypeParser[chain.Action]()
consts.AuthRegistry = codec.NewTypeParser[chain.Auth]()
Action = codec.NewTypeParser[chain.Action]()
Auth = codec.NewTypeParser[chain.Auth]()

errs := &wrappers.Errs{}
errs.Add(
// When registering new actions, ALWAYS make sure to append at the end.
consts.ActionRegistry.Register((&actions.Transfer{}).GetTypeID(), actions.UnmarshalTransfer),
Action.Register((&actions.Transfer{}).GetTypeID(), actions.UnmarshalTransfer),

// When registering new auth, ALWAYS make sure to append at the end.
consts.AuthRegistry.Register((&auth.ED25519{}).GetTypeID(), auth.UnmarshalED25519),
consts.AuthRegistry.Register((&auth.SECP256R1{}).GetTypeID(), auth.UnmarshalSECP256R1),
consts.AuthRegistry.Register((&auth.BLS{}).GetTypeID(), auth.UnmarshalBLS),
Auth.Register((&auth.ED25519{}).GetTypeID(), auth.UnmarshalED25519),
Auth.Register((&auth.SECP256R1{}).GetTypeID(), auth.UnmarshalSECP256R1),
Auth.Register((&auth.BLS{}).GetTypeID(), auth.UnmarshalBLS),
)
if errs.Errored() {
panic(errs.Err)
Expand Down
5 changes: 2 additions & 3 deletions examples/morpheusvm/rpc/jsonrpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ import (

"github.com/ava-labs/avalanchego/ids"

_ "github.com/ava-labs/hypersdk/examples/morpheusvm/registry" // ensure registry populated

"github.com/ava-labs/hypersdk/chain"
"github.com/ava-labs/hypersdk/examples/morpheusvm/consts"
"github.com/ava-labs/hypersdk/examples/morpheusvm/genesis"
"github.com/ava-labs/hypersdk/examples/morpheusvm/registry"
"github.com/ava-labs/hypersdk/examples/morpheusvm/storage"
"github.com/ava-labs/hypersdk/requester"
"github.com/ava-labs/hypersdk/rpc"
Expand Down Expand Up @@ -143,7 +142,7 @@ func (p *Parser) Rules(t int64) chain.Rules {
}

func (*Parser) Registry() (chain.ActionRegistry, chain.AuthRegistry) {
return consts.ActionRegistry, consts.AuthRegistry
return registry.Action, registry.Auth
}

func (*Parser) StateManager() chain.StateManager {
Expand Down

0 comments on commit 3fcfd4f

Please sign in to comment.