forked from TrueCloudLab/frostfs-node
[#625] client/balance: remove intermediate wrapper
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
c7a8c762e0
commit
6f50fefbea
17 changed files with 239 additions and 524 deletions
|
@ -3,177 +3,45 @@ package balance
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
||||
"github.com/nspcc-dev/neofs-sdk-go/owner"
|
||||
)
|
||||
|
||||
// TransferXArgs groups the arguments
|
||||
// of "transferX" invocation call.
|
||||
type TransferXArgs struct {
|
||||
amount int64 // amount in GASe-12
|
||||
// TransferPrm groups parameters of TransferX method.
|
||||
type TransferPrm struct {
|
||||
Amount int64
|
||||
|
||||
sender []byte // sender's wallet script hash
|
||||
From, To *owner.ID
|
||||
|
||||
recipient []byte // recipient's wallet script hash
|
||||
|
||||
details []byte // transfer details
|
||||
Details []byte
|
||||
|
||||
client.InvokePrmOptional
|
||||
}
|
||||
|
||||
// SetAmount sets amount of funds to transfer
|
||||
// in GASe-12.
|
||||
func (t *TransferXArgs) SetAmount(v int64) {
|
||||
t.amount = v
|
||||
}
|
||||
// TransferX transfers p.Amount of GASe-12 from p.From to p.To
|
||||
// with details p.Details through direct smart contract call.
|
||||
//
|
||||
// If TryNotary is provided, calls notary contract.
|
||||
func (c *Client) TransferX(p TransferPrm) error {
|
||||
from, err := address.StringToUint160(p.From.String())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// SetSender sets wallet script hash
|
||||
// of the sender of funds in a binary format.
|
||||
func (t *TransferXArgs) SetSender(v []byte) {
|
||||
t.sender = v
|
||||
}
|
||||
to, err := address.StringToUint160(p.To.String())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 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 {
|
||||
prm := client.InvokePrm{}
|
||||
|
||||
prm.SetMethod(transferXMethod)
|
||||
prm.SetArgs(args.sender, args.recipient, args.amount, args.details)
|
||||
prm.InvokePrmOptional = args.InvokePrmOptional
|
||||
prm.SetArgs(from.BytesBE(), to.BytesBE(), p.Amount, p.Details)
|
||||
prm.InvokePrmOptional = p.InvokePrmOptional
|
||||
|
||||
err := c.client.Invoke(prm)
|
||||
err = c.client.Invoke(prm)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not invoke method (%s): %w", transferXMethod, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
// Mint invokes `mint` method of the balance contract.
|
||||
func (c *Client) Mint(args MintPrm) error {
|
||||
prm := client.InvokePrm{}
|
||||
|
||||
prm.SetMethod(mintMethod)
|
||||
prm.SetArgs(args.to, args.amount, args.id)
|
||||
prm.InvokePrmOptional = args.InvokePrmOptional
|
||||
|
||||
return c.client.Invoke(prm)
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
// SetID sets ID.
|
||||
func (b *BurnPrm) SetID(id []byte) {
|
||||
b.id = id
|
||||
}
|
||||
|
||||
// Burn invokes `burn` method of the balance contract.
|
||||
func (c *Client) Burn(args BurnPrm) error {
|
||||
prm := client.InvokePrm{}
|
||||
|
||||
prm.SetMethod(burnMethod)
|
||||
prm.SetArgs(args.to, args.amount, args.id)
|
||||
prm.InvokePrmOptional = args.InvokePrmOptional
|
||||
|
||||
return c.client.Invoke(prm)
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
// Lock invokes `lock` method of the balance contract.
|
||||
func (c *Client) Lock(args LockPrm) error {
|
||||
prm := client.InvokePrm{}
|
||||
|
||||
prm.SetMethod(lockMethod)
|
||||
prm.SetArgs(args.id, args.user, args.lock, args.amount, args.dueEpoch)
|
||||
prm.InvokePrmOptional = args.InvokePrmOptional
|
||||
|
||||
return c.client.Invoke(prm)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue