Skip to content

Commit

Permalink
Merge pull request #12 from Layr-Labs/sm-removePostgres
Browse files Browse the repository at this point in the history
Remove postgres completely
  • Loading branch information
seanmcgary authored Sep 7, 2024
2 parents 373bc35 + a3364e0 commit d8ace29
Show file tree
Hide file tree
Showing 40 changed files with 35 additions and 1,750 deletions.
39 changes: 0 additions & 39 deletions cmd/migrate/main.go

This file was deleted.

24 changes: 7 additions & 17 deletions cmd/sidecar/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import (
"github.com/Layr-Labs/sidecar/internal/clients/etherscan"
"github.com/Layr-Labs/sidecar/internal/config"
"github.com/Layr-Labs/sidecar/internal/contractManager"
"github.com/Layr-Labs/sidecar/internal/contractStore/pgContractStore"
"github.com/Layr-Labs/sidecar/internal/contractStore/sqliteContractStore"
"github.com/Layr-Labs/sidecar/internal/fetcher"
"github.com/Layr-Labs/sidecar/internal/indexer"
"github.com/Layr-Labs/sidecar/internal/logger"
"github.com/Layr-Labs/sidecar/internal/metrics"
"github.com/Layr-Labs/sidecar/internal/pipeline"
"github.com/Layr-Labs/sidecar/internal/postgres"
"github.com/Layr-Labs/sidecar/internal/postgres/migrations"
"github.com/Layr-Labs/sidecar/internal/sidecar"
"github.com/Layr-Labs/sidecar/internal/sqlite"
"github.com/Layr-Labs/sidecar/internal/sqlite/migrations"
"github.com/Layr-Labs/sidecar/internal/storage/postgresql"
"go.uber.org/zap"
"log"
Expand All @@ -37,31 +37,21 @@ func main() {
etherscanClient := etherscan.NewEtherscanClient(cfg, l)
client := ethereum.NewClient(cfg.EthereumRpcConfig.BaseUrl, l)

db, err := postgres.NewPostgres(&postgres.PostgresConfig{
Host: cfg.PostgresConfig.Host,
Port: cfg.PostgresConfig.Port,
Username: cfg.PostgresConfig.Username,
Password: cfg.PostgresConfig.Password,
DbName: cfg.PostgresConfig.DbName,
})
if err != nil {
l.Error("Failed to setup postgres connection", zap.Error(err))
panic(err)
}
db := sqlite.NewSqlite(cfg.SqliteConfig.GetSqlitePath())

grm, err := postgres.NewGormFromPostgresConnection(db.Db)
grm, err := sqlite.NewGormSqliteFromSqlite(db)
if err != nil {
l.Error("Failed to create gorm instance", zap.Error(err))
panic(err)
}

migrator := migrations.NewMigrator(db.Db, grm, l)
migrator := migrations.NewSqliteMigrator(grm, l)
migrator.MigrateAll()
if err = migrator.MigrateAll(); err != nil {
log.Fatalf("Failed to migrate: %v", err)
}

contractStore, err := pgContractStore.NewPgContractStore(grm, l)
contractStore := sqliteContractStore.NewSqliteContractStore(grm, l)

cm := contractManager.NewContractManager(contractStore, etherscanClient, client, sdc, l)

Expand Down
18 changes: 18 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ type Config struct {
QuickNodeEthereumRpcConfig EthereumRpcConfig
PostgresConfig PostgresConfig
EtherscanConfig EtherscanConfig
SqliteConfig SqliteConfig
}

type EthereumRpcConfig struct {
Expand All @@ -137,6 +138,18 @@ type EtherscanConfig struct {
ApiKeys []string
}

type SqliteConfig struct {
InMemory bool
DbFilePath string
}

func (s *SqliteConfig) GetSqlitePath() string {
if s.InMemory {
return "file::memory:?cache=shared"
}
return s.DbFilePath
}

func NewConfig() *Config {
return &Config{
Network: ParseNetwork(getPrefixedEnvVar("NETWORK")),
Expand Down Expand Up @@ -165,6 +178,11 @@ func NewConfig() *Config {
EtherscanConfig: EtherscanConfig{
ApiKeys: parseListEnvVar(getPrefixedEnvVar("ETHERSCAN_API_KEYS")),
},

SqliteConfig: SqliteConfig{
InMemory: parseBooleanEnvVar(getPrefixedEnvVar("SQLITE_IN_MEMORY")),
DbFilePath: getPrefixedEnvVar("SQLITE_DB_FILE_PATH"),
},
}
}

Expand Down
241 changes: 0 additions & 241 deletions internal/contractStore/pgContractStore/pgContractStore.go

This file was deleted.

Loading

0 comments on commit d8ace29

Please sign in to comment.