OSDN Git Service

bugfix: disable wallet panic (#456)
authorWangYifu <lbqds@cryptape.com>
Thu, 22 Mar 2018 05:41:14 +0000 (13:41 +0800)
committerYongfeng LI <wliyongfeng@gmail.com>
Thu, 22 Mar 2018 05:41:14 +0000 (13:41 +0800)
blockchain/reactor.go
blockchain/rpc_reactor.go

index b951877..def6c92 100755 (executable)
@@ -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
 }
index 5655655..8fc8e64 100644 (file)
@@ -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))