[#584] pkg/innerring: Stop using deprecated methods

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2021-06-02 19:24:30 +03:00 committed by Alex Vanin
parent 91f010e0a9
commit 057ebf9d51
11 changed files with 65 additions and 44 deletions

View file

@ -18,6 +18,8 @@ type TransferPrm struct {
// TransferX transfers p.Amount of GASe-12 from p.From to p.To
// with details p.Details through direct smart contract call.
//
// If TryNotary is provided, calls notary contract.
func (w *Wrapper) TransferX(p TransferPrm) error {
return w.transferX(false, p)
}
@ -46,11 +48,5 @@ func (w *Wrapper) transferX(notary bool, p TransferPrm) error {
args.SetAmount(p.Amount)
args.SetDetails(p.Details)
// invoke smart contract call
f := w.client.TransferX
if notary {
f = w.client.TransferXNotary
}
return f(args)
return w.client.TransferX(args)
}

View file

@ -22,9 +22,33 @@ type Wrapper struct {
client *balance.Client
}
// Option allows to set an optional
// parameter of ClientWrapper.
type Option func(*opts)
type opts []client.StaticClientOption
func defaultOpts() *opts {
return new(opts)
}
// TryNotaryInvoke returns option to enable
// notary invocation tries.
func TryNotary() Option {
return func(o *opts) {
*o = append(*o, client.TryNotary())
}
}
// NewFromMorph returns the wrapper instance from the raw morph client.
func NewFromMorph(cli *client.Client, contract util.Uint160, fee fixedn.Fixed8) (*Wrapper, error) {
staticClient, err := client.NewStatic(cli, contract, fee)
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("could not create static client of Balance contract: %w", err)
}

View file

@ -58,7 +58,7 @@ func Put(w *Wrapper, cnr *container.Container) (*cid.ID, error) {
// Returns calculated container identifier and any error
// encountered that caused the saving to interrupt.
//
// If TryNotary is provided, call notary contract.
// If TryNotary is provided, calls notary contract.
func (w *Wrapper) Put(cnr, key, sig, token []byte) error {
if len(sig) == 0 || len(key) == 0 {
return errNilArgument

View file

@ -32,6 +32,8 @@ func (p *PutArgs) SetValue(v reputation.GlobalTrust) {
}
// Put invokes direct call of "put reputation value" method of reputation contract.
//
// If TryNotary is provided, calls notary contract.
func (w *ClientWrapper) Put(v PutArgs) error {
args, err := preparePutArgs(v)
if err != nil {

View file

@ -13,9 +13,33 @@ import (
// client which implements storage of reputation values.
type ClientWrapper reputation.Client
// Option allows to set an optional
// parameter of ClientWrapper.
type Option func(*opts)
type opts []client.StaticClientOption
func defaultOpts() *opts {
return new(opts)
}
// TryNotaryInvoke returns option to enable
// notary invocation tries.
func TryNotary() Option {
return func(o *opts) {
*o = append(*o, client.TryNotary())
}
}
// NewFromMorph returns the wrapper instance from the raw morph client.
func NewFromMorph(cli *client.Client, contract util.Uint160, fee fixedn.Fixed8) (*ClientWrapper, error) {
staticClient, err := client.NewStatic(cli, contract, fee)
func NewFromMorph(cli *client.Client, contract util.Uint160, fee fixedn.Fixed8, opts ...Option) (*ClientWrapper, 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("could not create static client of reputation contract: %w", err)
}

View file

@ -99,7 +99,7 @@ func (s StaticClient) TestInvoke(method string, args ...interface{}) ([]stackite
// NotaryInvoke calls NotaryInvoke method of Client with static internal
// script hash. Panics if notary support was not enabled in underlying
// moprh client.
// morph client.
//
// Deprecated: provide TryNotary() option to NewStatic and use Invoke.
func (s StaticClient) NotaryInvoke(method string, args ...interface{}) error {