OSDN Git Service

update
authorChengcheng Zhang <943420582@qq.com>
Mon, 24 Jun 2019 12:31:23 +0000 (20:31 +0800)
committerChengcheng Zhang <943420582@qq.com>
Mon, 24 Jun 2019 12:31:23 +0000 (20:31 +0800)
database/wallet_store.go
wallet/wallet.go

index 334882c..4d28783 100644 (file)
@@ -166,6 +166,9 @@ func (store *WalletStore) GetAccountByAccountID(accountID string) []byte {
 func (store *WalletStore) DeleteTransactions(height uint64) {
        tmpTx := query.AnnotatedTx{}
        batch := store.DB.NewBatch()
+       if store.batch != nil {
+               batch = store.batch
+       }
        txIter := store.DB.IteratorPrefix(calcDeleteKey(height))
        defer txIter.Release()
 
@@ -175,7 +178,9 @@ func (store *WalletStore) DeleteTransactions(height uint64) {
                }
                batch.Delete(txIter.Key())
        }
-       batch.Write()
+       if store.batch == nil {
+               batch.Write()
+       }
 }
 
 // SetTransaction set raw transaction by block height and tx position
index b7ee866..06d5f07 100644 (file)
@@ -212,6 +212,9 @@ func (w *Wallet) DetachBlock(block *types.Block) error {
                return err
        }
 
+       w.store.InitBatch()
+       defer w.store.CommitBatch()
+
        w.detachUtxos(block, txStatus)
        w.store.DeleteTransactions(w.status.BestHeight)
 
@@ -222,8 +225,9 @@ func (w *Wallet) DetachBlock(block *types.Block) error {
                w.status.WorkHeight = w.status.BestHeight
                w.status.WorkHash = w.status.BestHash
        }
+       err = w.commitWalletInfo()
 
-       return w.commitWalletInfo()
+       return err
 }
 
 //WalletUpdate process every valid block and reverse every invalid block which need to rollback