Skip to content

Commit

Permalink
Merge pull request #49 from initia-labs/feat/inject-db
Browse files Browse the repository at this point in the history
use db from outside
  • Loading branch information
Vritra4 authored Jul 16, 2024
2 parents 8808e02 + 940949a commit 151739d
Showing 1 changed file with 11 additions and 20 deletions.
31 changes: 11 additions & 20 deletions x/kvindexer/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package keeper
import (
"context"
"errors"
"path"

"cosmossdk.io/collections"
"cosmossdk.io/core/address"
Expand All @@ -20,16 +19,14 @@ import (
)

const StoreName = "indexer"
const DataDir = "data"

type Keeper struct {
cdc codec.Codec
store *store.CacheStore

vmType string

config *config.IndexerConfig
homeDir string
config *config.IndexerConfig

schemaBuilder *collections.SchemaBuilder
schema *collections.Schema
Expand Down Expand Up @@ -57,20 +54,20 @@ func (k Keeper) Close() error {
func NewKeeper(
cdc codec.Codec,
vmType string,
homeDir string,
db dbm.DB,
config *config.IndexerConfig,
ac, vc address.Codec,
) *Keeper {

k := &Keeper{
cdc: cdc,
vmType: vmType,
homeDir: homeDir,
config: config,
schema: nil,
ac: ac,
vc: vc,
sealed: false,
cdc: cdc,
vmType: vmType,
db: db,
config: config,
schema: nil,
ac: ac,
vc: vc,
sealed: false,
}

k.submodules = make(map[string]types.Submodule)
Expand All @@ -95,20 +92,14 @@ func (k *Keeper) Seal() error {
return errors.New("keeper is already sealed")
}

db, err := store.OpenDB(path.Join(k.homeDir, DataDir), StoreName, k.config.BackendConfig)
if err != nil {
panic(err)
}

schema, err := k.schemaBuilder.Build()
if err != nil {
return err
}

k.db = db
k.schema = &schema

k.store = store.NewCacheStore(dbadapter.Store{DB: db}, k.config.CacheCapacity)
k.store = store.NewCacheStore(dbadapter.Store{DB: k.db}, k.config.CacheCapacity)
k.sealed = true

return nil
Expand Down

0 comments on commit 151739d

Please sign in to comment.