OSDN Git Service

Merge branch 'dev' into backup
[bytom/bytom.git] / wallet / indexer.go
old mode 100755 (executable)
new mode 100644 (file)
index e1e8938..9552117
@@ -21,7 +21,7 @@ import (
 )
 
 type rawOutput struct {
-       OutputID bc.Hash
+       OutputID       bc.Hash
        bc.AssetAmount
        ControlProgram []byte
        txHash         bc.Hash
@@ -188,7 +188,6 @@ type TxSummary struct {
 func (w *Wallet) indexTransactions(batch db.Batch, b *types.Block, txStatus *bc.TransactionStatus) error {
        annotatedTxs := w.filterAccountTxs(b, txStatus)
        saveExternalAssetDefinition(b, w.DB)
-       annotateTxsAsset(w, annotatedTxs)
        annotateTxsAccount(annotatedTxs, w.DB)
 
        for _, tx := range annotatedTxs {
@@ -356,6 +355,7 @@ func upsertConfirmedAccountOutputs(outs []*accountOutput, batch db.Batch) error
                        AccountID:           out.AccountID,
                        Address:             out.Address,
                        ValidHeight:         out.ValidHeight,
+                       Change:              out.change,
                }
 
                data, err := json.Marshal(u)
@@ -386,7 +386,7 @@ transactionLoop:
                        var hash [32]byte
                        sha3pool.Sum256(hash[:], v.ControlProgram)
                        if bytes := w.DB.Get(account.CPKey(hash)); bytes != nil {
-                               annotatedTxs = append(annotatedTxs, buildAnnotatedTransaction(tx, b, statusFail, pos))
+                               annotatedTxs = append(annotatedTxs, w.buildAnnotatedTransaction(tx, b, statusFail, pos))
                                continue transactionLoop
                        }
                }
@@ -397,7 +397,7 @@ transactionLoop:
                                continue
                        }
                        if bytes := w.DB.Get(account.StandardUTXOKey(outid)); bytes != nil {
-                               annotatedTxs = append(annotatedTxs, buildAnnotatedTransaction(tx, b, statusFail, pos))
+                               annotatedTxs = append(annotatedTxs, w.buildAnnotatedTransaction(tx, b, statusFail, pos))
                                continue transactionLoop
                        }
                }
@@ -424,7 +424,7 @@ func (w *Wallet) GetTransactionByTxID(txID string) (*query.AnnotatedTx, error) {
 
 // GetTransactionsByTxID get account txs by account tx ID
 func (w *Wallet) GetTransactionsByTxID(txID string) ([]*query.AnnotatedTx, error) {
-       var annotatedTxs []*query.AnnotatedTx
+       annotatedTxs := []*query.AnnotatedTx{}
        formatKey := ""
 
        if txID != "" {
@@ -442,6 +442,7 @@ func (w *Wallet) GetTransactionsByTxID(txID string) ([]*query.AnnotatedTx, error
                if err := json.Unmarshal(txIter.Value(), annotatedTx); err != nil {
                        return nil, err
                }
+               annotateTxsAsset(w, []*query.AnnotatedTx{annotatedTx})
                annotatedTxs = append([]*query.AnnotatedTx{annotatedTx}, annotatedTxs...)
        }
 
@@ -513,6 +514,7 @@ func (w *Wallet) GetTransactionsByAccountID(accountID string) ([]*query.Annotate
                }
 
                if findTransactionsByAccount(annotatedTx, accountID) {
+                       annotateTxsAsset(w, []*query.AnnotatedTx{annotatedTx})
                        annotatedTxs = append(annotatedTxs, annotatedTx)
                }
        }