From 08439e4e5282fd2b6aa26103d3fb9cc1079dba9c Mon Sep 17 00:00:00 2001 From: gasby88 Date: Tue, 19 Jun 2018 18:02:11 +0800 Subject: [PATCH] [ONT-894]Add cleartestmodedata flag in testmode (#367) signed-off-by:wangbing@onchain.com --- cmd/usage.go | 1 + cmd/utils/flags.go | 4 ++++ main.go | 3 ++- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/cmd/usage.go b/cmd/usage.go index 0f827bb6..bd715643 100644 --- a/cmd/usage.go +++ b/cmd/usage.go @@ -159,6 +159,7 @@ var AppHelpFlagGroups = []flagGroup{ Flags: []cli.Flag{ utils.EnableTestModeFlag, utils.TestModeGenBlockTimeFlag, + utils.ClearTestModeDataFlag, }, }, { diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 3e7129d0..358be510 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -101,6 +101,10 @@ var ( Usage: "Interval of generate block in test mode, unit(s)", Value: config.DEFAULT_GEN_BLOCK_TIME, } + ClearTestModeDataFlag = cli.BoolFlag{ + Name: "cleartestmodedata", + Usage: "Clear test mode block data", + } //P2P setting ReservedPeersOnlyFlag = cli.BoolFlag{ diff --git a/main.go b/main.go index 6cb0c7d0..f62d9318 100644 --- a/main.go +++ b/main.go @@ -102,6 +102,7 @@ func setupAPP() *cli.App { //test mode setting utils.EnableTestModeFlag, utils.TestModeGenBlockTimeFlag, + utils.ClearTestModeDataFlag, //rpc setting utils.RPCDisabledFlag, utils.RPCPortFlag, @@ -234,7 +235,7 @@ func initLedger(ctx *cli.Context) (*ledger.Ledger, error) { var err error dbDir := config.DefConfig.Common.DataDir + string(os.PathSeparator) + config.DefConfig.P2PNode.NetworkName - if config.DefConfig.Genesis.ConsensusType == config.CONSENSUS_TYPE_SOLO { + if ctx.GlobalBool(utils.GetFlagName(utils.EnableTestModeFlag)) && ctx.GlobalBool(utils.GetFlagName(utils.ClearTestModeDataFlag)) { err = os.RemoveAll(dbDir) if err != nil { log.Warnf("InitLedger remove:%s error:%s", dbDir, err)