[#404] morph/client: Support notary calls in wrappers
Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
71dce97b76
commit
83980ccb85
4 changed files with 48 additions and 7 deletions
|
@ -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,
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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...,
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue