[#770] morph: Support non-alpha notary request by wrappers
Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
parent
94d431e56e
commit
79b350b628
6 changed files with 82 additions and 9 deletions
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue