Skip to content

Commit

Permalink
remove type alias for actions and auth registry
Browse files Browse the repository at this point in the history
Signed-off-by: Joshua Kim <[email protected]>
  • Loading branch information
joshua-kim committed Oct 2, 2024
1 parent 165a455 commit 6cd9ed2
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 41 deletions.
7 changes: 4 additions & 3 deletions api/dependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/ava-labs/avalanchego/utils/logging"

"github.com/ava-labs/hypersdk/chain"
"github.com/ava-labs/hypersdk/codec"
"github.com/ava-labs/hypersdk/fees"
"github.com/ava-labs/hypersdk/genesis"
"github.com/ava-labs/hypersdk/state"
Expand All @@ -24,9 +25,9 @@ type VM interface {
SubnetID() ids.ID
Tracer() trace.Tracer
Logger() logging.Logger
ActionRegistry() chain.ActionRegistry
OutputRegistry() chain.OutputRegistry
AuthRegistry() chain.AuthRegistry
ActionRegistry() *codec.TypeParser[chain.Action]
OutputRegistry() *codec.TypeParser[codec.Typed]
AuthRegistry() *codec.TypeParser[chain.Auth]
Rules(t int64) chain.Rules
Submit(
ctx context.Context,
Expand Down
5 changes: 2 additions & 3 deletions api/jsonrpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,7 @@ type GetABIReply struct {

func (j *JSONRPCServer) GetABI(_ *http.Request, _ *GetABIArgs, reply *GetABIReply) error {
actionRegistry, outputRegistry := j.vm.ActionRegistry(), j.vm.OutputRegistry()
// Must dereference aliased type to call GetRegisteredTypes
vmABI, err := abi.NewABI((*actionRegistry).GetRegisteredTypes(), (*outputRegistry).GetRegisteredTypes())
vmABI, err := abi.NewABI(actionRegistry.GetRegisteredTypes(), (*outputRegistry).GetRegisteredTypes())
if err != nil {
return err
}
Expand All @@ -180,7 +179,7 @@ func (j *JSONRPCServer) Execute(
defer span.End()

actionRegistry := j.vm.ActionRegistry()
action, err := (*actionRegistry).Unmarshal(codec.NewReader(args.Action, len(args.Action)))
action, err := actionRegistry.Unmarshal(codec.NewReader(args.Action, len(args.Action)))
if err != nil {
return fmt.Errorf("failed to unmashal action: %w", err)
}
Expand Down
8 changes: 4 additions & 4 deletions api/ws/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ type WebSocketServer struct {
vm api.VM
logger logging.Logger
tracer trace.Tracer
actionRegistry chain.ActionRegistry
authRegistry chain.AuthRegistry
actionRegistry *codec.TypeParser[chain.Action]
authRegistry *codec.TypeParser[chain.Auth]

s *pubsub.Server

Expand All @@ -122,8 +122,8 @@ func NewWebSocketServer(
vm api.VM,
log logging.Logger,
tracer trace.Tracer,
actionRegistry chain.ActionRegistry,
authRegistry chain.AuthRegistry,
actionRegistry *codec.TypeParser[chain.Action],
authRegistry *codec.TypeParser[chain.Auth],
maxPendingMessages int,
) (*WebSocketServer, *pubsub.Server) {
w := &WebSocketServer{
Expand Down
12 changes: 3 additions & 9 deletions chain/dependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,11 @@ import (
"github.com/ava-labs/hypersdk/state"
)

type (
ActionRegistry *codec.TypeParser[Action]
OutputRegistry *codec.TypeParser[codec.Typed]
AuthRegistry *codec.TypeParser[Auth]
)

type Parser interface {
Rules(int64) Rules
ActionRegistry() ActionRegistry
OutputRegistry() OutputRegistry
AuthRegistry() AuthRegistry
ActionRegistry() *codec.TypeParser[Action]
OutputRegistry() *codec.TypeParser[codec.Typed]
AuthRegistry() *codec.TypeParser[Auth]
}

type Metrics interface {
Expand Down
8 changes: 4 additions & 4 deletions chain/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ func (t *Transaction) Digest() ([]byte, error) {

func (t *Transaction) Sign(
factory AuthFactory,
actionRegistry ActionRegistry,
authRegistry AuthRegistry,
actionRegistry *codec.TypeParser[Action],
authRegistry *codec.TypeParser[Auth],
) (*Transaction, error) {
msg, err := t.Digest()
if err != nil {
Expand Down Expand Up @@ -416,8 +416,8 @@ func MarshalTxs(txs []*Transaction) ([]byte, error) {
func UnmarshalTxs(
raw []byte,
initialCapacity int,
actionRegistry ActionRegistry,
authRegistry AuthRegistry,
actionRegistry *codec.TypeParser[Action],
authRegistry *codec.TypeParser[Auth],
) (map[uint8]int, []*Transaction, error) {
p := codec.NewReader(raw, consts.NetworkSizeLimit)
txCount := p.UnpackInt(true)
Expand Down
6 changes: 3 additions & 3 deletions examples/morpheusvm/vm/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,15 @@ func (p *Parser) Rules(_ int64) chain.Rules {
return p.genesis.Rules
}

func (*Parser) ActionRegistry() chain.ActionRegistry {
func (*Parser) ActionRegistry() *codec.TypeParser[chain.Action]{
return ActionParser
}

func (*Parser) OutputRegistry() chain.OutputRegistry {
func (*Parser) OutputRegistry() *codec.TypeParser[chain.Output] {
return OutputParser
}

func (*Parser) AuthRegistry() chain.AuthRegistry {
func (*Parser) AuthRegistry() *codec.TypeParser[chain.Auth] {
return AuthParser
}

Expand Down
5 changes: 3 additions & 2 deletions internal/gossiper/dependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/ava-labs/avalanchego/utils/set"

"github.com/ava-labs/hypersdk/chain"
"github.com/ava-labs/hypersdk/codec"
)

type VM interface {
Expand All @@ -26,8 +27,8 @@ type VM interface {
IsValidator(context.Context, ids.NodeID) (bool, error)
Logger() logging.Logger
PreferredBlock(context.Context) (*chain.StatefulBlock, error)
ActionRegistry() chain.ActionRegistry
AuthRegistry() chain.AuthRegistry
ActionRegistry() *codec.TypeParser[chain.Action]
AuthRegistry() *codec.TypeParser[chain.Auth]
NodeID() ids.NodeID
Rules(int64) chain.Rules
Submit(ctx context.Context, verify bool, txs []*chain.Transaction) []error
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ var _ = ginkgo.Describe("[HyperSDK APIs]", func() {
ginkgo.By("Gets ABI")

actionRegistry, outputRegistry := instances[0].vm.ActionRegistry(), instances[0].vm.OutputRegistry()
expectedABI, err := abi.NewABI((*actionRegistry).GetRegisteredTypes(), (*outputRegistry).GetRegisteredTypes())
expectedABI, err := abi.NewABI(actionRegistry.GetRegisteredTypes(), (*outputRegistry).GetRegisteredTypes())
require.NoError(err)

workload.GetABI(ctx, require, uris, expectedABI)
Expand Down
7 changes: 4 additions & 3 deletions vm/defaultvm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/ava-labs/hypersdk/api/jsonrpc"
"github.com/ava-labs/hypersdk/api/ws"
"github.com/ava-labs/hypersdk/chain"
"github.com/ava-labs/hypersdk/codec"
"github.com/ava-labs/hypersdk/extension/externalsubscriber"
"github.com/ava-labs/hypersdk/genesis"
"github.com/ava-labs/hypersdk/vm"
Expand All @@ -35,9 +36,9 @@ func New(
v *version.Semantic,
genesisFactory genesis.GenesisAndRuleFactory,
stateManager chain.StateManager,
actionRegistry chain.ActionRegistry,
authRegistry chain.AuthRegistry,
outputRegistry chain.OutputRegistry,
actionRegistry *codec.TypeParser[chain.Action],
authRegistry *codec.TypeParser[chain.Auth],
outputRegistry *codec.TypeParser[codec.Typed],
authEngine map[uint8]vm.AuthEngine,
options ...vm.Option,
) (*vm.VM, error) {
Expand Down
7 changes: 4 additions & 3 deletions vm/resolutions.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"go.uber.org/zap"

"github.com/ava-labs/hypersdk/chain"
"github.com/ava-labs/hypersdk/codec"
"github.com/ava-labs/hypersdk/fees"
"github.com/ava-labs/hypersdk/genesis"
"github.com/ava-labs/hypersdk/internal/builder"
Expand Down Expand Up @@ -50,15 +51,15 @@ func (vm *VM) SubnetID() ids.ID {
return vm.snowCtx.SubnetID
}

func (vm *VM) ActionRegistry() chain.ActionRegistry {
func (vm *VM) ActionRegistry() *codec.TypeParser[chain.Action]{
return vm.actionRegistry
}

func (vm *VM) OutputRegistry() chain.OutputRegistry {
func (vm *VM) OutputRegistry() *codec.TypeParser[codec.Typed]{
return vm.outputRegistry
}

func (vm *VM) AuthRegistry() chain.AuthRegistry {
func (vm *VM) AuthRegistry() *codec.TypeParser[chain.Auth]{
return vm.authRegistry
}

Expand Down
13 changes: 7 additions & 6 deletions vm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (

"github.com/ava-labs/hypersdk/api"
"github.com/ava-labs/hypersdk/chain"
"github.com/ava-labs/hypersdk/codec"
"github.com/ava-labs/hypersdk/event"
"github.com/ava-labs/hypersdk/fees"
"github.com/ava-labs/hypersdk/genesis"
Expand Down Expand Up @@ -90,9 +91,9 @@ type VM struct {
vmDB database.Database
handlers map[string]http.Handler
stateManager chain.StateManager
actionRegistry chain.ActionRegistry
authRegistry chain.AuthRegistry
outputRegistry chain.OutputRegistry
actionRegistry *codec.TypeParser[chain.Action]
authRegistry *codec.TypeParser[chain.Auth]
outputRegistry *codec.TypeParser[codec.Typed]
authEngine map[uint8]AuthEngine

tracer avatrace.Tracer
Expand Down Expand Up @@ -150,9 +151,9 @@ func New(
v *version.Semantic,
genesisFactory genesis.GenesisAndRuleFactory,
stateManager chain.StateManager,
actionRegistry chain.ActionRegistry,
authRegistry chain.AuthRegistry,
outputRegistry chain.OutputRegistry,
actionRegistry *codec.TypeParser[chain.Action],
authRegistry *codec.TypeParser[chain.Auth],
outputRegistry *codec.TypeParser[codec.Typed],
authEngine map[uint8]AuthEngine,
options ...Option,
) (*VM, error) {
Expand Down

0 comments on commit 6cd9ed2

Please sign in to comment.