[#404] morph/client: Support notary calls in wrappers

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2021-02-25 19:49:05 +03:00 committed by Alex Vanin
parent 71dce97b76
commit 83980ccb85
4 changed files with 48 additions and 7 deletions

View file

@ -40,10 +40,25 @@ func (t *TransferXArgs) SetDetails(v []byte) {
t.details = v t.details = v
} }
// TransferX invokes the call of "transferX" method // TransferX directly invokes the call of "transferX" method
// of NeoFS Balance contract. // of NeoFS Balance contract.
func (c *Client) TransferX(args TransferXArgs) error { 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, c.transferXMethod,
args.sender, args.sender,
args.recipient, args.recipient,

View file

@ -15,9 +15,19 @@ type TransferPrm struct {
Details []byte Details []byte
} }
// TransferX transfers Amound of GASe-12 from p.From to p.To // TransferX transfers p.Amount of GASe-12 from p.From to p.To
// with details p.Details through smart contract call. // with details p.Details through direct smart contract call.
func (w *Wrapper) TransferX(p TransferPrm) error { 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) from, err := owner.ScriptHashBE(p.From)
if err != nil { if err != nil {
return errors.Wrap(err, "invalid sender") return errors.Wrap(err, "invalid sender")
@ -36,5 +46,10 @@ func (w *Wrapper) TransferX(p TransferPrm) error {
args.SetDetails(p.Details) args.SetDetails(p.Details)
// invoke smart contract call // invoke smart contract call
return w.client.TransferX(args) f := w.client.TransferX
if notary {
f = w.client.TransferXNotary
}
return f(args)
} }

View file

@ -21,14 +21,14 @@ func (e *StopEstimation) SetEpoch(v int64) {
} }
func (c *Client) StartEstimation(args StartEstimation) error { func (c *Client) StartEstimation(args StartEstimation) error {
return errors.Wrapf(c.client.Invoke( return errors.Wrapf(c.client.NotaryInvoke(
c.startEstimation, c.startEstimation,
args.epoch, args.epoch,
), "could not invoke method (%s)", c.startEstimation) ), "could not invoke method (%s)", c.startEstimation)
} }
func (c *Client) StopEstimation(args StopEstimation) error { func (c *Client) StopEstimation(args StopEstimation) error {
return errors.Wrapf(c.client.Invoke( return errors.Wrapf(c.client.NotaryInvoke(
c.stopEstimation, c.stopEstimation,
args.epoch, args.epoch,
), "could not invoke method (%s)", c.stopEstimation) ), "could not invoke method (%s)", c.stopEstimation)

View file

@ -61,3 +61,14 @@ func (s StaticClient) TestInvoke(method string, args ...interface{}) ([]stackite
args..., 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...,
)
}