Skip to content

Commit

Permalink
fix log and example
Browse files Browse the repository at this point in the history
  • Loading branch information
nkitlabs committed Jun 6, 2024
1 parent 0c13e34 commit ab69a60
Show file tree
Hide file tree
Showing 8 changed files with 385 additions and 340 deletions.
55 changes: 55 additions & 0 deletions examples/requester/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package main

import (
"os"
"time"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/spf13/viper"
)

type ChainConfig struct {
ChainID string `yaml:"chain_id" mapstructure:"chain_id"`
RPC string `yaml:"rpc" mapstructure:"rpc"`
Fee string `yaml:"fee" mapstructure:"fee"`
Timeout time.Duration `yaml:"timeout" mapstructure:"timeout"`
}

type RequestConfig struct {
OracleScriptID int `yaml:"oracle_script_id" mapstructure:"oracle_script_id"`
Calldata string `yaml:"calldata" mapstructure:"calldata"`
Mnemonic string `yaml:"mnemonic" mapstructure:"mnemonic"`
}

type Config struct {
Chain ChainConfig `yaml:"chain" mapstructure:"chain"`
Request RequestConfig `yaml:"request" mapstructure:"request"`
LogLevel string `yaml:"log_level" mapstructure:"log_level"`
SDK *sdk.Config
}

func GetConfig(name string) (Config, error) {
viper.SetConfigType("yaml")
viper.SetConfigName(name)
viper.AddConfigPath("./requester/configs")

if err := viper.ReadInConfig(); err != nil {
return Config{}, err
}

var config Config
if err := viper.Unmarshal(&config); err != nil {
return Config{}, err
}

config.SDK = sdk.GetConfig()

return config, nil
}

func GetEnv(key, fallback string) string {
if value, ok := os.LookupEnv(key); ok {
return value
}
return fallback
}
Loading

0 comments on commit ab69a60

Please sign in to comment.