[#770] morph: Support non-alpha notary request by wrappers

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2021-08-25 14:05:07 +03:00 committed by Pavel Karpy
parent 94d431e56e
commit 79b350b628
6 changed files with 82 additions and 9 deletions

View file

@ -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()

View file

@ -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()

View file

@ -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()

View file

@ -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()

View file

@ -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()

View file

@ -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,9 +77,13 @@ 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 {
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(
s.scScriptHash,
s.fee,
@ -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
}
}