Some checks are pending
docker-build-cometbft / vars (push) Waiting to run
docker-build-cometbft / build-images (amd64, ubuntu-24.04) (push) Blocked by required conditions
docker-build-cometbft / build-images (arm64, ubuntu-24.04-arm) (push) Blocked by required conditions
docker-build-cometbft / merge-images (push) Blocked by required conditions
docker-build-e2e-node / vars (push) Waiting to run
docker-build-e2e-node / build-images (amd64, ubuntu-24.04) (push) Blocked by required conditions
docker-build-e2e-node / build-images (arm64, ubuntu-24.04-arm) (push) Blocked by required conditions
docker-build-e2e-node / merge-images (push) Blocked by required conditions
57 lines
2.1 KiB
Go
57 lines
2.1 KiB
Go
package block
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
|
|
dbm "git.cw.tr/mukan-network/mukan-consensus-db"
|
|
|
|
"git.cw.tr/mukan-network/mukan-consensus/config"
|
|
"git.cw.tr/mukan-network/mukan-consensus/state/indexer"
|
|
blockidxkv "git.cw.tr/mukan-network/mukan-consensus/state/indexer/block/kv"
|
|
blockidxnull "git.cw.tr/mukan-network/mukan-consensus/state/indexer/block/null"
|
|
"git.cw.tr/mukan-network/mukan-consensus/state/indexer/sink/psql"
|
|
"git.cw.tr/mukan-network/mukan-consensus/state/txindex"
|
|
"git.cw.tr/mukan-network/mukan-consensus/state/txindex/kv"
|
|
"git.cw.tr/mukan-network/mukan-consensus/state/txindex/null"
|
|
)
|
|
|
|
// IndexerFromConfig constructs a slice of indexer.EventSink using the provided
|
|
// configuration.
|
|
func IndexerFromConfig(cfg *config.Config, dbProvider config.DBProvider, chainID string) (
|
|
txIdx txindex.TxIndexer, blockIdx indexer.BlockIndexer, err error,
|
|
) {
|
|
txidx, blkidx, _, err := IndexerFromConfigWithDisabledIndexers(cfg, dbProvider, chainID)
|
|
return txidx, blkidx, err
|
|
}
|
|
|
|
// IndexerFromConfigWithDisabledIndexers constructs a slice of indexer.EventSink using the provided
|
|
// configuration. If all indexers are disabled in the configuration, it returns null indexers.
|
|
// Otherwise, it creates the appropriate indexers based on the configuration.
|
|
func IndexerFromConfigWithDisabledIndexers(cfg *config.Config, dbProvider config.DBProvider, chainID string) (
|
|
txIdx txindex.TxIndexer, blockIdx indexer.BlockIndexer, allIndexersDisabled bool, err error,
|
|
) {
|
|
switch cfg.TxIndex.Indexer {
|
|
case "kv":
|
|
store, err := dbProvider(&config.DBContext{ID: "tx_index", Config: cfg})
|
|
if err != nil {
|
|
return nil, nil, false, err
|
|
}
|
|
|
|
return kv.NewTxIndex(store), blockidxkv.New(dbm.NewPrefixDB(store, []byte("block_events"))), false, nil
|
|
|
|
case "psql":
|
|
conn := cfg.TxIndex.PsqlConn
|
|
if conn == "" {
|
|
return nil, nil, false, errors.New("the psql connection settings cannot be empty")
|
|
}
|
|
es, err := psql.NewEventSink(cfg.TxIndex.PsqlConn, chainID)
|
|
if err != nil {
|
|
return nil, nil, false, fmt.Errorf("creating psql indexer: %w", err)
|
|
}
|
|
return es.TxIndexer(), es.BlockIndexer(), false, nil
|
|
|
|
default:
|
|
return &null.TxIndex{}, &blockidxnull.BlockerIndexer{}, true, nil
|
|
}
|
|
}
|