Compare commits

..

1 Commits

Author SHA1 Message Date
ee6cbe125f feat: add owner bootstrapper script 2024-11-25 15:01:00 +03:00
3 changed files with 103 additions and 3 deletions

View File

@@ -0,0 +1,100 @@
package main
import (
"context"
"flag"
"log/slog"
"os"
"time"
"github.com/grassrootseconomics/eth-indexer/internal/store"
"github.com/grassrootseconomics/eth-indexer/internal/util"
"github.com/grassrootseconomics/ethutils"
"github.com/jackc/pgx/v5/pgxpool"
"github.com/knadh/koanf/v2"
"github.com/lmittmann/w3"
)
const (
insertOwnerQuery = `INSERT INTO ownership_change(
new_owner
contract_address
) VALUES ($1, $2) ON CONFLICT DO NOTHING`
getTokens = `SELECT contract_address FROM tokens`
getPools = `SELECT contract_address FROM pools`
)
var (
build = "dev"
confFlag string
migrationsFolderFlag string
queriesFlag string
lo *slog.Logger
ko *koanf.Koanf
dbPool *pgxpool.Pool
)
func init() {
flag.StringVar(&confFlag, "config", "config.toml", "Config file location")
flag.StringVar(&migrationsFolderFlag, "migrations", "migrations/", "Migrations folder location")
flag.StringVar(&queriesFlag, "queries", "queries.sql", "Queries file location")
flag.Parse()
lo = util.InitLogger()
ko = util.InitConfig(lo, confFlag)
lo.Info("starting owners bootstrapper", "build", build)
}
func main() {
var ownerGetter = w3.MustNewFunc("owner()", "address")
chainProvider := ethutils.NewProvider(ko.MustString("chain.rpc_endpoint"), ko.MustInt64("chain.chainid"))
var err error
dbPool, err = newPgStore()
if err != nil {
lo.Error("could not initialize postgres store", "error", err)
os.Exit(1)
}
ctx, cancel := context.WithTimeout(context.Background(), time.Minute*5)
defer cancel()
// TODO: get all tokens and pools
}
func newPgStore() (*pgxpool.Pool, error) {
store, err := store.NewPgStore(store.PgOpts{
Logg: lo,
DSN: ko.MustString("postgres.dsn"),
MigrationsFolderPath: migrationsFolderFlag,
QueriesFolderPath: queriesFlag,
})
if err != nil {
lo.Error("could not initialize postgres store", "error", err)
os.Exit(1)
}
return store.Pool(), nil
}
func insertOwnershipChange(ctx context.Context, owner string, contractAddress string) error {
_, err := dbPool.Exec(
ctx,
insertOwnerQuery,
owner,
contractAddress,
)
if err != nil {
return err
}
return nil
}

2
go.mod
View File

@@ -6,7 +6,7 @@ require (
github.com/VictoriaMetrics/metrics v1.35.1
github.com/ethereum/go-ethereum v1.14.8
github.com/go-chi/chi/v5 v5.1.0
github.com/grassrootseconomics/eth-tracker v1.5.2-rc
github.com/grassrootseconomics/eth-tracker v1.3.0-rc
github.com/grassrootseconomics/ethutils v1.3.0
github.com/jackc/pgx/v5 v5.7.1
github.com/jackc/tern/v2 v2.2.3

4
go.sum
View File

@@ -94,8 +94,8 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/grassrootseconomics/eth-tracker v1.5.2-rc h1:gY9KDfpQVXl8UaAAETsQEh8Ctnrmo1YmLsqOqtyyyu8=
github.com/grassrootseconomics/eth-tracker v1.5.2-rc/go.mod h1:V2tbrxzuTdkrD/p5zqBOPPoF/gDSVgRbLAo5hmioCIA=
github.com/grassrootseconomics/eth-tracker v1.3.0-rc h1:iYe2rwCBrU5O8x0+HSJRjcPT1h68k/uGd3i/cJJQuTQ=
github.com/grassrootseconomics/eth-tracker v1.3.0-rc/go.mod h1:rLXM5u8FDHnMEdah8ACgo/wfawu4o2sljHGkky2rQKE=
github.com/grassrootseconomics/ethutils v1.3.0 h1:0uX9HG7EujqoNyueYN2gB40zki50AIdxuNLmU0FZroU=
github.com/grassrootseconomics/ethutils v1.3.0/go.mod h1:Wuv1VEZrkLIXqTSEYI3Nh9HG/ZHOUQ+U+xvWJ8QtjgQ=
github.com/holiman/bloomfilter/v2 v2.0.3 h1:73e0e/V0tCydx14a0SCYS/EWCxgwLZ18CZcZKVu0fao=