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

avoid parsing if EXCHANGE_SYMBOLS_MAP is not define. #40

Merged
merged 2 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
26 changes: 14 additions & 12 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,20 @@ func Get() (*Config, error) {
conf.WebsocketEndpoint = os.Getenv("WEBSOCKET_ENDPOINT")
conf.FeederMnemonic = os.Getenv("FEEDER_MNEMONIC")
conf.EnableTLS = os.Getenv("ENABLE_TLS") == "true"
overrideExchangeSymbolsMapJson := os.Getenv("EXCHANGE_SYMBOLS_MAP")
overrideExchangeSymbolsMap := map[string]map[string]string{}
err := json.Unmarshal([]byte(overrideExchangeSymbolsMapJson), &overrideExchangeSymbolsMap)
if err != nil {
return nil, fmt.Errorf("failed to parse EXCHANGE_SYMBOLS_MAP: invalid json")
}

conf.ExchangesToPairToSymbolMap = defaultExchangeSymbolsMap
for exchange, symbolMap := range overrideExchangeSymbolsMap {
conf.ExchangesToPairToSymbolMap[exchange] = map[asset.Pair]types.Symbol{}
for nibiAssetPair, tickerSymbol := range symbolMap {
conf.ExchangesToPairToSymbolMap[exchange][asset.MustNewPair(nibiAssetPair)] = types.Symbol(tickerSymbol)

overrideExchangeSymbolsMapJson := os.Getenv("EXCHANGE_SYMBOLS_MAP")
if overrideExchangeSymbolsMapJson != "" {
overrideExchangeSymbolsMap := map[string]map[string]string{}
err := json.Unmarshal([]byte(overrideExchangeSymbolsMapJson), &overrideExchangeSymbolsMap)
if err != nil {
return nil, fmt.Errorf("failed to parse EXCHANGE_SYMBOLS_MAP: invalid json")
}
for exchange, symbolMap := range overrideExchangeSymbolsMap {
conf.ExchangesToPairToSymbolMap[exchange] = map[asset.Pair]types.Symbol{}
for nibiAssetPair, tickerSymbol := range symbolMap {
conf.ExchangesToPairToSymbolMap[exchange][asset.MustNewPair(nibiAssetPair)] = types.Symbol(tickerSymbol)
}
}
}

Expand All @@ -104,7 +106,7 @@ func Get() (*Config, error) {
datasourceConfigMap := map[string]json.RawMessage{}

if datasourceConfigMapJson != "" {
err = json.Unmarshal([]byte(datasourceConfigMapJson), &datasourceConfigMap)
err := json.Unmarshal([]byte(datasourceConfigMapJson), &datasourceConfigMap)
if err != nil {
return nil, fmt.Errorf("failed to parse DATASOURCE_CONFIG_MAP: invalid json")
}
Expand Down
14 changes: 14 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package config

import (
"fmt"
"os"
"testing"

Expand All @@ -23,3 +24,16 @@ func TestConfig_Get(t *testing.T) {
_, err := Get()
require.NoError(t, err)
}

func TestConfig_Without_EXCHANGE_SYMBOLS_MAP(t *testing.T) {

os.Setenv("CHAIN_ID", "nibiru-localnet-0")
os.Setenv("GRPC_ENDPOINT", "localhost:9090")
os.Setenv("WEBSOCKET_ENDPOINT", "ws://localhost:26657/websocket")
os.Setenv("FEEDER_MNEMONIC", "earth wash broom grow recall fitness")
app.SetPrefixes(app.AccountAddressPrefix)
os.Setenv("VALIDATOR_ADDRESS", "nibivaloper1d7zygazerfwx4l362tnpcp0ramzm97xvv9ryxr")
cfg, err := Get()
fmt.Println(cfg)
require.NoError(t, err)
}