-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: refactor consumers config (#55)
* feat: refactor consumers config * chore: refactor balances fetcher * chore: refactor node_info fetcher * chore: refactor node_signing_info fetcher * chore: refactor slashing_params fetcher * chore: validate fix * chore: allow disabling queries
- Loading branch information
1 parent
ec959b4
commit e384ec1
Showing
29 changed files
with
802 additions
and
421 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package config | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/rs/zerolog" | ||
) | ||
|
||
type Chain struct { | ||
Name string `toml:"name"` | ||
LCDEndpoint string `toml:"lcd-endpoint"` | ||
BaseDenom string `toml:"base-denom"` | ||
Denoms DenomInfos `toml:"denoms"` | ||
BechWalletPrefix string `toml:"bech-wallet-prefix"` | ||
Validators []Validator `toml:"validators"` | ||
Queries Queries `toml:"queries"` | ||
|
||
ConsumerChains []*ConsumerChain `toml:"consumers"` | ||
} | ||
|
||
func (c *Chain) GetQueries() Queries { | ||
return c.Queries | ||
} | ||
|
||
func (c *Chain) GetHost() string { | ||
return c.LCDEndpoint | ||
} | ||
|
||
func (c *Chain) GetName() string { | ||
return c.Name | ||
} | ||
|
||
func (c *Chain) Validate() error { | ||
if c.Name == "" { | ||
return errors.New("empty chain name") | ||
} | ||
|
||
if c.LCDEndpoint == "" { | ||
return errors.New("no LCD endpoint provided") | ||
} | ||
|
||
if len(c.Validators) == 0 { | ||
return errors.New("no validators provided") | ||
} | ||
|
||
for index, validator := range c.Validators { | ||
if err := validator.Validate(); err != nil { | ||
return fmt.Errorf("error in validator #%d: %s", index, err) | ||
} | ||
} | ||
|
||
for index, denomInfo := range c.Denoms { | ||
if err := denomInfo.Validate(); err != nil { | ||
return fmt.Errorf("error in denom #%d: %s", index, err) | ||
} | ||
} | ||
|
||
for index, chain := range c.ConsumerChains { | ||
if err := chain.Validate(); err != nil { | ||
return fmt.Errorf("error in consumer chain #%d: %s", index, err) | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (c *Chain) DisplayWarnings(logger *zerolog.Logger) { | ||
if c.BaseDenom == "" { | ||
logger.Warn(). | ||
Str("chain", c.Name). | ||
Msg("Base denom is not set") | ||
} | ||
|
||
for _, denom := range c.Denoms { | ||
denom.DisplayWarnings(c, logger) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package config | ||
|
||
type ChainInfo interface { | ||
GetQueries() Queries | ||
GetHost() string | ||
GetName() string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package config | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
) | ||
|
||
type ConsumerChain struct { | ||
Name string `toml:"name"` | ||
LCDEndpoint string `toml:"lcd-endpoint"` | ||
BaseDenom string `toml:"base-denom"` | ||
Denoms DenomInfos `toml:"denoms"` | ||
ChainID string `toml:"chain-id"` | ||
BechWalletPrefix string `toml:"bech-wallet-prefix"` | ||
BechValidatorPrefix string `toml:"bech-validator-prefix"` | ||
BechConsensusPrefix string `toml:"bech-consensus-prefix"` | ||
Queries Queries `toml:"queries"` | ||
} | ||
|
||
func (c *ConsumerChain) GetQueries() Queries { | ||
return c.Queries | ||
} | ||
|
||
func (c *ConsumerChain) GetHost() string { | ||
return c.LCDEndpoint | ||
} | ||
|
||
func (c *ConsumerChain) GetName() string { | ||
return c.Name | ||
} | ||
|
||
func (c *ConsumerChain) Validate() error { | ||
if c.Name == "" { | ||
return errors.New("empty chain name") | ||
} | ||
|
||
if c.LCDEndpoint == "" { | ||
return errors.New("no LCD endpoint provided") | ||
} | ||
|
||
if c.ChainID == "" { | ||
return errors.New("no chain-id provided") | ||
} | ||
|
||
for index, denomInfo := range c.Denoms { | ||
if err := denomInfo.Validate(); err != nil { | ||
return fmt.Errorf("error in denom #%d: %s", index, err) | ||
} | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package config | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/rs/zerolog" | ||
) | ||
|
||
type DenomInfo struct { | ||
Denom string `toml:"denom"` | ||
DenomCoefficient int64 `default:"1000000" toml:"denom-coefficient"` | ||
DisplayDenom string `toml:"display-denom"` | ||
CoingeckoCurrency string `toml:"coingecko-currency"` | ||
DexScreenerChainID string `toml:"dex-screener-chain-id"` | ||
DexScreenerPair string `toml:"dex-screener-pair"` | ||
} | ||
|
||
func (d *DenomInfo) Validate() error { | ||
if d.Denom == "" { | ||
return errors.New("empty denom name") | ||
} | ||
|
||
if d.DisplayDenom == "" { | ||
return errors.New("empty display denom name") | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (d *DenomInfo) DisplayWarnings(chain *Chain, logger *zerolog.Logger) { | ||
if d.CoingeckoCurrency == "" && (d.DexScreenerPair == "" || d.DexScreenerChainID == "") { | ||
logger.Warn(). | ||
Str("chain", chain.Name). | ||
Str("denom", d.Denom). | ||
Msg("Currency code not set, not fetching exchange rate.") | ||
} | ||
} | ||
|
||
type DenomInfos []*DenomInfo | ||
|
||
func (d DenomInfos) Find(denom string) *DenomInfo { | ||
for _, info := range d { | ||
if denom == info.Denom { | ||
return info | ||
} | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.