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

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
remotes/fyrchik/meta-pebble
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. // 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) { func NewFromMorph(cli *client.Client, contract util.Uint160, fee fixedn.Fixed8, opts ...Option) (*Wrapper, error) {
o := defaultOpts() 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. // 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) { func NewFromMorph(cli *client.Client, contract util.Uint160, fee fixedn.Fixed8, opts ...Option) (*Wrapper, error) {
o := defaultOpts() 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. // NewFromMorph wraps client to work with NeoFS contract.
func NewFromMorph(cli *client.Client, contract util.Uint160, fee fixedn.Fixed8, opts ...Option) (*ClientWrapper, error) { func NewFromMorph(cli *client.Client, contract util.Uint160, fee fixedn.Fixed8, opts ...Option) (*ClientWrapper, error) {
o := defaultOpts() 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. // NewFromMorph wraps client to work with NeoFS ID contract.
func NewFromMorph(cli *client.Client, contract util.Uint160, fee fixedn.Fixed8, opts ...Option) (*ClientWrapper, error) { func NewFromMorph(cli *client.Client, contract util.Uint160, fee fixedn.Fixed8, opts ...Option) (*ClientWrapper, error) {
o := defaultOpts() 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. // 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) { func NewFromMorph(cli *client.Client, contract util.Uint160, fee fixedn.Fixed8, opts ...Option) (*ClientWrapper, error) {
o := defaultOpts() o := defaultOpts()

View File

@ -17,6 +17,7 @@ import (
// and can lead to panic. // and can lead to panic.
type StaticClient struct { type StaticClient struct {
tryNotary bool tryNotary bool
alpha bool // use client's key to sign notary request's main TX
client *Client // neo-go client instance client *Client // neo-go client instance
@ -27,6 +28,7 @@ type StaticClient struct {
type staticOpts struct { type staticOpts struct {
tryNotary bool tryNotary bool
alpha bool
} }
// StaticClientOption allows to set an optional // StaticClientOption allows to set an optional
@ -37,14 +39,6 @@ func defaultStaticOpts() *staticOpts {
return new(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 // ErrNilStaticClient is returned by functions that expect
// a non-nil StaticClient pointer, but received nil. // a non-nil StaticClient pointer, but received nil.
var ErrNilStaticClient = errors.New("static client is 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{ return &StaticClient{
tryNotary: o.tryNotary, tryNotary: o.tryNotary,
alpha: o.alpha,
client: client, client: client,
scScriptHash: scriptHash, scScriptHash: scriptHash,
fee: fee, fee: fee,
@ -82,7 +77,11 @@ func (s StaticClient) Morph() *Client {
// If TryNotary is provided, calls NotaryInvoke on Client. // If TryNotary is provided, calls NotaryInvoke on Client.
func (s StaticClient) Invoke(method string, args ...interface{}) error { func (s StaticClient) Invoke(method string, args ...interface{}) error {
if s.tryNotary { 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( return s.client.Invoke(
@ -101,3 +100,22 @@ func (s StaticClient) TestInvoke(method string, args ...interface{}) ([]stackite
args..., 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
}
}