forked from TrueCloudLab/frostfs-node
[#326] morph/balance: Provide interface to "transferX" method's invocations
Implement TransferX method on Balance contract client. Implement TransferX method on Balance client's wrapper that encapsulates it's TransferX call. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
f7a9e43165
commit
20ad0ae82a
3 changed files with 110 additions and 0 deletions
40
pkg/morph/client/balance/wrapper/transfer.go
Normal file
40
pkg/morph/client/balance/wrapper/transfer.go
Normal file
|
@ -0,0 +1,40 @@
|
|||
package wrapper
|
||||
|
||||
import (
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/owner"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/morph/client/balance"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// TransferPrm groups parameters of TransferX method.
|
||||
type TransferPrm struct {
|
||||
Amount int64
|
||||
|
||||
From, To *owner.ID
|
||||
|
||||
Details []byte
|
||||
}
|
||||
|
||||
// TransferX transfers Amound of GASe-12 from p.From to p.To
|
||||
// with details p.Details through smart contract call.
|
||||
func (w *Wrapper) TransferX(p TransferPrm) error {
|
||||
from, err := owner.ScriptHashBE(p.From)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "invalid sender")
|
||||
}
|
||||
|
||||
to, err := owner.ScriptHashBE(p.To)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "invalid recipient")
|
||||
}
|
||||
|
||||
// prepare invocation arguments
|
||||
args := balance.TransferXArgs{}
|
||||
args.SetSender(from)
|
||||
args.SetRecipient(to)
|
||||
args.SetAmount(p.Amount)
|
||||
args.SetDetails(p.Details)
|
||||
|
||||
// invoke smart contract call
|
||||
return w.client.TransferX(args)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue