frostfs-node/pkg/morph/client/balance/wrapper/transfer.go
Leonard Lyubich 20ad0ae82a [#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>
2021-01-29 11:04:30 +03:00

40 lines
906 B
Go

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)
}