OSDN Git Service

pass ci wallet-store-interface-dev
authorChengcheng Zhang <943420582@qq.com>
Fri, 21 Jun 2019 16:53:00 +0000 (00:53 +0800)
committerChengcheng Zhang <943420582@qq.com>
Fri, 21 Jun 2019 16:53:00 +0000 (00:53 +0800)
wallet/store.go
wallet/unconfirmed.go
wallet/wallet_test.go

index cffb05b..a082033 100644 (file)
@@ -66,6 +66,7 @@ func (store *LevelDBStore) GetAssetDefinitionByAssetID(assetID *bc.AssetID) []by
 func (store *LevelDBStore) SetAssetDefinition(assetID *bc.AssetID, definition []byte) {
        batch := store.DB.NewBatch()
        batch.Set(asset.ExtAssetKey(assetID), definition)
+       batch.Write()
 }
 
 // GetRawProgramByAccountHash get raw program by account hash
@@ -91,30 +92,35 @@ func (store *LevelDBStore) DeleteTransactionByHeight(height uint64) {
                }
                batch.Delete(txIter.Key())
        }
+       batch.Write()
 }
 
 // SetRawTransaction set raw transaction by block height and tx position
 func (store *LevelDBStore) SetRawTransaction(height uint64, position uint32, rawTx []byte) {
        batch := store.DB.NewBatch()
        batch.Set(calcAnnotatedKey(formatKey(height, position)), rawTx)
+       batch.Write()
 }
 
 // SetHeightAndPostion set block height and tx position according to tx ID
 func (store *LevelDBStore) SetHeightAndPostion(txID string, height uint64, position uint32) {
        batch := store.DB.NewBatch()
        batch.Set(calcTxIndexKey(txID), []byte(formatKey(height, position)))
+       batch.Write()
 }
 
 // DeleteUnconfirmedTxByTxID delete unconfirmed tx by txID
 func (store *LevelDBStore) DeleteUnconfirmedTxByTxID(txID string) {
        batch := store.DB.NewBatch()
        batch.Delete(calcUnconfirmedTxKey(txID))
+       batch.Write()
 }
 
 // SetGlobalTxIndex set global tx index by blockhash and position
 func (store *LevelDBStore) SetGlobalTxIndex(globalTxID string, blockHash *bc.Hash, position uint64) {
        batch := store.DB.NewBatch()
        batch.Set(calcGlobalTxIndexKey(globalTxID), calcGlobalTxIndex(blockHash, position))
+       batch.Write()
 }
 
 // GetStandardUTXOByID get standard utxo by id
@@ -184,24 +190,28 @@ func (store *LevelDBStore) SetUnconfirmedTx(txID string, rawTx []byte) {
 func (store *LevelDBStore) DeleteStardardUTXOByOutputID(outputID bc.Hash) {
        batch := store.DB.NewBatch()
        batch.Delete(account.StandardUTXOKey(outputID))
+       batch.Write()
 }
 
 // DeleteContractUTXOByOutputID delete contract utxo by outputID
 func (store *LevelDBStore) DeleteContractUTXOByOutputID(outputID bc.Hash) {
        batch := store.DB.NewBatch()
        batch.Delete(account.ContractUTXOKey(outputID))
+       batch.Write()
 }
 
 // SetStandardUTXO set standard utxo
 func (store *LevelDBStore) SetStandardUTXO(outputID bc.Hash, data []byte) {
        batch := store.DB.NewBatch()
        batch.Set(account.StandardUTXOKey(outputID), data)
+       batch.Write()
 }
 
 // SetContractUTXO set standard utxo
 func (store *LevelDBStore) SetContractUTXO(outputID bc.Hash, data []byte) {
        batch := store.DB.NewBatch()
        batch.Set(account.ContractUTXOKey(outputID), data)
+       batch.Write()
 }
 
 // GetWalletInfo get wallet information
index 0183198..9b4dd46 100644 (file)
@@ -51,8 +51,6 @@ func (w *Wallet) GetUnconfirmedTxs(accountID string) ([]*query.AnnotatedTx, erro
                return nil, err
        }
 
-       fmt.Println("GetUnconfirmedTxs len(annotatedTxs):", len(annotatedTxs))
-
        newAnnotatedTxs := []*query.AnnotatedTx{}
        for _, annotatedTx := range annotatedTxs {
                if accountID == "" || findTransactionsByAccount(annotatedTx, accountID) {
@@ -62,7 +60,6 @@ func (w *Wallet) GetUnconfirmedTxs(accountID string) ([]*query.AnnotatedTx, erro
        }
 
        sort.Sort(SortByTimestamp(newAnnotatedTxs))
-       fmt.Println("GetUnconfirmedTxs:", len(newAnnotatedTxs))
        return newAnnotatedTxs, nil
 }
 
@@ -153,7 +150,6 @@ func (w *Wallet) saveUnconfirmedTx(tx *types.Tx) error {
 }
 
 func (w *Wallet) delExpiredTxs() error {
-       fmt.Println("delExpiredTxs...")
        AnnotatedTx, err := w.GetUnconfirmedTxs("")
        if err != nil {
                return err
index f3c18f2..ea69818 100644 (file)
@@ -2,7 +2,6 @@ package wallet
 
 import (
        "encoding/json"
-       "fmt"
        "io/ioutil"
        "os"
        "reflect"
@@ -330,10 +329,8 @@ func TestMemPoolTxQueryLoop(t *testing.T) {
        go w.memPoolTxQueryLoop()
        w.eventDispatcher.Post(protocol.TxMsgEvent{TxMsg: &protocol.TxPoolMsg{TxDesc: &protocol.TxDesc{Tx: tx}, MsgType: protocol.MsgNewTx}})
        time.Sleep(time.Millisecond * 10)
-       if txxx, err := w.GetUnconfirmedTxByTxID(tx.ID.String()); err != nil {
+       if _, err := w.GetUnconfirmedTxByTxID(tx.ID.String()); err != nil {
                t.Fatal("dispatch new tx msg error:", err)
-       } else {
-               fmt.Println("txxx:", txxx)
        }
        w.eventDispatcher.Post(protocol.TxMsgEvent{TxMsg: &protocol.TxPoolMsg{TxDesc: &protocol.TxDesc{Tx: tx}, MsgType: protocol.MsgRemoveTx}})
        time.Sleep(time.Millisecond * 10)
@@ -342,8 +339,6 @@ func TestMemPoolTxQueryLoop(t *testing.T) {
                t.Fatal("get unconfirmed tx error:", err)
        }
 
-       fmt.Println("len(txs) is:", len(txs))
-
        if len(txs) != 0 {
                t.Fatal("dispatch remove tx msg error")
        }