Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use db from outside #49

Merged
merged 1 commit into from
Jul 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading