config and env updates
This commit is contained in:
parent
5b86cadeff
commit
0041f5823b
@ -19,6 +19,8 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/database/sql/postgres"
|
||||
@ -41,6 +43,7 @@ type Config struct {
|
||||
Eth *EthConfig
|
||||
DB *DBConfig
|
||||
File *FileConfig
|
||||
Service *ServiceConfig
|
||||
}
|
||||
|
||||
// EthConfig is config parameters for the chain.
|
||||
@ -60,11 +63,17 @@ type FileConfig struct {
|
||||
OutputDir string
|
||||
}
|
||||
|
||||
type ServiceConfig struct {
|
||||
AllowedPaths [][]byte
|
||||
AllowedAccounts []common.Address
|
||||
}
|
||||
|
||||
func NewConfig(mode SnapshotMode) (*Config, error) {
|
||||
ret := &Config{
|
||||
&EthConfig{},
|
||||
&DBConfig{},
|
||||
&FileConfig{},
|
||||
&ServiceConfig{},
|
||||
}
|
||||
return ret, ret.Init(mode)
|
||||
}
|
||||
@ -110,7 +119,7 @@ func (c *Config) Init(mode SnapshotMode) error {
|
||||
default:
|
||||
return fmt.Errorf("no output mode specified")
|
||||
}
|
||||
return nil
|
||||
return c.Service.Init()
|
||||
}
|
||||
|
||||
func (c *DBConfig) Init() {
|
||||
@ -148,3 +157,18 @@ func (c *FileConfig) Init() error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *ServiceConfig) Init() error {
|
||||
viper.BindEnv(SNAPSHOT_ACCOUNTS_TOML, SNAPSHOT_ACCOUNTS)
|
||||
allowedAccounts := viper.GetStringSlice(SNAPSHOT_ACCOUNTS)
|
||||
accountsLen := len(allowedAccounts)
|
||||
if accountsLen != 0 {
|
||||
c.AllowedAccounts = make([]common.Address, accountsLen)
|
||||
for i, allowedAccount := range allowedAccounts {
|
||||
c.AllowedAccounts[i] = common.HexToAddress(allowedAccount)
|
||||
}
|
||||
} else {
|
||||
logrus.Infof("no snapshot addresses specified, will perform snapshot of entire trie(s)")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ const (
|
||||
SNAPSHOT_MODE = "SNAPSHOT_MODE"
|
||||
SNAPSHOT_START_HEIGHT = "SNAPSHOT_START_HEIGHT"
|
||||
SNAPSHOT_END_HEIGHT = "SNAPSHOT_END_HEIGHT"
|
||||
SNAPSHOT_ACCOUNTS = "SNAPSHOT_ACCOUNTS"
|
||||
|
||||
LOGRUS_LEVEL = "LOGRUS_LEVEL"
|
||||
LOGRUS_FILE = "LOGRUS_FILE"
|
||||
@ -62,6 +63,7 @@ const (
|
||||
SNAPSHOT_MODE_TOML = "snapshot.mode"
|
||||
SNAPSHOT_START_HEIGHT_TOML = "snapshot.startHeight"
|
||||
SNAPSHOT_END_HEIGHT_TOML = "snapshot.endHeight"
|
||||
SNAPSHOT_ACCOUNTS_TOML = "snapshot.accounts"
|
||||
|
||||
LOGRUS_LEVEL_TOML = "log.level"
|
||||
LOGRUS_FILE_TOML = "log.file"
|
||||
@ -101,6 +103,7 @@ const (
|
||||
SNAPSHOT_MODE_CLI = "snapshot-mode"
|
||||
SNAPSHOT_START_HEIGHT_CLI = "start-height"
|
||||
SNAPSHOT_END_HEIGHT_CLI = "end-height"
|
||||
SNAPSHOT_ACCOUNTS_CLI = "snapshot-accounts"
|
||||
|
||||
LOGRUS_LEVEL_CLI = "log-level"
|
||||
LOGRUS_FILE_CLI = "log-file"
|
||||
|
Loading…
Reference in New Issue
Block a user