Skip to content

Commit

Permalink
Add build/config env check
Browse files Browse the repository at this point in the history
  • Loading branch information
devfans committed Aug 9, 2021
1 parent 0e4da68 commit 8f4a44b
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 8 deletions.
4 changes: 3 additions & 1 deletion basedef/define_devnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

package basedef

var (
const (
POLY_CROSSCHAIN_ID = uint64(0)
ETHEREUM_CROSSCHAIN_ID = uint64(2)
ONT_CROSSCHAIN_ID = uint64(3)
Expand All @@ -30,4 +30,6 @@ var (
NEO3_CROSSCHAIN_ID = uint64(88)
OK_CROSSCHAIN_ID = uint64(90)
MATIC_CROSSCHAIN_ID = uint64(13)

ENV = "devnet"
)
4 changes: 3 additions & 1 deletion basedef/define_mainnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

package basedef

var (
const (
POLY_CROSSCHAIN_ID = uint64(0)
ETHEREUM_CROSSCHAIN_ID = uint64(2)
ONT_CROSSCHAIN_ID = uint64(3)
Expand All @@ -30,4 +30,6 @@ var (
OK_CROSSCHAIN_ID = uint64(12)
NEO3_CROSSCHAIN_ID = uint64(14)
MATIC_CROSSCHAIN_ID = uint64(17)

ENV = "mainnet"
)
4 changes: 3 additions & 1 deletion basedef/define_testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

package basedef

var (
const (
POLY_CROSSCHAIN_ID = uint64(0)
ETHEREUM_CROSSCHAIN_ID = uint64(2)
ONT_CROSSCHAIN_ID = uint64(3)
Expand All @@ -30,4 +30,6 @@ var (
NEO3_CROSSCHAIN_ID = uint64(88)
OK_CROSSCHAIN_ID = uint64(200)
MATIC_CROSSCHAIN_ID = uint64(202)

ENV = "testnet"
)
8 changes: 8 additions & 0 deletions basedef/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
5 changes: 4 additions & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"fmt"
"os"
"os/signal"
"poly-bridge/basedef"
"poly-bridge/chainfeelisten"
"poly-bridge/coinpricelisten"
"poly-bridge/common"
Expand Down Expand Up @@ -110,14 +111,16 @@ 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 {
return
}
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)
}

Expand Down
9 changes: 5 additions & 4 deletions conf/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -168,7 +169,7 @@ type Config struct {
EventEffectConfig *EventEffectConfig
StatsConfig *StatsConfig
DBConfig *DBConfig
IPPortConfig *IPPortConfig
IPPortConfig *IPPortConfig
}

func (cfg *Config) GetChainListenConfig(chainId uint64) *ChainListenConfig {
Expand Down
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package main
import (
"encoding/json"

"poly-bridge/basedef"
"poly-bridge/common"
"poly-bridge/conf"
_ "poly-bridge/routers"
Expand All @@ -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")
Expand Down

0 comments on commit 8f4a44b

Please sign in to comment.