2021-01-26 10:21:16 +00:00
|
|
|
package balance
|
|
|
|
|
|
|
|
import (
|
2021-05-18 08:12:51 +00:00
|
|
|
"fmt"
|
2021-11-09 20:52:29 +00:00
|
|
|
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
2021-01-26 10:21:16 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// 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
|
2021-11-14 22:04:19 +00:00
|
|
|
|
|
|
|
client.InvokePrmOptional
|
2021-01-26 10:21:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|
|
|
|
|
2021-02-25 16:49:05 +00:00
|
|
|
// TransferX directly invokes the call of "transferX" method
|
2021-01-26 10:21:16 +00:00
|
|
|
// of NeoFS Balance contract.
|
|
|
|
func (c *Client) TransferX(args TransferXArgs) error {
|
2021-11-09 20:52:29 +00:00
|
|
|
prm := client.InvokePrm{}
|
|
|
|
|
2022-01-29 13:06:36 +00:00
|
|
|
prm.SetMethod(transferXMethod)
|
2021-11-09 20:52:29 +00:00
|
|
|
prm.SetArgs(args.sender, args.recipient, args.amount, args.details)
|
2021-11-14 22:04:19 +00:00
|
|
|
prm.InvokePrmOptional = args.InvokePrmOptional
|
2021-11-09 20:52:29 +00:00
|
|
|
|
|
|
|
err := c.client.Invoke(prm)
|
2021-05-18 08:12:51 +00:00
|
|
|
if err != nil {
|
2022-01-29 13:06:36 +00:00
|
|
|
return fmt.Errorf("could not invoke method (%s): %w", transferXMethod, err)
|
2021-05-18 08:12:51 +00:00
|
|
|
}
|
2021-06-02 16:29:19 +00:00
|
|
|
|
2021-05-18 08:12:51 +00:00
|
|
|
return nil
|
2021-01-26 10:21:16 +00:00
|
|
|
}
|
2021-05-31 11:50:11 +00:00
|
|
|
|
2021-11-14 22:04:19 +00:00
|
|
|
// MintPrm groups parameters of Mint operation.
|
|
|
|
type MintPrm struct {
|
|
|
|
to []byte
|
|
|
|
amount int64
|
|
|
|
id []byte
|
|
|
|
|
|
|
|
client.InvokePrmOptional
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetTo sets receiver of the transfer.
|
|
|
|
func (m *MintPrm) SetTo(to []byte) {
|
|
|
|
m.to = to
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetAmount sets amount of the transfer.
|
|
|
|
func (m *MintPrm) SetAmount(amount int64) {
|
|
|
|
m.amount = amount
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetID sets ID.
|
|
|
|
func (m *MintPrm) SetID(id []byte) {
|
|
|
|
m.id = id
|
|
|
|
}
|
|
|
|
|
2021-05-31 11:50:11 +00:00
|
|
|
// Mint invokes `mint` method of the balance contract.
|
2021-11-14 22:04:19 +00:00
|
|
|
func (c *Client) Mint(args MintPrm) error {
|
2021-11-09 20:52:29 +00:00
|
|
|
prm := client.InvokePrm{}
|
|
|
|
|
2022-01-29 13:06:36 +00:00
|
|
|
prm.SetMethod(mintMethod)
|
2021-11-14 22:04:19 +00:00
|
|
|
prm.SetArgs(args.to, args.amount, args.id)
|
|
|
|
prm.InvokePrmOptional = args.InvokePrmOptional
|
2021-11-09 20:52:29 +00:00
|
|
|
|
|
|
|
return c.client.Invoke(prm)
|
2021-05-31 11:50:11 +00:00
|
|
|
}
|
|
|
|
|
2021-11-14 22:04:19 +00:00
|
|
|
// BurnPrm groups parameters of Burn operation.
|
|
|
|
type BurnPrm struct {
|
|
|
|
to []byte
|
|
|
|
amount int64
|
|
|
|
id []byte
|
|
|
|
|
|
|
|
client.InvokePrmOptional
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetTo sets receiver.
|
|
|
|
func (b *BurnPrm) SetTo(to []byte) {
|
|
|
|
b.to = to
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetAmount sets amount.
|
|
|
|
func (b *BurnPrm) SetAmount(amount int64) {
|
|
|
|
b.amount = amount
|
|
|
|
}
|
|
|
|
|
2021-11-18 16:18:54 +00:00
|
|
|
// SetID sets ID.
|
2021-11-14 22:04:19 +00:00
|
|
|
func (b *BurnPrm) SetID(id []byte) {
|
|
|
|
b.id = id
|
|
|
|
}
|
|
|
|
|
2021-05-31 11:50:11 +00:00
|
|
|
// Burn invokes `burn` method of the balance contract.
|
2021-11-14 22:04:19 +00:00
|
|
|
func (c *Client) Burn(args BurnPrm) error {
|
2021-11-09 20:52:29 +00:00
|
|
|
prm := client.InvokePrm{}
|
|
|
|
|
2022-01-29 13:06:36 +00:00
|
|
|
prm.SetMethod(burnMethod)
|
2021-11-14 22:04:19 +00:00
|
|
|
prm.SetArgs(args.to, args.amount, args.id)
|
|
|
|
prm.InvokePrmOptional = args.InvokePrmOptional
|
2021-11-09 20:52:29 +00:00
|
|
|
|
|
|
|
return c.client.Invoke(prm)
|
2021-05-31 11:50:11 +00:00
|
|
|
}
|
|
|
|
|
2021-11-14 22:04:19 +00:00
|
|
|
// LockPrm groups parameters of Lock operation.
|
|
|
|
type LockPrm struct {
|
|
|
|
id []byte
|
|
|
|
user []byte
|
|
|
|
lock []byte
|
|
|
|
amount int64
|
|
|
|
dueEpoch int64
|
|
|
|
|
|
|
|
client.InvokePrmOptional
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetID sets ID.
|
|
|
|
func (l *LockPrm) SetID(id []byte) {
|
|
|
|
l.id = id
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetUser set user.
|
|
|
|
func (l *LockPrm) SetUser(user []byte) {
|
|
|
|
l.user = user
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetLock sets lock.
|
|
|
|
func (l *LockPrm) SetLock(lock []byte) {
|
|
|
|
l.lock = lock
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetAmount sets amount.
|
|
|
|
func (l *LockPrm) SetAmount(amount int64) {
|
|
|
|
l.amount = amount
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetDueEpoch sets end of the lock.
|
|
|
|
func (l *LockPrm) SetDueEpoch(dueEpoch int64) {
|
|
|
|
l.dueEpoch = dueEpoch
|
|
|
|
}
|
|
|
|
|
2021-05-31 11:50:11 +00:00
|
|
|
// Lock invokes `lock` method of the balance contract.
|
2021-11-14 22:04:19 +00:00
|
|
|
func (c *Client) Lock(args LockPrm) error {
|
2021-11-09 20:52:29 +00:00
|
|
|
prm := client.InvokePrm{}
|
|
|
|
|
2022-01-29 13:06:36 +00:00
|
|
|
prm.SetMethod(lockMethod)
|
2021-11-14 22:04:19 +00:00
|
|
|
prm.SetArgs(args.id, args.user, args.lock, args.amount, args.dueEpoch)
|
|
|
|
prm.InvokePrmOptional = args.InvokePrmOptional
|
2021-11-09 20:52:29 +00:00
|
|
|
|
|
|
|
return c.client.Invoke(prm)
|
2021-05-31 11:50:11 +00:00
|
|
|
}
|