fix: migrated runes indexer integration to new cli

This commit is contained in:
Gaze
2024-04-16 23:38:15 +07:00
parent f4508b6e80
commit b929fbed58
2 changed files with 26 additions and 6 deletions

View File

@@ -124,22 +124,32 @@ func runHandler(opts *runCmdOptions, cmd *cobra.Command, _ []string) error {
}
// Initialize Runes Indexer
if opts.Runes.Enabled {
if opts.Runes {
var db runesdatagateway.RunesDataGateway
switch strings.ToLower(opts.Runes.Database) {
switch strings.ToLower(conf.Modules.Runes.Database) {
case "postgres", "pg":
pg, err := postgres.NewPool(ctx, conf.Modules["runes"].Postgres)
pg, err := postgres.NewPool(ctx, conf.Modules.Runes.Postgres)
if err != nil {
logger.PanicContext(ctx, "Failed to create Postgres connection pool", slogx.Error(err))
}
defer pg.Close()
db = runespostgres.NewRepository(pg)
default:
logger.PanicContext(ctx, "Unsupported database", slogx.String("database", opts.Runes.Database))
logger.PanicContext(ctx, "Unsupported database", slogx.String("database", conf.Modules.Runes.Database))
}
// TODO: add option to change bitcoinNodeDatasource implementation
bitcoinNodeDatasource := datasources.NewBitcoinNode(client)
runesProcessor := runes.NewProcessor(db, bitcoinNodeDatasource, bitcoinNodeDatasource, conf.Network)
runesIndexer := indexers.NewBitcoinIndexer(runesProcessor, bitcoinNodeDatasource)
var bitcoinDatasource indexers.BitcoinDatasource
switch strings.ToLower(conf.Modules.Runes.Datasource) {
case "bitcoin-node":
bitcoinDatasource = bitcoinNodeDatasource
case "database":
return errors.Wrap(errs.Unsupported, "%database datasource is not supported yet")
default:
return errors.Wrapf(errs.Unsupported, "%q datasource is not supported", conf.Modules.Runes.Datasource)
}
runesProcessor := runes.NewProcessor(db, bitcoinNodeDatasource, bitcoinDatasource, conf.Network)
runesIndexer := indexers.NewBitcoinIndexer(runesProcessor, bitcoinDatasource)
if err := runesProcessor.Init(ctx); err != nil {
logger.PanicContext(ctx, "Failed to initialize Runes Processor", slogx.Error(err))

View File

@@ -20,3 +20,13 @@ modules:
password: "password"
db_name: "postgres"
# url: "postgres://postgres:password@localhost:5432/postgres?sslmode=prefer" # [Optional] This will override other database connection configurations
runes:
database: "postgres" # Database to store Runes data. current supported databases: "postgres"
datasource: "bitcoin-node"
postgres:
host: "localhost"
port: 5432
user: "postgres"
password: "password"
db_name: "postgres"
# url: "postgres://postgres:password@localhost:5432/postgres?sslmode=prefer" # [Optional] This will override other database connection configurations