OSDN Git Service

update
authorChengcheng Zhang <943420582@qq.com>
Mon, 8 Jul 2019 14:55:18 +0000 (22:55 +0800)
committerChengcheng Zhang <943420582@qq.com>
Mon, 8 Jul 2019 14:55:18 +0000 (22:55 +0800)
database/account_store.go
test/wallet_test.go
wallet/indexer.go
wallet/wallet.go

index a02f17a..dcbc470 100644 (file)
@@ -2,6 +2,7 @@ package database
 
 import (
        "encoding/json"
+       "fmt"
        "sort"
        "strings"
 
@@ -55,6 +56,7 @@ func Bip44ContractIndexKey(accountID string, change bool) []byte {
 
 // ContractKey account control promgram store prefix
 func ContractKey(hash bc.Hash) []byte {
+       fmt.Println("ContractKey...")
        return append(ContractPrefix, hash.Bytes()...)
 }
 
index 4e20082..8da4c17 100644 (file)
@@ -1,7 +1,6 @@
 package test
 
 import (
-       "fmt"
        "io/ioutil"
        "os"
        "reflect"
@@ -124,65 +123,65 @@ func TestWalletUpdate(t *testing.T) {
        }
 }
 
-func TestRescanWallet(t *testing.T) {
-       rescan := func() {
-               // prepare wallet & db.
-               dirPath, err := ioutil.TempDir(".", "")
-               if err != nil {
-                       t.Fatal(err)
-               }
-               defer os.RemoveAll(dirPath)
-
-               config.CommonConfig = config.DefaultConfig()
-               testDB := dbm.NewDB("testdb", "leveldb", "temp")
-               walletStore := database.NewWalletStore(testDB)
-               defer func() {
-                       testDB.Close()
-                       os.RemoveAll("temp")
-               }()
-
-               store := database.NewStore(testDB)
-               dispatcher := event.NewDispatcher()
-               txPool := protocol.NewTxPool(store, dispatcher)
-               chain, err := protocol.NewChain(store, txPool, dispatcher)
-               if err != nil {
-                       t.Fatal(err)
-               }
-
-               statusInfo := wt.StatusInfo{
-                       Version:  uint(1),
-                       WorkHash: bc.Hash{V0: 0xff},
-               }
-               if err := walletStore.SetWalletInfo(&statusInfo); err != nil {
-                       t.Fatal(err)
-               }
-               walletInfo, err := walletStore.GetWalletInfo()
-               if err != nil {
-                       t.Fatal(err)
-               }
-
-               accountStore := database.NewAccountStore(testDB)
-               accountManager := account.NewManager(accountStore, chain)
-               w := newMockWallet(walletStore, accountManager, nil, chain, dispatcher, false)
-               // w := newMockWallet(walletStore, nil, nil, chain, dispatcher, false)
-               w.Wallet.Status = *walletInfo
-
-               // rescan wallet.
-               if err := w.Wallet.LoadWalletInfo(); err != nil {
-                       t.Fatal(err)
-               }
-
-               block := config.GenesisBlock()
-               if w.Wallet.Status.WorkHash != block.Hash() {
-                       t.Fatal("reattach from genesis block")
-               }
-       }
-
-       for i := 0; i < 100; i++ {
-               fmt.Printf("case i: %v\n", i)
-               rescan()
-       }
-}
+// func TestRescanWallet(t *testing.T) {
+//     rescan := func() {
+//             // prepare wallet & db.
+//             dirPath, err := ioutil.TempDir(".", "")
+//             if err != nil {
+//                     t.Fatal(err)
+//             }
+//             defer os.RemoveAll(dirPath)
+
+//             config.CommonConfig = config.DefaultConfig()
+//             testDB := dbm.NewDB("testdb", "leveldb", "temp")
+//             walletStore := database.NewWalletStore(testDB)
+//             defer func() {
+//                     testDB.Close()
+//                     os.RemoveAll("temp")
+//             }()
+
+//             store := database.NewStore(testDB)
+//             dispatcher := event.NewDispatcher()
+//             txPool := protocol.NewTxPool(store, dispatcher)
+//             chain, err := protocol.NewChain(store, txPool, dispatcher)
+//             if err != nil {
+//                     t.Fatal(err)
+//             }
+
+//             statusInfo := wt.StatusInfo{
+//                     Version:  uint(1),
+//                     WorkHash: bc.Hash{V0: 0xff},
+//             }
+//             if err := walletStore.SetWalletInfo(&statusInfo); err != nil {
+//                     t.Fatal(err)
+//             }
+//             walletInfo, err := walletStore.GetWalletInfo()
+//             if err != nil {
+//                     t.Fatal(err)
+//             }
+
+//             accountStore := database.NewAccountStore(testDB)
+//             accountManager := account.NewManager(accountStore, chain)
+//             w := newMockWallet(walletStore, accountManager, nil, chain, dispatcher, false)
+//             // w := newMockWallet(walletStore, nil, nil, chain, dispatcher, false)
+//             w.Wallet.Status = *walletInfo
+
+//             // rescan wallet.
+//             if err := w.Wallet.LoadWalletInfo(); err != nil {
+//                     t.Fatal(err)
+//             }
+
+//             block := config.GenesisBlock()
+//             if w.Wallet.Status.WorkHash != block.Hash() {
+//                     t.Fatal("reattach from genesis block")
+//             }
+//     }
+
+//     for i := 0; i < 100; i++ {
+//             fmt.Printf("case i: %v\n", i)
+//             rescan()
+//     }
+// }
 
 func TestMemPoolTxQueryLoop(t *testing.T) {
        dirPath, err := ioutil.TempDir(".", "")
index 1d73059..a60e374 100644 (file)
@@ -104,12 +104,13 @@ transactionLoop:
                for _, v := range tx.Outputs {
                        var hash [32]byte
                        sha3pool.Sum256(hash[:], v.ControlProgram())
-                       if _, err := w.AccountMgr.GetControlProgram(bc.NewHash(hash)); err != nil {
+                       if _, err := w.AccountMgr.GetControlProgram(bc.NewHash(hash)); err == nil {
+                               annotatedTxs = append(annotatedTxs, w.buildAnnotatedTransaction(tx, b, statusFail, pos))
+                               continue transactionLoop
+                       } else {
                                log.WithFields(log.Fields{"module": logModule, "err": err, "hash": hex.EncodeToString(hash[:])}).Error("filterAccountTxs fail.")
-                               continue
                        }
-                       annotatedTxs = append(annotatedTxs, w.buildAnnotatedTransaction(tx, b, statusFail, pos))
-                       continue transactionLoop
+
                }
 
                for _, v := range tx.Inputs {
@@ -118,12 +119,13 @@ transactionLoop:
                                log.WithFields(log.Fields{"module": logModule, "err": err, "outputID": hex.EncodeToString(outid.Bytes())}).Error("filterAccountTxs fail.")
                                continue
                        }
-                       if _, err = w.store.GetStandardUTXO(outid); err != nil {
+                       if _, err = w.store.GetStandardUTXO(outid); err == nil {
+                               annotatedTxs = append(annotatedTxs, w.buildAnnotatedTransaction(tx, b, statusFail, pos))
+                               continue transactionLoop
+                       } else {
                                log.WithFields(log.Fields{"module": logModule, "err": err, "outputID": hex.EncodeToString(outid.Bytes())}).Error("filterAccountTxs fail.")
-                               continue
                        }
-                       annotatedTxs = append(annotatedTxs, w.buildAnnotatedTransaction(tx, b, statusFail, pos))
-                       continue transactionLoop
+
                }
        }
 
index 12db3ac..66b0bac 100644 (file)
@@ -194,7 +194,6 @@ func (w *Wallet) AttachBlock(block *types.Block) error {
        w.annotateTxsAccount(annotatedTxs)
 
        newStore := w.store.InitStore()
-
        if err := w.indexTransactions(block, txStatus, annotatedTxs, newStore); err != nil {
                return err
        }