From: WangYifu Date: Thu, 22 Mar 2018 05:41:14 +0000 (+0800) Subject: bugfix: disable wallet panic (#456) X-Git-Tag: v1.0.5~253 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=7c6caf7a599fcbb4b5b3163858785ca48b7f86e8;p=bytom%2Fbytom.git bugfix: disable wallet panic (#456) --- diff --git a/blockchain/reactor.go b/blockchain/reactor.go index b9518770..def6c925 100755 --- a/blockchain/reactor.go +++ b/blockchain/reactor.go @@ -97,21 +97,28 @@ func maxBytes(h http.Handler) http.Handler { } // NewBlockchainReactor returns the reactor of whole blockchain. -func NewBlockchainReactor(chain *protocol.Chain, txPool *protocol.TxPool, sw *p2p.Switch,wallet *wallet.Wallet, txfeeds *txfeed.Tracker, miningEnable bool) *BlockchainReactor { +func NewBlockchainReactor(chain *protocol.Chain, txPool *protocol.TxPool, sw *p2p.Switch, wallet *wallet.Wallet, txfeeds *txfeed.Tracker, miningEnable bool) *BlockchainReactor { newBlockCh := make(chan *bc.Hash, maxNewBlockChSize) bcr := &BlockchainReactor{ chain: chain, wallet: wallet, blockKeeper: newBlockKeeper(chain, sw), txPool: txPool, - mining: cpuminer.NewCPUMiner(chain, wallet.AccountMgr, txPool, newBlockCh), - miningPool: miningpool.NewMiningPool(chain, wallet.AccountMgr, txPool, newBlockCh), mux: http.NewServeMux(), sw: sw, txFeedTracker: txfeeds, miningEnable: miningEnable, newBlockCh: newBlockCh, } + + if wallet == nil { + bcr.mining = cpuminer.NewCPUMiner(chain, nil, txPool, newBlockCh) + bcr.miningPool = miningpool.NewMiningPool(chain, nil, txPool, newBlockCh) + } else { + bcr.mining = cpuminer.NewCPUMiner(chain, wallet.AccountMgr, txPool, newBlockCh) + bcr.miningPool = miningpool.NewMiningPool(chain, wallet.AccountMgr, txPool, newBlockCh) + } + bcr.BaseReactor = *p2p.NewBaseReactor("BlockchainReactor", bcr) return bcr } diff --git a/blockchain/rpc_reactor.go b/blockchain/rpc_reactor.go index 56556559..8fc8e64a 100644 --- a/blockchain/rpc_reactor.go +++ b/blockchain/rpc_reactor.go @@ -53,7 +53,7 @@ func webAssetsHandler(next http.Handler) http.Handler { // BuildHandler is in charge of all the rpc handling. func (bcr *BlockchainReactor) BuildHandler() { m := bcr.mux - if bcr.wallet.AccountMgr != nil && bcr.wallet.AssetReg != nil { + if bcr.wallet != nil && bcr.wallet.AccountMgr != nil && bcr.wallet.AssetReg != nil { m.Handle("/create-account", jsonHandler(bcr.createAccount)) m.Handle("/update-account-tags", jsonHandler(bcr.updateAccountTags)) m.Handle("/create-account-receiver", jsonHandler(bcr.createAccountReceiver))