OSDN Git Service

update
authorChengcheng Zhang <943420582@qq.com>
Mon, 24 Jun 2019 15:13:45 +0000 (23:13 +0800)
committerChengcheng Zhang <943420582@qq.com>
Mon, 24 Jun 2019 15:13:45 +0000 (23:13 +0800)
database/wallet_store.go
wallet/indexer.go
wallet/wallet.go

index 4c2bde0..59da494 100644 (file)
@@ -146,8 +146,10 @@ func (store *WalletStore) GetAssetDefinition(assetID *bc.AssetID) []byte {
 // SetAssetDefinition set assetID and definition
 func (store *WalletStore) SetAssetDefinition(assetID *bc.AssetID, definition []byte) {
        if store.batch == nil {
+               fmt.Println("SetAssetDefinition... nil")
                store.DB.Set(asset.ExtAssetKey(assetID), definition)
        } else {
+               fmt.Println("SetAssetDefinition... not nil")
                store.batch.Set(asset.ExtAssetKey(assetID), definition)
        }
 }
@@ -185,12 +187,15 @@ func (store *WalletStore) DeleteTransactions(height uint64) {
 
 // SetTransaction set raw transaction by block height and tx position
 func (store *WalletStore) SetTransaction(height uint64, position uint32, txID string, rawTx []byte) {
+       fmt.Println("SetTransaction...")
        if store.batch == nil {
+               fmt.Println("SetTransaction ... nil")
                batch := store.DB.NewBatch()
                batch.Set(calcAnnotatedKey(formatKey(height, position)), rawTx)
                batch.Set(calcTxIndexKey(txID), []byte(formatKey(height, position)))
                batch.Write()
        } else {
+               fmt.Println("SetTransaction ... not nil")
                store.batch.Set(calcAnnotatedKey(formatKey(height, position)), rawTx)
                store.batch.Set(calcTxIndexKey(txID), []byte(formatKey(height, position)))
        }
index 7bc2b3c..0d5f9f0 100644 (file)
@@ -66,10 +66,10 @@ type TxSummary struct {
 }
 
 // indexTransactions saves all annotated transactions to the database.
-func (w *Wallet) indexTransactions(b *types.Block, txStatus *bc.TransactionStatus) error {
-       annotatedTxs := w.filterAccountTxs(b, txStatus)
-       saveExternalAssetDefinition(b, w.store)
-       annotateTxsAccount(annotatedTxs, w.store)
+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)
index 7ffa876..d3d97da 100644 (file)
@@ -187,10 +187,14 @@ func (w *Wallet) AttachBlock(block *types.Block) error {
                w.RecoveryMgr.finished()
        }
 
+       annotatedTxs := w.filterAccountTxs(block, txStatus)
+       saveExternalAssetDefinition(block, w.store)
+       annotateTxsAccount(annotatedTxs, w.store)
+
        // w.store.InitBatch()
        // defer w.store.CommitBatch()
 
-       if err := w.indexTransactions(block, txStatus); err != nil {
+       if err := w.indexTransactions(block, txStatus, annotatedTxs); err != nil {
                return err
        }