2021-01-26 10:21:16 +00:00
|
|
|
package wrapper
|
|
|
|
|
|
|
|
import (
|
2021-05-18 08:12:51 +00:00
|
|
|
"fmt"
|
|
|
|
|
2021-05-31 11:50:11 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
2021-01-26 10:21:16 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/owner"
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client/balance"
|
|
|
|
)
|
|
|
|
|
|
|
|
// TransferPrm groups parameters of TransferX method.
|
|
|
|
type TransferPrm struct {
|
|
|
|
Amount int64
|
|
|
|
|
|
|
|
From, To *owner.ID
|
|
|
|
|
|
|
|
Details []byte
|
|
|
|
}
|
|
|
|
|
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 {
|
|
|
|
from, err := owner.ScriptHashBE(p.From)
|
|
|
|
if err != nil {
|
2021-05-18 08:12:51 +00:00
|
|
|
return fmt.Errorf("invalid sender: %w", err)
|
2021-01-26 10:21:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
to, err := owner.ScriptHashBE(p.To)
|
|
|
|
if err != nil {
|
2021-05-18 08:12:51 +00:00
|
|
|
return fmt.Errorf("invalid recipient: %w", err)
|
2021-01-26 10:21:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// prepare invocation arguments
|
|
|
|
args := balance.TransferXArgs{}
|
|
|
|
args.SetSender(from)
|
|
|
|
args.SetRecipient(to)
|
|
|
|
args.SetAmount(p.Amount)
|
|
|
|
args.SetDetails(p.Details)
|
|
|
|
|
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
|
|
|
|
|
|
|
// Mint sends funds to the account.
|
|
|
|
func (w *Wrapper) Mint(to util.Uint160, amount int64, id []byte) error {
|
|
|
|
return w.client.Mint(to.BytesBE(), amount, id)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Burn destroys funds from the account.
|
|
|
|
func (w *Wrapper) Burn(to util.Uint160, amount int64, id []byte) error {
|
|
|
|
return w.client.Burn(to.BytesBE(), amount, id)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Lock locks fund on the user account.
|
|
|
|
func (w *Wrapper) Lock(id []byte, user, lock util.Uint160, amount, dueEpoch int64) error {
|
|
|
|
return w.client.Lock(id, user.BytesBE(), lock.BytesBE(), amount, dueEpoch)
|
|
|
|
}
|