cic-go/net/token_index.go
Mohammed Sohail 3601b61c20
refactor: rpc provider
- provider now lives on its own
- existing modules need the provider as a param
2022-05-18 12:50:45 +03:00

39 lines
802 B
Go

package net
import (
"context"
"math/big"
"github.com/ethereum/go-ethereum/common"
"github.com/lmittmann/w3"
"github.com/lmittmann/w3/module/eth"
)
func (c *CicNet) EntryCount(ctx context.Context) (big.Int, error) {
var tokenCount big.Int
err := c.provider.EthClient.CallCtx(
ctx,
eth.CallFunc(w3.MustNewFunc("entryCount()", "uint256"), c.tokenIndex).Returns(&tokenCount),
)
if err != nil {
return big.Int{}, err
}
return tokenCount, nil
}
func (c *CicNet) AddressAtIndex(ctx context.Context, index *big.Int) (string, error) {
var address common.Address
err := c.provider.EthClient.CallCtx(
ctx,
eth.CallFunc(w3.MustNewFunc("entry(uint256 _idx)", "address"), c.tokenIndex, index).Returns(&address),
)
if err != nil {
return "", err
}
return address.String(), nil
}