ipld-eth-server/pkg/transformers/shared/constants/external.go
Konstantin Zolotarev 65cb6e9092 VDB-205 Fix external configuration values (#121)
* Updated loading config from /Users/konstantinzolotarev/.vulcanizedb for addreses

* Updated contract addresses loading from env variables.

* Implement getter chain for addresses, configs and transformers

Solves the issue with declaring stuff as vars when the environment file hasn't been loaded yet. Instead, this data is fetched dynamically when the root commands are called.

* Update test data to use constant Kovan addresses

* Decouple integration tests from config file IO

* Add ABI to environment file, convert getter chains for related values

* Decouple tests suites from ABI config file IO

* Add startingBlock to environment and implement getter chain

* Exit when called without config file

* Add missing deployment blocks to staging.toml

* Remove comment
2019-01-23 19:44:09 +01:00

79 lines
3.8 KiB
Go

package constants
import (
"fmt"
"github.com/spf13/viper"
)
var initialized = false
func initConfig() {
if initialized {
return
}
if err := viper.ReadInConfig(); err == nil {
fmt.Printf("Using config file: %s\n\n", viper.ConfigFileUsed())
} else {
panic(fmt.Sprintf("Could not find environment file: %v", err))
}
initialized = true
}
func getEnvironmentString(key string) string {
initConfig()
value := viper.GetString(key)
if value == "" {
panic(fmt.Sprintf("No environment configuration variable set for key: \"%v\"", key))
}
return value
}
func getEnvironmentInt64(key string) int64 {
initConfig()
value := viper.GetInt64(key)
if value == -1 {
panic(fmt.Sprintf("No environment configuration variable set for key: \"%v\"", key))
}
return value
}
// Getters for contract addresses from environment files
func CatContractAddress() string { return getEnvironmentString("contract.address.cat") }
func DripContractAddress() string { return getEnvironmentString("contract.address.drip") }
func FlapperContractAddress() string { return getEnvironmentString("contract.address.mcd_flap") }
func FlipperContractAddress() string { return getEnvironmentString("contract.address.eth_flip") }
func FlopperContractAddress() string { return getEnvironmentString("contract.address.mcd_flop") }
func PepContractAddress() string { return getEnvironmentString("contract.address.pep") }
func PipContractAddress() string { return getEnvironmentString("contract.address.pip") }
func PitContractAddress() string { return getEnvironmentString("contract.address.pit") }
func RepContractAddress() string { return getEnvironmentString("contract.address.rep") }
func VatContractAddress() string { return getEnvironmentString("contract.address.vat") }
func VowContractAddress() string { return getEnvironmentString("contract.address.vow") }
func CatABI() string { return getEnvironmentString("contract.abi.cat") }
func DripABI() string { return getEnvironmentString("contract.abi.drip") }
func FlapperABI() string { return getEnvironmentString("contract.abi.mcd_flap") }
func FlipperABI() string { return getEnvironmentString("contract.abi.eth_flip") }
func FlopperABI() string { return getEnvironmentString("contract.abi.mcd_flop") }
func MedianizerABI() string { return getEnvironmentString("contract.abi.medianizer") }
func PitABI() string { return getEnvironmentString("contract.abi.pit") }
func VatABI() string { return getEnvironmentString("contract.abi.vat") }
func VowABI() string { return getEnvironmentString("contract.abi.vow") }
func CatDeploymentBlock() int64 { return getEnvironmentInt64("contract.deployment-block.cat") }
func DripDeploymentBlock() int64 { return getEnvironmentInt64("contract.deployment-block.drip") }
func FlapperDeploymentBlock() int64 { return getEnvironmentInt64("contract.deployment-block.mcd_flap") }
func FlipperDeploymentBlock() int64 { return getEnvironmentInt64("contract.deployment-block.eth_flip") }
func FlopperDeploymentBlock() int64 { return getEnvironmentInt64("contract.deployment-block.mcd_flop") }
func PepDeploymentBlock() int64 { return getEnvironmentInt64("contract.deployment-block.pep") }
func PipDeploymentBlock() int64 { return getEnvironmentInt64("contract.deployment-block.pip") }
func PitDeploymentBlock() int64 { return getEnvironmentInt64("contract.deployment-block.pit") }
func RepDeploymentBlock() int64 { return getEnvironmentInt64("contract.deployment-block.rep") }
func VatDeploymentBlock() int64 { return getEnvironmentInt64("contract.deployment-block.vat") }
func VowDeploymentBlock() int64 { return getEnvironmentInt64("contract.deployment-block.vow") }
func MedianizerDeploymentBlock() int64 {
return getEnvironmentInt64("contract.deployment-block.medianizer")
}