[#16] ir: Use mint and burn methods in balance contract
Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
27fcf2cc1d
commit
58cb90966a
2 changed files with 45 additions and 17 deletions
|
@ -22,11 +22,20 @@ type (
|
|||
Amount int64 // in Fixed16
|
||||
Until uint64 // epochs
|
||||
}
|
||||
|
||||
// MintBurnParams for Mint and Burn invocations.
|
||||
MintBurnParams struct {
|
||||
ScriptHash []byte
|
||||
Amount int64 // in Fixed16
|
||||
Comment []byte
|
||||
}
|
||||
)
|
||||
|
||||
const (
|
||||
transferXMethod = "transferX"
|
||||
lockMethod = "lock"
|
||||
mintMethod = "mint"
|
||||
burnMethod = "burn"
|
||||
)
|
||||
|
||||
// TransferBalanceX invokes transferX method.
|
||||
|
@ -43,6 +52,32 @@ func TransferBalanceX(cli *client.Client, con util.Uint160, p *TransferXParams)
|
|||
)
|
||||
}
|
||||
|
||||
// Mint assets in contract.
|
||||
func Mint(cli *client.Client, con util.Uint160, p *MintBurnParams) error {
|
||||
if cli == nil {
|
||||
return client.ErrNilClient
|
||||
}
|
||||
|
||||
return cli.Invoke(con, extraFee, mintMethod,
|
||||
p.ScriptHash,
|
||||
p.Amount,
|
||||
p.Comment,
|
||||
)
|
||||
}
|
||||
|
||||
// Burn minted assets.
|
||||
func Burn(cli *client.Client, con util.Uint160, p *MintBurnParams) error {
|
||||
if cli == nil {
|
||||
return client.ErrNilClient
|
||||
}
|
||||
|
||||
return cli.Invoke(con, extraFee, burnMethod,
|
||||
p.ScriptHash,
|
||||
p.Amount,
|
||||
p.Comment,
|
||||
)
|
||||
}
|
||||
|
||||
// LockAsset invokes Lock method.
|
||||
func LockAsset(cli *client.Client, con util.Uint160, p *LockParams) error {
|
||||
if cli == nil {
|
||||
|
|
|
@ -15,11 +15,6 @@ const (
|
|||
lockAccountLifetime uint64 = 20
|
||||
)
|
||||
|
||||
var (
|
||||
// fedReserveAddr is a special account in balance contract.
|
||||
fedReserveAddr = []byte{0x0F, 0xED}
|
||||
)
|
||||
|
||||
// Process deposit event by invoking balance contract and sending native
|
||||
// gas in morph chain.
|
||||
func (np *Processor) processDeposit(deposit *neofsEvent.Deposit) {
|
||||
|
@ -29,12 +24,11 @@ func (np *Processor) processDeposit(deposit *neofsEvent.Deposit) {
|
|||
}
|
||||
|
||||
// send transferX to balance contract
|
||||
err := invoke.TransferBalanceX(np.morphClient, np.balanceContract,
|
||||
&invoke.TransferXParams{
|
||||
Sender: fedReserveAddr,
|
||||
Receiver: deposit.To().BytesBE(),
|
||||
Amount: deposit.Amount() * 1_0000_0000, // from Fixed8 to Fixed16
|
||||
Comment: append([]byte(txLogPrefix), deposit.ID()...),
|
||||
err := invoke.Mint(np.morphClient, np.balanceContract,
|
||||
&invoke.MintBurnParams{
|
||||
ScriptHash: deposit.To().BytesBE(),
|
||||
Amount: deposit.Amount() * 1_0000_0000, // from Fixed8 to Fixed16
|
||||
Comment: append([]byte(txLogPrefix), deposit.ID()...),
|
||||
})
|
||||
if err != nil {
|
||||
np.log.Error("can't transfer assets to balance contract", zap.Error(err))
|
||||
|
@ -91,12 +85,11 @@ func (np *Processor) processCheque(cheque *neofsEvent.Cheque) {
|
|||
return
|
||||
}
|
||||
|
||||
err := invoke.TransferBalanceX(np.morphClient, np.balanceContract,
|
||||
&invoke.TransferXParams{
|
||||
Sender: cheque.LockAccount().BytesBE(),
|
||||
Receiver: fedReserveAddr,
|
||||
Amount: cheque.Amount() * 1_0000_0000, // from Fixed8 to Fixed16
|
||||
Comment: append([]byte(txLogPrefix), cheque.ID()...),
|
||||
err := invoke.Burn(np.morphClient, np.balanceContract,
|
||||
&invoke.MintBurnParams{
|
||||
ScriptHash: cheque.LockAccount().BytesBE(),
|
||||
Amount: cheque.Amount() * 1_0000_0000, // from Fixed8 to Fixed16
|
||||
Comment: append([]byte(txLogPrefix), cheque.ID()...),
|
||||
})
|
||||
if err != nil {
|
||||
np.log.Error("can't transfer assets to fed contract", zap.Error(err))
|
||||
|
|
Loading…
Reference in a new issue