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

fix: App Config (app.toml) Parsing Fix #624

Merged
merged 4 commits into from
Jul 24, 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
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 @@
)

var (
DefaultOracleEnabled = true
DefaultOracleEnabled = false
DefaultOracleAddress = "localhost:8080"
DefaultClientTimeout = 3 * time.Second
DefaultMetricsEnabled = false
Expand Down Expand Up @@ -152,17 +152,33 @@
}
}

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")

Check warning on line 163 in oracle/config/app.go

View check run for this annotation

Codecov / codecov/patch

oracle/config/app.go#L163

Added line #L163 was not covered by tests
technicallyty marked this conversation as resolved.
Show resolved Hide resolved
}

// 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 @@

// 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")
}
technicallyty marked this conversation as resolved.
Show resolved Hide resolved

// 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 @@

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)

Check warning on line 234 in oracle/config/app.go

View check run for this annotation

Codecov / codecov/patch

oracle/config/app.go#L226-L234

Added lines #L226 - L234 were not covered by tests
}
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
Loading