Merge pull request #7 from grassrootseconomics/sohail/total-supply

add: (feat) erc20 total supply
This commit is contained in:
Mohamed Sohail 2022-05-23 12:49:40 +03:00 committed by GitHub
commit 2070f9afcd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -13,6 +13,7 @@ type ERC20Token struct {
Name string Name string
Symbol string Symbol string
Decimals big.Int Decimals big.Int
TotalSupply big.Int
} }
func (c *CicNet) ERC20TokenInfo(ctx context.Context, tokenAddress common.Address) (ERC20Token, error) { func (c *CicNet) ERC20TokenInfo(ctx context.Context, tokenAddress common.Address) (ERC20Token, error) {
@ -20,6 +21,7 @@ func (c *CicNet) ERC20TokenInfo(ctx context.Context, tokenAddress common.Address
tokenName string tokenName string
tokenSymbol string tokenSymbol string
tokenDecimals big.Int tokenDecimals big.Int
totalSupply big.Int
) )
err := c.provider.EthClient.CallCtx( err := c.provider.EthClient.CallCtx(
@ -27,6 +29,7 @@ func (c *CicNet) ERC20TokenInfo(ctx context.Context, tokenAddress common.Address
eth.CallFunc(w3.MustNewFunc("name()", "string"), tokenAddress).Returns(&tokenName), eth.CallFunc(w3.MustNewFunc("name()", "string"), tokenAddress).Returns(&tokenName),
eth.CallFunc(w3.MustNewFunc("symbol()", "string"), tokenAddress).Returns(&tokenSymbol), eth.CallFunc(w3.MustNewFunc("symbol()", "string"), tokenAddress).Returns(&tokenSymbol),
eth.CallFunc(w3.MustNewFunc("decimals()", "uint256"), tokenAddress).Returns(&tokenDecimals), eth.CallFunc(w3.MustNewFunc("decimals()", "uint256"), tokenAddress).Returns(&tokenDecimals),
eth.CallFunc(w3.MustNewFunc("totalSupply()", "uint256"), tokenAddress).Returns(&totalSupply),
) )
if err != nil { if err != nil {
return ERC20Token{}, err return ERC20Token{}, err
@ -36,6 +39,7 @@ func (c *CicNet) ERC20TokenInfo(ctx context.Context, tokenAddress common.Address
Name: tokenName, Name: tokenName,
Symbol: tokenSymbol, Symbol: tokenSymbol,
Decimals: tokenDecimals, Decimals: tokenDecimals,
TotalSupply: totalSupply,
}, nil }, nil
} }
func (c *CicNet) BalanceOf(ctx context.Context, tokenAddress common.Address, accountAddress common.Address) (big.Int, error) { func (c *CicNet) BalanceOf(ctx context.Context, tokenAddress common.Address, accountAddress common.Address) (big.Int, error) {