OSDN Git Service

fix get-transaction
authoroysheng <oysheng@bytom.io>
Tue, 5 Jun 2018 08:03:12 +0000 (16:03 +0800)
committeroysheng <oysheng@bytom.io>
Tue, 5 Jun 2018 08:03:12 +0000 (16:03 +0800)
wallet/indexer.go

index c6e07ac..0c2d10e 100644 (file)
@@ -418,15 +418,18 @@ transactionLoop:
 // GetTransaction search confirmed or unconfirmed transaction by txID
 func (w *Wallet) GetTransaction(txID string) (*query.AnnotatedTx, error) {
        annotatedTx, err := w.GetTransactionByTxID(txID)
-       if errors.Root(err) != ErrNotFoundTx {
-               return nil, err
+       if errors.Root(err) == ErrNotFoundTx {
+               // transaction not found in blockchain db, search it from unconfirmed db
+               annotatedTx, err = w.GetUnconfirmedTxByTxID(txID)
+               if err != nil {
+                       return nil, err
+               }
+               return annotatedTx, nil
        }
 
-       annotatedTx, err = w.GetUnconfirmedTxByTxID(txID)
        if err != nil {
                return nil, err
        }
-
        return annotatedTx, nil
 }