mirror of
https://github.com/GrassrootsEconomics/cic-dw.git
synced 2026-05-16 19:35:25 +02:00
add: token syncer
core: - add koanf for runtime config loading - cicnet connection must dial else panic - add db connection init - add goyesql for convenient querying - add async tasker processor (scheduler, processor) dev: - add redis server to dev docker-compose - update volume to prune-able local
This commit is contained in:
@@ -10,16 +10,13 @@ type CicNet struct {
|
||||
tokenIndex common.Address
|
||||
}
|
||||
|
||||
func NewCicNet(rpcEndpoint string, tokenIndex common.Address) (*CicNet, error) {
|
||||
ethClient, err := w3.Dial(rpcEndpoint)
|
||||
if err != nil {
|
||||
return &CicNet{}, err
|
||||
}
|
||||
func NewCicNet(rpcEndpoint string, tokenIndex common.Address) *CicNet {
|
||||
ethClient := w3.MustDial(rpcEndpoint)
|
||||
|
||||
return &CicNet{
|
||||
ethClient: ethClient,
|
||||
tokenIndex: tokenIndex,
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c *CicNet) Close() error {
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/lmittmann/w3"
|
||||
"github.com/lmittmann/w3/module/eth"
|
||||
"math/big"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func (c *CicNet) EntryCount(ctx context.Context) (big.Int, error) {
|
||||
@@ -22,7 +23,7 @@ func (c *CicNet) EntryCount(ctx context.Context) (big.Int, error) {
|
||||
return tokenCount, nil
|
||||
}
|
||||
|
||||
func (c *CicNet) AddressAtIndex(ctx context.Context, index *big.Int) (common.Address, error) {
|
||||
func (c *CicNet) AddressAtIndex(ctx context.Context, index *big.Int) (string, error) {
|
||||
var address common.Address
|
||||
|
||||
err := c.ethClient.CallCtx(
|
||||
@@ -30,8 +31,9 @@ func (c *CicNet) AddressAtIndex(ctx context.Context, index *big.Int) (common.Add
|
||||
eth.CallFunc(w3.MustNewFunc("entry(uint256 _idx)", "address"), c.tokenIndex, index).Returns(&address),
|
||||
)
|
||||
if err != nil {
|
||||
return [20]byte{}, err
|
||||
return "", err
|
||||
}
|
||||
|
||||
return address, nil
|
||||
// strip 0x at pkg level
|
||||
return strings.Trim(address.String(), "0x"), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user