From 3fcfd4f41107460232b2ab67cce6f9840095747e Mon Sep 17 00:00:00 2001 From: Franfran <51274081+iFrostizz@users.noreply.github.com> Date: Fri, 9 Aug 2024 23:53:49 +0800 Subject: [PATCH] Move action and auth registry to `registry` package (#1258) * move {Action,Auth}Registry to registry package * gci --- examples/morpheusvm/controller/controller.go | 5 +++-- examples/morpheusvm/registry/registry.go | 18 +++++++++++------- examples/morpheusvm/rpc/jsonrpc_client.go | 5 ++--- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/examples/morpheusvm/controller/controller.go b/examples/morpheusvm/controller/controller.go index 7f3c06e9a9..7a029d42df 100644 --- a/examples/morpheusvm/controller/controller.go +++ b/examples/morpheusvm/controller/controller.go @@ -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" @@ -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..., ) diff --git a/examples/morpheusvm/registry/registry.go b/examples/morpheusvm/registry/registry.go index 829b5b4c94..479ec08c2f 100644 --- a/examples/morpheusvm/registry/registry.go +++ b/examples/morpheusvm/registry/registry.go @@ -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) diff --git a/examples/morpheusvm/rpc/jsonrpc_client.go b/examples/morpheusvm/rpc/jsonrpc_client.go index 78ff052467..245aca54ea 100644 --- a/examples/morpheusvm/rpc/jsonrpc_client.go +++ b/examples/morpheusvm/rpc/jsonrpc_client.go @@ -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" @@ -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 {