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:
2022-05-03 18:54:51 +03:00
parent d9f42005af
commit 05ab865c63
13 changed files with 630 additions and 63 deletions

View File

@@ -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 {

View File

@@ -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
}