From 2c83876f2f14f9f35f5576822d879b9ace56542c Mon Sep 17 00:00:00 2001 From: Rongjian Lan Date: Thu, 20 Jun 2019 21:01:10 -0700 Subject: [PATCH] Panic for invalid network type --- cmd/harmony/main.go | 2 ++ common/config/global_config.go | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/cmd/harmony/main.go b/cmd/harmony/main.go index e1be600b0..fcb11c201 100644 --- a/cmd/harmony/main.go +++ b/cmd/harmony/main.go @@ -146,6 +146,8 @@ func initSetup() { config.Network = config.Testnet case "devnet": config.Network = config.Devnet + default: + panic(fmt.Sprintf("invalid network type: %s", *networkType)) } // Set port and ip to global config. diff --git a/common/config/global_config.go b/common/config/global_config.go index eb9dd717c..fed48ced6 100644 --- a/common/config/global_config.go +++ b/common/config/global_config.go @@ -10,5 +10,18 @@ const ( Devnet NetworkType = 2 ) +func (network NetworkType) String() string { + switch network { + case 0: + return "Mainnet" + case 1: + return "Testnet" + case 2: + return "Devnet" + default: + return "Unknown" + } +} + // Network is the type of Harmony network var Network = Testnet