2020-07-24 13:54:03 +00:00
|
|
|
package invoke
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
|
|
|
)
|
|
|
|
|
|
|
|
type (
|
|
|
|
// LockParams for LockAsset invocation.
|
|
|
|
LockParams struct {
|
|
|
|
ID []byte
|
|
|
|
User util.Uint160
|
|
|
|
LockAccount util.Uint160
|
|
|
|
Amount int64 // in Fixed16
|
|
|
|
Until uint64 // epochs
|
|
|
|
}
|
2020-09-01 11:16:16 +00:00
|
|
|
|
|
|
|
// MintBurnParams for Mint and Burn invocations.
|
|
|
|
MintBurnParams struct {
|
|
|
|
ScriptHash []byte
|
|
|
|
Amount int64 // in Fixed16
|
|
|
|
Comment []byte
|
|
|
|
}
|
2020-07-24 13:54:03 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
transferXMethod = "transferX"
|
2020-08-27 12:37:01 +00:00
|
|
|
lockMethod = "lock"
|
2020-09-01 11:16:16 +00:00
|
|
|
mintMethod = "mint"
|
|
|
|
burnMethod = "burn"
|
2020-10-27 10:25:55 +00:00
|
|
|
precisionMethod = "decimals"
|
2020-07-24 13:54:03 +00:00
|
|
|
)
|
|
|
|
|
2020-09-01 11:16:16 +00:00
|
|
|
// Mint assets in contract.
|
2021-04-29 13:39:09 +00:00
|
|
|
func Mint(cli *client.Client, con util.Uint160, fee SideFeeProvider, p *MintBurnParams) error {
|
2020-09-01 11:16:16 +00:00
|
|
|
if cli == nil {
|
|
|
|
return client.ErrNilClient
|
|
|
|
}
|
|
|
|
|
2021-05-21 07:39:21 +00:00
|
|
|
return cli.NotaryInvoke(con, fee.SideChainFee(), mintMethod,
|
2020-09-01 11:16:16 +00:00
|
|
|
p.ScriptHash,
|
|
|
|
p.Amount,
|
|
|
|
p.Comment,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Burn minted assets.
|
2021-04-29 13:39:09 +00:00
|
|
|
func Burn(cli *client.Client, con util.Uint160, fee SideFeeProvider, p *MintBurnParams) error {
|
2020-09-01 11:16:16 +00:00
|
|
|
if cli == nil {
|
|
|
|
return client.ErrNilClient
|
|
|
|
}
|
|
|
|
|
2021-05-21 07:39:21 +00:00
|
|
|
return cli.NotaryInvoke(con, fee.SideChainFee(), burnMethod,
|
2020-09-01 11:16:16 +00:00
|
|
|
p.ScriptHash,
|
|
|
|
p.Amount,
|
|
|
|
p.Comment,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-07-24 13:54:03 +00:00
|
|
|
// LockAsset invokes Lock method.
|
2021-04-29 13:39:09 +00:00
|
|
|
func LockAsset(cli *client.Client, con util.Uint160, fee SideFeeProvider, p *LockParams) error {
|
2020-07-24 13:54:03 +00:00
|
|
|
if cli == nil {
|
|
|
|
return client.ErrNilClient
|
|
|
|
}
|
|
|
|
|
2021-05-21 07:39:21 +00:00
|
|
|
return cli.NotaryInvoke(con, fee.SideChainFee(), lockMethod,
|
2020-07-24 13:54:03 +00:00
|
|
|
p.ID,
|
|
|
|
p.User.BytesBE(),
|
|
|
|
p.LockAccount.BytesBE(),
|
|
|
|
p.Amount,
|
2020-09-08 09:09:08 +00:00
|
|
|
int64(p.Until),
|
2020-07-24 13:54:03 +00:00
|
|
|
)
|
|
|
|
}
|
2020-10-27 10:25:55 +00:00
|
|
|
|
|
|
|
// BalancePrecision invokes Decimal method that returns precision of NEP-5 contract.
|
|
|
|
func BalancePrecision(cli *client.Client, con util.Uint160) (uint32, error) {
|
|
|
|
if cli == nil {
|
|
|
|
return 0, client.ErrNilClient
|
|
|
|
}
|
|
|
|
|
|
|
|
v, err := cli.TestInvoke(con, precisionMethod)
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
|
|
|
|
precision, err := client.IntFromStackItem(v[0])
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return uint32(precision), nil
|
|
|
|
}
|