From 8f4a44b359ff51244ed66ab2e37dc4764e40d320 Mon Sep 17 00:00:00 2001 From: Stefan Liu Date: Mon, 9 Aug 2021 11:51:34 +0800 Subject: [PATCH] Add build/config env check --- basedef/define_devnet.go | 4 +++- basedef/define_mainnet.go | 4 +++- basedef/define_testnet.go | 4 +++- basedef/utils.go | 8 ++++++++ cmd/main.go | 5 ++++- conf/config.go | 9 +++++---- main.go | 2 ++ 7 files changed, 28 insertions(+), 8 deletions(-) diff --git a/basedef/define_devnet.go b/basedef/define_devnet.go index b77f5609..8ce11331 100644 --- a/basedef/define_devnet.go +++ b/basedef/define_devnet.go @@ -19,7 +19,7 @@ package basedef -var ( +const ( POLY_CROSSCHAIN_ID = uint64(0) ETHEREUM_CROSSCHAIN_ID = uint64(2) ONT_CROSSCHAIN_ID = uint64(3) @@ -30,4 +30,6 @@ var ( NEO3_CROSSCHAIN_ID = uint64(88) OK_CROSSCHAIN_ID = uint64(90) MATIC_CROSSCHAIN_ID = uint64(13) + + ENV = "devnet" ) diff --git a/basedef/define_mainnet.go b/basedef/define_mainnet.go index 250e3ba4..b6e2dcfd 100644 --- a/basedef/define_mainnet.go +++ b/basedef/define_mainnet.go @@ -19,7 +19,7 @@ package basedef -var ( +const ( POLY_CROSSCHAIN_ID = uint64(0) ETHEREUM_CROSSCHAIN_ID = uint64(2) ONT_CROSSCHAIN_ID = uint64(3) @@ -30,4 +30,6 @@ var ( OK_CROSSCHAIN_ID = uint64(12) NEO3_CROSSCHAIN_ID = uint64(14) MATIC_CROSSCHAIN_ID = uint64(17) + + ENV = "mainnet" ) diff --git a/basedef/define_testnet.go b/basedef/define_testnet.go index 53d65fd4..44a6d254 100644 --- a/basedef/define_testnet.go +++ b/basedef/define_testnet.go @@ -19,7 +19,7 @@ package basedef -var ( +const ( POLY_CROSSCHAIN_ID = uint64(0) ETHEREUM_CROSSCHAIN_ID = uint64(2) ONT_CROSSCHAIN_ID = uint64(3) @@ -30,4 +30,6 @@ var ( NEO3_CROSSCHAIN_ID = uint64(88) OK_CROSSCHAIN_ID = uint64(200) MATIC_CROSSCHAIN_ID = uint64(202) + + ENV = "testnet" ) diff --git a/basedef/utils.go b/basedef/utils.go index 0f0c55a7..444ca7e7 100644 --- a/basedef/utils.go +++ b/basedef/utils.go @@ -110,3 +110,11 @@ func Int64FromFigure(figure int) int64 { } return x } + +func ConfirmEnv(env string) { + if ENV != env { + logs.Error("Config env(%s) does not match build env(%s)", env, ENV) + os.Exit(1) + } + logs.Info("Current env: %s", ENV) +} diff --git a/cmd/main.go b/cmd/main.go index 75dbfe57..14c3c92c 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -22,6 +22,7 @@ import ( "fmt" "os" "os/signal" + "poly-bridge/basedef" "poly-bridge/chainfeelisten" "poly-bridge/coinpricelisten" "poly-bridge/common" @@ -110,6 +111,8 @@ func startServer(ctx *cli.Context) { conf, _ := json.Marshal(config) logs.Info("%s\n", string(conf)) } + + basedef.ConfirmEnv(config.Env) common.SetupChainsSDK(config) crosschainlisten.StartCrossChainListen(config.Server, config.Backup, config.ChainListenConfig, config.DBConfig) if config.Backup { @@ -117,7 +120,7 @@ func startServer(ctx *cli.Context) { } coinpricelisten.StartCoinPriceListen(config.Server, config.CoinPriceUpdateSlot, config.CoinPriceListenConfig, config.DBConfig) chainfeelisten.StartFeeListen(config.Server, config.FeeUpdateSlot, config.FeeListenConfig, config.DBConfig) - crosschaineffect.StartCrossChainEffect(config.Server, config.EventEffectConfig, config.DBConfig,config.IPPortConfig) + crosschaineffect.StartCrossChainEffect(config.Server, config.EventEffectConfig, config.DBConfig, config.IPPortConfig) crosschainstats.StartCrossChainStats(config.Server, config.StatsConfig, config.DBConfig) } diff --git a/conf/config.go b/conf/config.go index 11476daa..9e0e2a41 100644 --- a/conf/config.go +++ b/conf/config.go @@ -152,13 +152,14 @@ type EventEffectConfig struct { } type IPPortConfig struct { - WBTCIP string - USDTIP string - DingIP string + WBTCIP string + USDTIP string + DingIP string } type Config struct { Server string + Env string Backup bool ChainListenConfig []*ChainListenConfig CoinPriceUpdateSlot int64 @@ -168,7 +169,7 @@ type Config struct { EventEffectConfig *EventEffectConfig StatsConfig *StatsConfig DBConfig *DBConfig - IPPortConfig *IPPortConfig + IPPortConfig *IPPortConfig } func (cfg *Config) GetChainListenConfig(chainId uint64) *ChainListenConfig { diff --git a/main.go b/main.go index bf568fd6..0bd5d960 100644 --- a/main.go +++ b/main.go @@ -20,6 +20,7 @@ package main import ( "encoding/json" + "poly-bridge/basedef" "poly-bridge/common" "poly-bridge/conf" _ "poly-bridge/routers" @@ -36,6 +37,7 @@ func main() { logs.SetLogger(logs.AdapterFile, `{"filename":"logs/bridge_http.log"}`) configFile := beego.AppConfig.String("chain_config") config := conf.NewConfig(configFile) + basedef.ConfirmEnv(config.Env) common.SetupChainsSDK(config) mode := beego.AppConfig.String("runmode")