cic-go/batch_balance/token_balances.go
Mohamed Sohail 8ebcbbf479
add: (wip) on-chain balance query (#5)
* add: smart-contracts

* add: implement and test

changes to contract:
- returns 0 instead of false error status
- func return type is []big.Int

* fix: test name

* fix: (test) env var name
2022-05-17 20:33:03 +03:00

25 lines
585 B
Go

package balance
import (
"context"
"math/big"
"github.com/ethereum/go-ethereum/common"
"github.com/lmittmann/w3"
"github.com/lmittmann/w3/module/eth"
)
func (c *BatchBalance) TokensBalance(ctx context.Context, owner common.Address, tokens []common.Address) ([]*big.Int, error) {
var balancesResults []*big.Int
err := c.ethClient.CallCtx(
ctx,
eth.CallFunc(w3.MustNewFunc("tokensBalance(address owner, address[] contracts)", "uint256[]"), c.batchContract, owner, tokens).Returns(&balancesResults),
)
if err != nil {
return nil, err
}
return balancesResults, nil
}