diff --git a/pkg/morph/client/balance/transfer.go b/pkg/morph/client/balance/transfer.go index f3a212490..5305aa54e 100644 --- a/pkg/morph/client/balance/transfer.go +++ b/pkg/morph/client/balance/transfer.go @@ -40,10 +40,25 @@ func (t *TransferXArgs) SetDetails(v []byte) { t.details = v } -// TransferX invokes the call of "transferX" method +// TransferX directly invokes the call of "transferX" method // of NeoFS Balance contract. func (c *Client) TransferX(args TransferXArgs) error { - return errors.Wrapf(c.client.Invoke( + return c.transferX(false, args) +} + +// TransferXNotary invokes the call of "transferX" method +// of NeoFS Balance contract via notary contract. +func (c *Client) TransferXNotary(args TransferXArgs) error { + return c.transferX(true, args) +} + +func (c *Client) transferX(notary bool, args TransferXArgs) error { + f := c.client.Invoke + if notary { + f = c.client.NotaryInvoke + } + + return errors.Wrapf(f( c.transferXMethod, args.sender, args.recipient, diff --git a/pkg/morph/client/balance/wrapper/transfer.go b/pkg/morph/client/balance/wrapper/transfer.go index 7cadede9e..8152c44f0 100644 --- a/pkg/morph/client/balance/wrapper/transfer.go +++ b/pkg/morph/client/balance/wrapper/transfer.go @@ -15,9 +15,19 @@ type TransferPrm struct { Details []byte } -// TransferX transfers Amound of GASe-12 from p.From to p.To -// with details p.Details through smart contract call. +// TransferX transfers p.Amount of GASe-12 from p.From to p.To +// with details p.Details through direct smart contract call. func (w *Wrapper) TransferX(p TransferPrm) error { + return w.transferX(false, p) +} + +// TransferXNotary transfers p.Amount of GASe-12 from p.From to p.To +// with details p.Details via notary contract. +func (w *Wrapper) TransferXNotary(p TransferPrm) error { + return w.transferX(true, p) +} + +func (w *Wrapper) transferX(notary bool, p TransferPrm) error { from, err := owner.ScriptHashBE(p.From) if err != nil { return errors.Wrap(err, "invalid sender") @@ -36,5 +46,10 @@ func (w *Wrapper) TransferX(p TransferPrm) error { args.SetDetails(p.Details) // invoke smart contract call - return w.client.TransferX(args) + f := w.client.TransferX + if notary { + f = w.client.TransferXNotary + } + + return f(args) } diff --git a/pkg/morph/client/container/estimations.go b/pkg/morph/client/container/estimations.go index be21e8cd7..118ee2968 100644 --- a/pkg/morph/client/container/estimations.go +++ b/pkg/morph/client/container/estimations.go @@ -21,14 +21,14 @@ func (e *StopEstimation) SetEpoch(v int64) { } func (c *Client) StartEstimation(args StartEstimation) error { - return errors.Wrapf(c.client.Invoke( + return errors.Wrapf(c.client.NotaryInvoke( c.startEstimation, args.epoch, ), "could not invoke method (%s)", c.startEstimation) } func (c *Client) StopEstimation(args StopEstimation) error { - return errors.Wrapf(c.client.Invoke( + return errors.Wrapf(c.client.NotaryInvoke( c.stopEstimation, args.epoch, ), "could not invoke method (%s)", c.stopEstimation) diff --git a/pkg/morph/client/static.go b/pkg/morph/client/static.go index f4db5cedf..62530e275 100644 --- a/pkg/morph/client/static.go +++ b/pkg/morph/client/static.go @@ -61,3 +61,14 @@ func (s StaticClient) TestInvoke(method string, args ...interface{}) ([]stackite args..., ) } + +// NotaryInvoke calls NotaryInvoke method of Client with static internal +// script hash. Returns error if notary support was not enabled in underlying +// moprh client. +func (s StaticClient) NotaryInvoke(method string, args ...interface{}) error { + return s.client.NotaryInvoke( + s.scScriptHash, + method, + args..., + ) +}