OSDN Git Service

update GetControlProgram
[bytom/vapor.git] / wallet / indexer.go
index 5c84dad..139f8c4 100644 (file)
@@ -13,7 +13,6 @@ import (
        "github.com/vapor/blockchain/query"
        "github.com/vapor/consensus"
        "github.com/vapor/crypto/sha3pool"
-       "github.com/vapor/database"
        chainjson "github.com/vapor/encoding/json"
        "github.com/vapor/protocol/bc"
        "github.com/vapor/protocol/bc/types"
@@ -30,7 +29,7 @@ func parseGlobalTxIdx(globalTxIdx []byte) (*bc.Hash, uint64) {
 // saveExternalAssetDefinition save external and local assets definition,
 // when query ,query local first and if have no then query external
 // details see getAliasDefinition
-func saveExternalAssetDefinition(b *types.Block, store database.WalletStorer) {
+func saveExternalAssetDefinition(b *types.Block, store WalletStorer) error {
        store.InitBatch()
        defer store.CommitBatch()
 
@@ -38,14 +37,17 @@ func saveExternalAssetDefinition(b *types.Block, store database.WalletStorer) {
                for _, orig := range tx.Inputs {
                        if cci, ok := orig.TypedInput.(*types.CrossChainInput); ok {
                                assetID := cci.AssetId
-                               if assetExist := store.GetAssetDefinition(assetID); assetExist == nil {
+                               assetExist, err := store.GetAssetDefinition(assetID)
+                               if err != nil {
+                                       return err
+                               }
+                               if assetExist == nil {
                                        store.SetAssetDefinition(assetID, cci.AssetDefinition)
                                }
                        }
                }
        }
-
-       // store.CommitBatch()
+       return nil
 }
 
 // Summary is the struct of transaction's input and output summary
@@ -69,10 +71,6 @@ type TxSummary struct {
 
 // indexTransactions saves all annotated transactions to the database.
 func (w *Wallet) indexTransactions(b *types.Block, txStatus *bc.TransactionStatus, annotatedTxs []*query.AnnotatedTx) error {
-       // annotatedTxs := w.filterAccountTxs(b, txStatus)
-       // saveExternalAssetDefinition(b, w.store)
-       // annotateTxsAccount(annotatedTxs, w.store)
-
        for _, tx := range annotatedTxs {
                rawTx, err := json.Marshal(tx)
                if err != nil {
@@ -107,7 +105,12 @@ transactionLoop:
                        var hash [32]byte
                        sha3pool.Sum256(hash[:], v.ControlProgram())
 
-                       if bytes := w.store.GetRawProgram(hash); bytes != nil {
+                       cp, err := w.store.GetControlProgram(hash)
+                       if err != nil {
+                               log.WithFields(log.Fields{"module": logModule, "err": err, "hash": string(hash[:])}).Error("filterAccountTxs fail.")
+                               continue
+                       }
+                       if cp != nil {
                                annotatedTxs = append(annotatedTxs, w.buildAnnotatedTransaction(tx, b, statusFail, pos))
                                continue transactionLoop
                        }