From 425c02b0ecee3a4624763b09ae37eeae1266d883 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Mon, 6 Sep 2021 15:14:16 +0300 Subject: [PATCH] [#801] morph/netmap: Add wrapper options Add constructor options on wrapper level of `netmap` contract. Signed-off-by: Pavel Karpy --- pkg/innerring/innerring.go | 2 +- pkg/morph/client/netmap/wrapper/wrapper.go | 39 ++++++++++++++++++++-- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/pkg/innerring/innerring.go b/pkg/innerring/innerring.go index 2ea5bf716..f1cb00829 100644 --- a/pkg/innerring/innerring.go +++ b/pkg/innerring/innerring.go @@ -476,7 +476,7 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error return nil, err } - server.netmapClient, err = nmWrapper.NewFromMorph(server.morphClient, server.contracts.netmap, fee, client.TryNotary(), client.AsAlphabet()) + server.netmapClient, err = nmWrapper.NewFromMorph(server.morphClient, server.contracts.netmap, fee, nmWrapper.TryNotary(), nmWrapper.AsAlphabet()) if err != nil { return nil, err } diff --git a/pkg/morph/client/netmap/wrapper/wrapper.go b/pkg/morph/client/netmap/wrapper/wrapper.go index a05c92476..133258096 100644 --- a/pkg/morph/client/netmap/wrapper/wrapper.go +++ b/pkg/morph/client/netmap/wrapper/wrapper.go @@ -22,9 +22,25 @@ type Wrapper struct { client *netmap.Client } +// Option allows to set an optional +// parameter of Wrapper. +type Option func(*opts) + +type opts []client.StaticClientOption + +func defaultOpts() *opts { + return new(opts) +} + // NewFromMorph returns the wrapper instance from the raw morph client. -func NewFromMorph(cli *client.Client, contract util.Uint160, fee fixedn.Fixed8, opts ...client.StaticClientOption) (*Wrapper, error) { - staticClient, err := client.NewStatic(cli, contract, fee, opts...) +func NewFromMorph(cli *client.Client, contract util.Uint160, fee fixedn.Fixed8, opts ...Option) (*Wrapper, error) { + o := defaultOpts() + + for i := range opts { + opts[i](o) + } + + staticClient, err := client.NewStatic(cli, contract, fee, ([]client.StaticClientOption)(*o)...) if err != nil { return nil, fmt.Errorf("can't create netmap static client: %w", err) } @@ -36,3 +52,22 @@ func NewFromMorph(cli *client.Client, contract util.Uint160, fee fixedn.Fixed8, return &Wrapper{client: enhancedNetmapClient}, nil } + +// TryNotary returns option to enable +// notary invocation tries. +func TryNotary() Option { + return func(o *opts) { + *o = append(*o, client.TryNotary()) + } +} + +// AsAlphabet returns option to sign main TX +// of notary requests with client's private +// key. +// +// Considered to be used by IR nodes only. +func AsAlphabet() Option { + return func(o *opts) { + *o = append(*o, client.AsAlphabet()) + } +}