Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move action and auth registry to registry package #1258

Merged
merged 3 commits into from
Aug 9, 2024
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
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
Loading