OSDN Git Service

update
authorChengcheng Zhang <943420582@qq.com>
Fri, 28 Jun 2019 06:49:58 +0000 (14:49 +0800)
committerChengcheng Zhang <943420582@qq.com>
Fri, 28 Jun 2019 06:49:58 +0000 (14:49 +0800)
database/wallet_store.go
wallet/indexer.go
wallet/store.go

index 60d3992..dc2af92 100644 (file)
@@ -268,18 +268,23 @@ 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) {
+func (store *WalletStore) SetTransaction(height uint64, tx *query.AnnotatedTx) error {
        batch := store.walletDB.NewBatch()
        if store.batch != nil {
                batch = store.batch
        }
 
-       batch.Set(calcAnnotatedKey(formatKey(height, position)), rawTx)
-       batch.Set(calcTxIndexKey(txID), []byte(formatKey(height, position)))
+       rawTx, err := json.Marshal(tx)
+       if err != nil {
+               return err
+       }
+       batch.Set(calcAnnotatedKey(formatKey(height, tx.Position)), rawTx)
+       batch.Set(calcTxIndexKey(tx.ID.String()), []byte(formatKey(height, tx.Position)))
 
        if store.batch == nil {
                batch.Write()
        }
+       return nil
 }
 
 // DeleteUnconfirmedTransaction delete unconfirmed tx by txID
index 139f8c4..37a578c 100644 (file)
@@ -72,13 +72,9 @@ 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 {
        for _, tx := range annotatedTxs {
-               rawTx, err := json.Marshal(tx)
-               if err != nil {
-                       log.WithFields(log.Fields{"module": logModule, "err": err}).Error("inserting annotated_txs to db")
+               if err := w.store.SetTransaction(b.Height, tx); err != nil {
                        return err
                }
-
-               w.store.SetTransaction(b.Height, tx.Position, tx.ID.String(), rawTx)
                w.store.DeleteUnconfirmedTransaction(tx.ID.String())
        }
 
index 5feaa44..c421341 100644 (file)
@@ -17,7 +17,7 @@ type WalletStorer interface {
        GetControlProgram(common.Hash) (*acc.CtrlProgram, error)
        GetAccountByAccountID(string) (*acc.Account, error)
        DeleteTransactions(uint64)
-       SetTransaction(uint64, uint32, string, []byte)
+       SetTransaction(height uint64, tx *query.AnnotatedTx) error
        DeleteUnconfirmedTransaction(string)
        SetGlobalTransactionIndex(string, *bc.Hash, uint64)
        GetStandardUTXO(bc.Hash) []byte