frostfs-node/pkg/morph/client/balance/transfer.go
Leonard Lyubich 8d201f920e [#496] morph/wrappers: Deprecate all notary-dedicated methods
All client wrappers should use underlying static client with enabled notary
work mode in order to produce invocations of notary contract.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2021-05-25 16:35:52 +03:00

76 lines
1.7 KiB
Go

package balance
import (
"fmt"
)
// TransferXArgs groups the arguments
// of "transferX" invocation call.
type TransferXArgs struct {
amount int64 // amount in GASe-12
sender []byte // sender's wallet script hash
recipient []byte // recipient's wallet script hash
details []byte // transfer details
}
// SetAmount sets amount of funds to transfer
// in GASe-12.
func (t *TransferXArgs) SetAmount(v int64) {
t.amount = v
}
// SetSender sets wallet script hash
// of the sender of funds in a binary format.
func (t *TransferXArgs) SetSender(v []byte) {
t.sender = v
}
// SetRecipient sets wallet script hash
// of the recipient of funds in a binary format.
func (t *TransferXArgs) SetRecipient(v []byte) {
t.recipient = v
}
// SetDetails sets details of the money transaction
// in a binary format.
func (t *TransferXArgs) SetDetails(v []byte) {
t.details = v
}
// TransferX directly invokes the call of "transferX" method
// of NeoFS Balance contract.
func (c *Client) TransferX(args TransferXArgs) error {
return c.transferX(false, args)
}
// TransferXNotary invokes the call of "transferX" method
// of NeoFS Balance contract via notary contract.
//
// Deprecated: construct underlying StaticClient with TryNotary() option
// and use TransferX.
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
}
err := f(
c.transferXMethod,
args.sender,
args.recipient,
args.amount,
args.details,
)
if err != nil {
return fmt.Errorf("could not invoke method (%s): %w", c.transferXMethod, err)
}
return nil
}