[#971] morph/balance: Add optional parameters

Add optional parameters to the client call
signature.

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2021-11-15 01:04:19 +03:00 committed by Alex Vanin
parent dbf3a2f2fb
commit 644baf4985
2 changed files with 213 additions and 12 deletions

View file

@ -16,6 +16,8 @@ type TransferXArgs struct {
recipient []byte // recipient's wallet script hash recipient []byte // recipient's wallet script hash
details []byte // transfer details details []byte // transfer details
client.InvokePrmOptional
} }
// SetAmount sets amount of funds to transfer // SetAmount sets amount of funds to transfer
@ -49,6 +51,7 @@ func (c *Client) TransferX(args TransferXArgs) error {
prm.SetMethod(c.transferXMethod) prm.SetMethod(c.transferXMethod)
prm.SetArgs(args.sender, args.recipient, args.amount, args.details) prm.SetArgs(args.sender, args.recipient, args.amount, args.details)
prm.InvokePrmOptional = args.InvokePrmOptional
err := c.client.Invoke(prm) err := c.client.Invoke(prm)
if err != nil { if err != nil {
@ -58,32 +61,119 @@ func (c *Client) TransferX(args TransferXArgs) error {
return nil 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. // Mint invokes `mint` method of the balance contract.
func (c *Client) Mint(to []byte, amount int64, id []byte) error { func (c *Client) Mint(args MintPrm) error {
prm := client.InvokePrm{} prm := client.InvokePrm{}
prm.SetMethod(c.mintMethod) prm.SetMethod(c.mintMethod)
prm.SetArgs(to, amount, id) prm.SetArgs(args.to, args.amount, args.id)
prm.InvokePrmOptional = args.InvokePrmOptional
return c.client.Invoke(prm) 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. // Burn invokes `burn` method of the balance contract.
func (c *Client) Burn(to []byte, amount int64, id []byte) error { func (c *Client) Burn(args BurnPrm) error {
prm := client.InvokePrm{} prm := client.InvokePrm{}
prm.SetMethod(c.burnMethod) prm.SetMethod(c.burnMethod)
prm.SetArgs(to, amount, id) prm.SetArgs(args.to, args.amount, args.id)
prm.InvokePrmOptional = args.InvokePrmOptional
return c.client.Invoke(prm) 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. // Lock invokes `lock` method of the balance contract.
func (c *Client) Lock(id, user, lock []byte, amount, dueEpoch int64) error { func (c *Client) Lock(args LockPrm) error {
prm := client.InvokePrm{} prm := client.InvokePrm{}
prm.SetMethod(c.lockMethod) prm.SetMethod(c.lockMethod)
prm.SetArgs(id, user, lock, amount, dueEpoch) prm.SetArgs(args.id, args.user, args.lock, args.amount, args.dueEpoch)
prm.InvokePrmOptional = args.InvokePrmOptional
return c.client.Invoke(prm) return c.client.Invoke(prm)
} }

View file

@ -3,6 +3,7 @@ package wrapper
import ( import (
"github.com/nspcc-dev/neo-go/pkg/encoding/address" "github.com/nspcc-dev/neo-go/pkg/encoding/address"
"github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
"github.com/nspcc-dev/neofs-node/pkg/morph/client/balance" "github.com/nspcc-dev/neofs-node/pkg/morph/client/balance"
"github.com/nspcc-dev/neofs-sdk-go/owner" "github.com/nspcc-dev/neofs-sdk-go/owner"
) )
@ -14,6 +15,8 @@ type TransferPrm struct {
From, To *owner.ID From, To *owner.ID
Details []byte Details []byte
client.InvokePrmOptional
} }
// TransferX transfers p.Amount of GASe-12 from p.From to p.To // TransferX transfers p.Amount of GASe-12 from p.From to p.To
@ -36,21 +39,129 @@ func (w *Wrapper) TransferX(p TransferPrm) error {
args.SetRecipient(to.BytesBE()) args.SetRecipient(to.BytesBE())
args.SetAmount(p.Amount) args.SetAmount(p.Amount)
args.SetDetails(p.Details) args.SetDetails(p.Details)
args.InvokePrmOptional = p.InvokePrmOptional
return w.client.TransferX(args) return w.client.TransferX(args)
} }
// MintPrm groups parameters of Mint operation.
type MintPrm struct {
to util.Uint160
amount int64
id []byte
client.InvokePrmOptional
}
// SetTo sets receiver of the transfer.
func (m *MintPrm) SetTo(to util.Uint160) {
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 sends funds to the account. // Mint sends funds to the account.
func (w *Wrapper) Mint(to util.Uint160, amount int64, id []byte) error { func (w *Wrapper) Mint(prm MintPrm) error {
return w.client.Mint(to.BytesBE(), amount, id) args := balance.MintPrm{}
args.SetTo(prm.to.BytesBE())
args.SetAmount(prm.amount)
args.SetID(prm.id)
args.InvokePrmOptional = prm.InvokePrmOptional
return w.client.Mint(args)
}
// BurnPrm groups parameters of Burn operation.
type BurnPrm struct {
to util.Uint160
amount int64
id []byte
client.InvokePrmOptional
}
// SetTo sets receiver.
func (b *BurnPrm) SetTo(to util.Uint160) {
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 destroys funds from the account. // Burn destroys funds from the account.
func (w *Wrapper) Burn(to util.Uint160, amount int64, id []byte) error { func (w *Wrapper) Burn(prm BurnPrm) error {
return w.client.Burn(to.BytesBE(), amount, id) args := balance.BurnPrm{}
args.SetTo(prm.to.BytesBE())
args.SetAmount(prm.amount)
args.SetID(prm.id)
args.InvokePrmOptional = prm.InvokePrmOptional
return w.client.Burn(args)
}
// LockPrm groups parameters of Lock operation.
type LockPrm struct {
id []byte
user util.Uint160
lock util.Uint160
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 util.Uint160) {
l.user = user
}
// SetLock sets lock.
func (l *LockPrm) SetLock(lock util.Uint160) {
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 locks fund on the user account. // Lock locks fund on the user account.
func (w *Wrapper) Lock(id []byte, user, lock util.Uint160, amount, dueEpoch int64) error { func (w *Wrapper) Lock(prm LockPrm) error {
return w.client.Lock(id, user.BytesBE(), lock.BytesBE(), amount, dueEpoch) args := balance.LockPrm{}
args.SetID(prm.id)
args.SetUser(prm.user.BytesBE())
args.SetLock(prm.lock.BytesBE())
args.SetAmount(prm.amount)
args.SetDueEpoch(prm.dueEpoch)
args.InvokePrmOptional = prm.InvokePrmOptional
return w.client.Lock(args)
} }