Skip to content

Commit

Permalink
fix: App Config (app.toml) Parsing Fix (#624)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidterpay authored Jul 24, 2024
1 parent 1d7f928 commit 9f85f7f
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 12 deletions.
58 changes: 49 additions & 9 deletions oracle/config/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

var (
DefaultOracleEnabled = true
DefaultOracleEnabled = false
DefaultOracleAddress = "localhost:8080"
DefaultClientTimeout = 3 * time.Second
DefaultMetricsEnabled = false
Expand Down Expand Up @@ -152,17 +152,33 @@ func ReadConfigFromAppOpts(opts servertypes.AppOptions) (AppConfig, error) {
}
}

if !cfg.Enabled {
return cfg, nil
}

// get the oracle address
if v := opts.Get(flagOracleAddress); v != nil {
if cfg.OracleAddress, err = cast.ToStringE(v); err != nil {
return cfg, err
address, err := cast.ToStringE(v)
if err != nil {
return cfg, fmt.Errorf("oracle address must be a non-empty string")
}

// only update the address if it is non-empty
if len(address) > 0 {
cfg.OracleAddress = address
}
}

// get the client timeout
if v := opts.Get(flagClientTimeout); v != nil {
if cfg.ClientTimeout, err = cast.ToDurationE(v); err != nil {
return cfg, err
clientTimeout, err := cast.ToDurationE(v)
if err != nil {
return cfg, fmt.Errorf("client timeout must be a positive duration")
}

// only update the client timeout if it is positive
if clientTimeout > 0 {
cfg.ClientTimeout = clientTimeout
}
}

Expand All @@ -175,15 +191,27 @@ func ReadConfigFromAppOpts(opts servertypes.AppOptions) (AppConfig, error) {

// get the price ttl
if v := opts.Get(flagPriceTTL); v != nil {
if cfg.PriceTTL, err = cast.ToDurationE(v); err != nil {
return cfg, err
priceTTL, err := cast.ToDurationE(v)
if err != nil {
return cfg, fmt.Errorf("price ttl must be a positive duration")
}

// only update the price ttl if it is positive
if priceTTL > 0 {
cfg.PriceTTL = priceTTL
}
}

// get the interval
if v := opts.Get(flagInterval); v != nil {
if cfg.Interval, err = cast.ToDurationE(v); err != nil {
return cfg, err
interval, err := cast.ToDurationE(v)
if err != nil {
return cfg, fmt.Errorf("interval must be a positive duration")
}

// only update the interval if it is positive
if interval > 0 {
cfg.Interval = interval
}
}

Expand All @@ -193,3 +221,15 @@ func ReadConfigFromAppOpts(opts servertypes.AppOptions) (AppConfig, error) {

return cfg, err
}

// String implements the stringer interface for the AppConfig.
func (c AppConfig) String() string {
return fmt.Sprintf(`Oracle Config:
Enabled: %v
Oracle Address: %s
Client Timeout: %s
Metrics Enabled: %v
Price TTL: %s
Interval: %s`,
c.Enabled, c.OracleAddress, c.ClientTimeout, c.MetricsEnabled, c.PriceTTL, c.Interval)
}
6 changes: 3 additions & 3 deletions scripts/genesis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ for i in $(env | grep -v "_BALANCE" | grep -o "GENESIS_ACCOUNT_[0-9]*" | sort -n
./build/slinkyd genesis add-genesis-account $ACCOUNT $BALANCE --home "$HOMEDIR" --keyring-backend test
done

# add the MARKET_MAP_AUTHORITY environment variable address to the genesis file (if there is one)
MARKET_MAP_AUTHORITY=$(printenv MARKET_MAP_AUTHORITY)
if [ -n "$MARKET_MAP_AUTHORITY" ]; then
# Check if MARKET_MAP_AUTHORITY environment variable exists and is not empty
if [ -n "${MARKET_MAP_AUTHORITY+x}" ] && [ -n "$MARKET_MAP_AUTHORITY" ]; then
MARKET_MAP_AUTHORITY=$(printenv MARKET_MAP_AUTHORITY)
jq --arg authority "$MARKET_MAP_AUTHORITY" \
'.app_state["marketmap"]["params"]["market_authorities"] += [$authority]' \
"$GENESIS" > "$GENESIS_TMP" && mv "$GENESIS_TMP" "$GENESIS"
Expand Down

0 comments on commit 9f85f7f

Please sign in to comment.