2021-01-26 10:21:16 +00:00
|
|
|
package wrapper
|
|
|
|
|
|
|
|
import (
|
2021-11-10 07:08:33 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
2021-05-31 11:50:11 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
2021-11-14 22:04:19 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
2021-01-26 10:21:16 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client/balance"
|
2021-11-10 07:08:33 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/owner"
|
2021-01-26 10:21:16 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// TransferPrm groups parameters of TransferX method.
|
|
|
|
type TransferPrm struct {
|
|
|
|
Amount int64
|
|
|
|
|
|
|
|
From, To *owner.ID
|
|
|
|
|
|
|
|
Details []byte
|
2021-11-14 22:04:19 +00:00
|
|
|
|
|
|
|
client.InvokePrmOptional
|
2021-01-26 10:21:16 +00:00
|
|
|
}
|
|
|
|
|
2021-02-25 16:49:05 +00:00
|
|
|
// TransferX transfers p.Amount of GASe-12 from p.From to p.To
|
|
|
|
// with details p.Details through direct smart contract call.
|
2021-06-02 16:24:30 +00:00
|
|
|
//
|
|
|
|
// If TryNotary is provided, calls notary contract.
|
2021-01-26 10:21:16 +00:00
|
|
|
func (w *Wrapper) TransferX(p TransferPrm) error {
|
2021-11-10 07:08:33 +00:00
|
|
|
from, err := address.StringToUint160(p.From.String())
|
2021-01-26 10:21:16 +00:00
|
|
|
if err != nil {
|
2021-11-10 07:08:33 +00:00
|
|
|
return err
|
2021-01-26 10:21:16 +00:00
|
|
|
}
|
2022-01-04 08:43:33 +00:00
|
|
|
to, err := address.StringToUint160(p.To.String())
|
2021-01-26 10:21:16 +00:00
|
|
|
if err != nil {
|
2021-11-10 07:08:33 +00:00
|
|
|
return err
|
2021-01-26 10:21:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// prepare invocation arguments
|
|
|
|
args := balance.TransferXArgs{}
|
2021-11-10 07:08:33 +00:00
|
|
|
args.SetSender(from.BytesBE())
|
|
|
|
args.SetRecipient(to.BytesBE())
|
2021-01-26 10:21:16 +00:00
|
|
|
args.SetAmount(p.Amount)
|
|
|
|
args.SetDetails(p.Details)
|
2021-11-14 22:04:19 +00:00
|
|
|
args.InvokePrmOptional = p.InvokePrmOptional
|
2021-01-26 10:21:16 +00:00
|
|
|
|
2021-06-02 16:24:30 +00:00
|
|
|
return w.client.TransferX(args)
|
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 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
|
|
|
|
}
|
|
|
|
|
2021-05-31 11:50:11 +00:00
|
|
|
// Mint sends funds to the account.
|
2021-11-14 22:04:19 +00:00
|
|
|
func (w *Wrapper) Mint(prm MintPrm) error {
|
|
|
|
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
|
2021-05-31 11:50:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Burn destroys funds from the account.
|
2021-11-14 22:04:19 +00:00
|
|
|
func (w *Wrapper) Burn(prm BurnPrm) error {
|
|
|
|
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
|
2021-05-31 11:50:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Lock locks fund on the user account.
|
2021-11-14 22:04:19 +00:00
|
|
|
func (w *Wrapper) Lock(prm LockPrm) error {
|
|
|
|
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)
|
2021-05-31 11:50:11 +00:00
|
|
|
}
|