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

feat/Publicize more indexer funcs for utils #99

Merged
merged 1 commit into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions cmd/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func GetBuiltinIndexer() *indexerPackage.Indexer {

// setupIndex loads the configuration from file and command line flags, validates the configuration, and sets up the logger and database connection.
func setupIndex(cmd *cobra.Command, args []string) error {
bindFlags(cmd, viperConf)
BindFlags(cmd, viperConf)

err := indexer.Config.Validate()
if err != nil {
Expand All @@ -70,7 +70,7 @@ func setupIndex(cmd *cobra.Command, args []string) error {

// If DB has not been preset, connect to the database and migrate using the default configuration settings
if indexer.DB == nil {
db, err := connectToDBAndMigrate(indexer.Config.Database)
db, err := ConnectToDBAndMigrate(indexer.Config.Database)
if err != nil {
config.Log.Fatal("Could not establish connection to the database", err)
}
Expand Down
8 changes: 6 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,12 @@ func getViperConfig() {
viperConf = v
}

func GetViperConfig() *viper.Viper {
return viperConf
}

// Set config vars from cpnfig file not already specified on command line.
func bindFlags(cmd *cobra.Command, v *viper.Viper) {
func BindFlags(cmd *cobra.Command, v *viper.Viper) {
cmd.Flags().VisitAll(func(f *pflag.Flag) {
configName := f.Name

Expand All @@ -109,7 +113,7 @@ func setupLogger(logLevel string, logPath string, prettyLogging bool) {
config.DoConfigureLogger(logPath, logLevel, prettyLogging)
}

func connectToDBAndMigrate(dbConfig config.Database) (*gorm.DB, error) {
func ConnectToDBAndMigrate(dbConfig config.Database) (*gorm.DB, error) {
database, err := db.PostgresDbConnect(dbConfig.Host, dbConfig.Port, dbConfig.Database, dbConfig.User, dbConfig.Password, strings.ToLower(dbConfig.LogLevel))
if err != nil {
config.Log.Fatal("Could not establish connection to the database", err)
Expand Down
8 changes: 8 additions & 0 deletions db/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,11 @@ func FindOrCreateAddressByAddress(db *gorm.DB, address string) (models.Address,
err := db.Where(&addr).FirstOrCreate(&addr).Error
return addr, err
}

func GetChains(db *gorm.DB) ([]models.Chain, error) {
var chains []models.Chain
if err := db.Find(&chains).Error; err != nil {
return nil, err
}
return chains, nil
}
Loading