OSDN Git Service

fix bug (#260)
authorwz <mars@bytom.io>
Thu, 11 Jul 2019 10:28:10 +0000 (18:28 +0800)
committerPaladz <yzhu101@uottawa.ca>
Thu, 11 Jul 2019 10:28:09 +0000 (18:28 +0800)
* fix  bug

* fix bug

database/wallet_store.go
wallet/indexer.go
wallet/unconfirmed.go

index b810e46..a0c2a36 100644 (file)
@@ -342,6 +342,7 @@ func (store *WalletStore) ListAccountUTXOs(id string, isSmartContract bool) ([]*
 
                confirmedUTXOs = append(confirmedUTXOs, utxo)
        }
+
        return confirmedUTXOs, nil
 }
 
@@ -376,8 +377,11 @@ func (store *WalletStore) ListTransactions(accountID string, StartTxID string, c
                        return nil, err
                }
 
-               annotatedTxs = append(annotatedTxs, annotatedTx)
-               txNum--
+               if accountID == "" || wallet.FindTransactionsByAccount(annotatedTx, accountID) {
+                       annotatedTxs = append([]*query.AnnotatedTx{annotatedTx}, annotatedTxs...)
+                       txNum--
+               }
+
        }
 
        return annotatedTxs, nil
index 9f55115..0cf4a32 100644 (file)
@@ -212,7 +212,7 @@ func (w *Wallet) GetTransactionsSummary(transactions []*query.AnnotatedTx) []TxS
        return Txs
 }
 
-func findTransactionsByAccount(annotatedTx *query.AnnotatedTx, accountID string) bool {
+func FindTransactionsByAccount(annotatedTx *query.AnnotatedTx, accountID string) bool {
        for _, input := range annotatedTx.Inputs {
                if input.AccountID == accountID {
                        return true
@@ -238,16 +238,14 @@ func (w *Wallet) GetTransactions(accountID string, StartTxID string, count uint,
 
        newAnnotatedTxs := []*query.AnnotatedTx{}
        for _, annotatedTx := range annotatedTxs {
-               if accountID == "" || findTransactionsByAccount(annotatedTx, accountID) {
-                       annotateTxsAsset(w, []*query.AnnotatedTx{annotatedTx})
-                       newAnnotatedTxs = append([]*query.AnnotatedTx{annotatedTx}, newAnnotatedTxs...)
-               }
+               annotateTxsAsset(w, []*query.AnnotatedTx{annotatedTx})
+               newAnnotatedTxs = append([]*query.AnnotatedTx{annotatedTx}, newAnnotatedTxs...)
        }
 
        if unconfirmed {
-               sort.Sort(SortByTimestamp(annotatedTxs))
+               sort.Sort(SortByTimestamp(newAnnotatedTxs))
        } else {
-               sort.Sort(SortByHeight(annotatedTxs))
+               sort.Sort(SortByHeight(newAnnotatedTxs))
        }
 
        return newAnnotatedTxs, nil
index 229cbc5..aabf8d2 100644 (file)
@@ -57,7 +57,7 @@ func (w *Wallet) GetUnconfirmedTxs(accountID string) ([]*query.AnnotatedTx, erro
 
        newAnnotatedTxs := []*query.AnnotatedTx{}
        for _, annotatedTx := range annotatedTxs {
-               if accountID == "" || findTransactionsByAccount(annotatedTx, accountID) {
+               if accountID == "" || FindTransactionsByAccount(annotatedTx, accountID) {
                        annotateTxsAsset(w, []*query.AnnotatedTx{annotatedTx})
                        newAnnotatedTxs = append([]*query.AnnotatedTx{annotatedTx}, newAnnotatedTxs...)
                }