feat(RemoteBurn): Add remote burn collectibles functionality

* Updating smart contract (new burn function)
* remoteBurn() and estimateRemoteBurn() functions
This commit is contained in:
Michal Iskierko 2023-05-05 13:03:06 +02:00 committed by Michał Iskierko
parent f3c826275e
commit 1c17fbeacc
5 changed files with 104 additions and 25 deletions

View File

@ -1 +1 @@
0.151.16 0.152.0

View File

@ -74,12 +74,14 @@ contract CollectibleV1 is
/** /**
* @notice remoteBurn allows the owner to burn a token * @notice remoteBurn allows the owner to burn a token
* @param tokenId The token ID to be burned * @param tokenIds The list of token IDs to be burned
*/ */
function remoteBurn(uint256 tokenId) public onlyOwner { function remoteBurn(uint256[] memory tokenIds) public onlyOwner {
require(remoteBurnable, "NOT_REMOTE_BURNABLE"); require(remoteBurnable, "NOT_REMOTE_BURNABLE");
_burn(tokenId); for (uint256 i = 0; i < tokenIds.length; i++) {
_burn(tokenIds[i]);
}
} }
/** /**

File diff suppressed because one or more lines are too long

View File

@ -6,7 +6,10 @@ import (
"errors" "errors"
"fmt" "fmt"
"math/big" "math/big"
"strings"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
@ -15,6 +18,7 @@ import (
"github.com/status-im/status-go/params" "github.com/status-im/status-go/params"
"github.com/status-im/status-go/rpc" "github.com/status-im/status-go/rpc"
"github.com/status-im/status-go/services/utils" "github.com/status-im/status-go/services/utils"
"github.com/status-im/status-go/services/wallet/bigint"
"github.com/status-im/status-go/transactions" "github.com/status-im/status-go/transactions"
) )
@ -156,6 +160,31 @@ func (api *API) MintTo(ctx context.Context, chainID uint64, contractAddress stri
return tx.Hash().Hex(), nil return tx.Hash().Hex(), nil
} }
func (api *API) RemoteBurn(ctx context.Context, chainID uint64, contractAddress string, txArgs transactions.SendTxArgs, password string, tokenIds []*bigint.BigInt) (string, error) {
if len(tokenIds) == 0 {
return "", errors.New("tokenIds list is empty")
}
contractInst, err := api.newCollectiblesInstance(chainID, contractAddress)
if err != nil {
return "", err
}
transactOpts := txArgs.ToTransactOpts(utils.GetSigner(chainID, api.accountsManager, api.config.KeyStoreDir, txArgs.From, password))
var tempTokenIds []*big.Int
for _, v := range tokenIds {
tempTokenIds = append(tempTokenIds, v.Int)
}
tx, err := contractInst.RemoteBurn(transactOpts, tempTokenIds)
if err != nil {
return "", err
}
return tx.Hash().Hex(), nil
}
func (api *API) ContractOwner(ctx context.Context, chainID uint64, contractAddress string) (string, error) { func (api *API) ContractOwner(ctx context.Context, chainID uint64, contractAddress string) (string, error) {
callOpts := &bind.CallOpts{Context: ctx, Pending: false} callOpts := &bind.CallOpts{Context: ctx, Pending: false}
contractInst, err := api.newCollectiblesInstance(chainID, contractAddress) contractInst, err := api.newCollectiblesInstance(chainID, contractAddress)
@ -188,3 +217,50 @@ func (api *API) validateWalletsAndAmounts(walletAddresses []string, amount int)
} }
return nil return nil
} }
func (api *API) EstimateRemoteBurn(ctx context.Context, chainID uint64, contractAddress string, tokenIds []*bigint.BigInt) (uint64, error) {
if len(tokenIds) == 0 {
return 0, errors.New("token list is empty")
}
ethClient, err := api.RPCClient.EthClient(chainID)
if err != nil {
log.Error(err.Error())
return 0, err
}
collectiblesABI, err := abi.JSON(strings.NewReader(collectibles.CollectiblesABI))
if err != nil {
return 0, err
}
var tempTokenIds []*big.Int
for _, v := range tokenIds {
tempTokenIds = append(tempTokenIds, v.Int)
}
data, err := collectiblesABI.Pack("remoteBurn", tempTokenIds)
if err != nil {
return 0, err
}
ownerAddr, err := api.ContractOwner(ctx, chainID, contractAddress)
if err != nil {
return 0, err
}
toAddr := common.HexToAddress(contractAddress)
fromAddr := common.HexToAddress(ownerAddr)
callMsg := ethereum.CallMsg{
From: fromAddr,
To: &toAddr,
Value: big.NewInt(0),
Data: data,
}
estimate, err := ethClient.EstimateGas(ctx, callMsg)
if err != nil {
return 0, err
}
return estimate + uint64(float32(estimate)*0.1), nil
}

View File

@ -71,13 +71,14 @@ type MultiTransactionResult struct {
type PendingTrxType string type PendingTrxType string
const ( const (
RegisterENS PendingTrxType = "RegisterENS" RegisterENS PendingTrxType = "RegisterENS"
ReleaseENS PendingTrxType = "ReleaseENS" ReleaseENS PendingTrxType = "ReleaseENS"
SetPubKey PendingTrxType = "SetPubKey" SetPubKey PendingTrxType = "SetPubKey"
BuyStickerPack PendingTrxType = "BuyStickerPack" BuyStickerPack PendingTrxType = "BuyStickerPack"
WalletTransfer PendingTrxType = "WalletTransfer" WalletTransfer PendingTrxType = "WalletTransfer"
CollectibleDeployment PendingTrxType = "CollectibleDeployment" CollectibleDeployment PendingTrxType = "CollectibleDeployment"
CollectibleAirdrop PendingTrxType = "CollectibleAirdrop" CollectibleAirdrop PendingTrxType = "CollectibleAirdrop"
CollectibleRemoteSelfDestruct PendingTrxType = "CollectibleRemoteSelfDestruct"
) )
type PendingTransaction struct { type PendingTransaction struct {