From 79b350b6284a46ed5d480c2d4f8845ebee133d1e Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Wed, 25 Aug 2021 14:05:07 +0300 Subject: [PATCH] [#770] morph: Support non-alpha notary request by wrappers Signed-off-by: Pavel Karpy --- pkg/morph/client/balance/wrapper/wrapper.go | 11 ++++++ pkg/morph/client/container/wrapper/wrapper.go | 11 ++++++ pkg/morph/client/neofs/wrapper/client.go | 11 ++++++ pkg/morph/client/neofsid/wrapper/client.go | 11 ++++++ .../client/reputation/wrapper/wrapper.go | 11 ++++++ pkg/morph/client/static.go | 36 ++++++++++++++----- 6 files changed, 82 insertions(+), 9 deletions(-) diff --git a/pkg/morph/client/balance/wrapper/wrapper.go b/pkg/morph/client/balance/wrapper/wrapper.go index 434352ff..4cc95b54 100644 --- a/pkg/morph/client/balance/wrapper/wrapper.go +++ b/pkg/morph/client/balance/wrapper/wrapper.go @@ -40,6 +40,17 @@ func TryNotary() Option { } } +// 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()) + } +} + // NewFromMorph returns the wrapper instance from the raw morph client. func NewFromMorph(cli *client.Client, contract util.Uint160, fee fixedn.Fixed8, opts ...Option) (*Wrapper, error) { o := defaultOpts() diff --git a/pkg/morph/client/container/wrapper/wrapper.go b/pkg/morph/client/container/wrapper/wrapper.go index 499b62e0..eda5f776 100644 --- a/pkg/morph/client/container/wrapper/wrapper.go +++ b/pkg/morph/client/container/wrapper/wrapper.go @@ -44,6 +44,17 @@ func TryNotary() Option { } } +// 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()) + } +} + // NewFromMorph returns the wrapper instance from the raw morph client. func NewFromMorph(cli *client.Client, contract util.Uint160, fee fixedn.Fixed8, opts ...Option) (*Wrapper, error) { o := defaultOpts() diff --git a/pkg/morph/client/neofs/wrapper/client.go b/pkg/morph/client/neofs/wrapper/client.go index 8d038ab1..90c49538 100644 --- a/pkg/morph/client/neofs/wrapper/client.go +++ b/pkg/morph/client/neofs/wrapper/client.go @@ -34,6 +34,17 @@ func TryNotary() Option { } } +// 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()) + } +} + // NewFromMorph wraps client to work with NeoFS contract. func NewFromMorph(cli *client.Client, contract util.Uint160, fee fixedn.Fixed8, opts ...Option) (*ClientWrapper, error) { o := defaultOpts() diff --git a/pkg/morph/client/neofsid/wrapper/client.go b/pkg/morph/client/neofsid/wrapper/client.go index 3deffbf2..9bc28c31 100644 --- a/pkg/morph/client/neofsid/wrapper/client.go +++ b/pkg/morph/client/neofsid/wrapper/client.go @@ -34,6 +34,17 @@ func TryNotary() Option { } } +// 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()) + } +} + // NewFromMorph wraps client to work with NeoFS ID contract. func NewFromMorph(cli *client.Client, contract util.Uint160, fee fixedn.Fixed8, opts ...Option) (*ClientWrapper, error) { o := defaultOpts() diff --git a/pkg/morph/client/reputation/wrapper/wrapper.go b/pkg/morph/client/reputation/wrapper/wrapper.go index f9b315aa..9bcbb618 100644 --- a/pkg/morph/client/reputation/wrapper/wrapper.go +++ b/pkg/morph/client/reputation/wrapper/wrapper.go @@ -31,6 +31,17 @@ func TryNotary() Option { } } +// 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()) + } +} + // NewFromMorph returns the wrapper instance from the raw morph client. func NewFromMorph(cli *client.Client, contract util.Uint160, fee fixedn.Fixed8, opts ...Option) (*ClientWrapper, error) { o := defaultOpts() diff --git a/pkg/morph/client/static.go b/pkg/morph/client/static.go index 57d02604..11387042 100644 --- a/pkg/morph/client/static.go +++ b/pkg/morph/client/static.go @@ -17,6 +17,7 @@ import ( // and can lead to panic. type StaticClient struct { tryNotary bool + alpha bool // use client's key to sign notary request's main TX client *Client // neo-go client instance @@ -27,6 +28,7 @@ type StaticClient struct { type staticOpts struct { tryNotary bool + alpha bool } // StaticClientOption allows to set an optional @@ -37,14 +39,6 @@ func defaultStaticOpts() *staticOpts { return new(staticOpts) } -// TryNotary returns option to enable -// notary invocation tries. -func TryNotary() StaticClientOption { - return func(o *staticOpts) { - o.tryNotary = true - } -} - // ErrNilStaticClient is returned by functions that expect // a non-nil StaticClient pointer, but received nil. var ErrNilStaticClient = errors.New("static client is nil") @@ -65,6 +59,7 @@ func NewStatic(client *Client, scriptHash util.Uint160, fee fixedn.Fixed8, opts return &StaticClient{ tryNotary: o.tryNotary, + alpha: o.alpha, client: client, scScriptHash: scriptHash, fee: fee, @@ -82,7 +77,11 @@ func (s StaticClient) Morph() *Client { // If TryNotary is provided, calls NotaryInvoke on Client. func (s StaticClient) Invoke(method string, args ...interface{}) error { if s.tryNotary { - return s.client.NotaryInvoke(s.scScriptHash, s.fee, method, args...) + if s.alpha { + return s.client.NotaryInvoke(s.scScriptHash, s.fee, method, args...) + } + + return s.client.NotaryInvokeNotAlpha(s.scScriptHash, s.fee, method, args...) } return s.client.Invoke( @@ -101,3 +100,22 @@ func (s StaticClient) TestInvoke(method string, args ...interface{}) ([]stackite args..., ) } + +// TryNotary returns option to enable +// notary invocation tries. +func TryNotary() StaticClientOption { + return func(o *staticOpts) { + o.tryNotary = true + } +} + +// 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() StaticClientOption { + return func(o *staticOpts) { + o.alpha = true + } +}