From 7a116d441f60d7f4c894de6e7d4fb23d193515ac Mon Sep 17 00:00:00 2001 From: David Terpay Date: Wed, 24 Jul 2024 14:36:12 -0400 Subject: [PATCH] init --- oracle/config/app.go | 58 +++++++++++++++++++++++++++++++++++++------- scripts/genesis.sh | 6 ++--- 2 files changed, 52 insertions(+), 12 deletions(-) diff --git a/oracle/config/app.go b/oracle/config/app.go index 6bb0b0041..25fcede17 100644 --- a/oracle/config/app.go +++ b/oracle/config/app.go @@ -9,7 +9,7 @@ import ( ) var ( - DefaultOracleEnabled = true + DefaultOracleEnabled = false DefaultOracleAddress = "localhost:8080" DefaultClientTimeout = 3 * time.Second DefaultMetricsEnabled = false @@ -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 } } @@ -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 } } @@ -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) +} diff --git a/scripts/genesis.sh b/scripts/genesis.sh index df4daf0e1..a756444e7 100644 --- a/scripts/genesis.sh +++ b/scripts/genesis.sh @@ -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"