From 1592d2a07988c0dc85f686565016623e93f1a6dc Mon Sep 17 00:00:00 2001 From: Michal Iskierko Date: Thu, 13 Jul 2023 10:57:37 +0200 Subject: [PATCH] feat(RemoteDestructedAmount): Add RemoteDestructedAmount function Issue #1182 --- services/collectibles/api.go | 39 ++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/services/collectibles/api.go b/services/collectibles/api.go index 9294f8ce6..c243126e9 100644 --- a/services/collectibles/api.go +++ b/services/collectibles/api.go @@ -332,6 +332,32 @@ func (api *API) EstimateMintAssets(ctx context.Context, chainID uint64, contract return api.estimateMethod(ctx, chainID, contractAddress, "mintTo", usersAddresses, amountsList) } +// This is only ERC721 function +func (api *API) RemoteDestructedAmount(ctx context.Context, chainID uint64, contractAddress string) (*bigint.BigInt, error) { + callOpts := &bind.CallOpts{Context: ctx, Pending: false} + contractInst, err := api.newCollectiblesInstance(chainID, contractAddress) + if err != nil { + return nil, err + } + + // total supply = airdropped only (w/o burnt) + totalSupply, err := contractInst.TotalSupply(callOpts) + if err != nil { + return nil, err + } + + // minted = all created tokens (airdropped and remotely destructed) + mintedCount, err := contractInst.MintedCount(callOpts) + if err != nil { + return nil, err + } + + var res = new(big.Int) + res.Sub(mintedCount, totalSupply) + + return &bigint.BigInt{Int: res}, nil +} + // This is only ERC721 function func (api *API) RemoteBurn(ctx context.Context, chainID uint64, contractAddress string, txArgs transactions.SendTxArgs, password string, tokenIds []*bigint.BigInt) (string, error) { err := api.validateTokens(tokenIds) @@ -411,19 +437,6 @@ func (api *API) ContractOwner(ctx context.Context, chainID uint64, contractAddre return "", fmt.Errorf("unknown token type: %v", tokenType) } -func (api *API) MintedCount(ctx context.Context, chainID uint64, contractAddress string) (*big.Int, error) { - callOpts := &bind.CallOpts{Context: ctx, Pending: false} - contractInst, err := api.newCollectiblesInstance(chainID, contractAddress) - if err != nil { - return nil, err - } - mintedCount, err := contractInst.MintedCount(callOpts) - if err != nil { - return nil, err - } - return mintedCount, nil -} - func (api *API) RemainingSupply(ctx context.Context, chainID uint64, contractAddress string) (*bigint.BigInt, error) { tokenType, err := api.db.GetTokenType(chainID, contractAddress) if err != nil {