OSDN Git Service

update SetUnconfirmedTransaction
authorChengcheng Zhang <943420582@qq.com>
Fri, 28 Jun 2019 08:25:34 +0000 (16:25 +0800)
committerChengcheng Zhang <943420582@qq.com>
Fri, 28 Jun 2019 08:25:34 +0000 (16:25 +0800)
database/wallet_store.go
wallet/store.go
wallet/unconfirmed.go

index f21d067..362f96b 100644 (file)
@@ -384,12 +384,17 @@ func (store *WalletStore) GetUnconfirmedTransaction(txID string) (*query.Annotat
 }
 
 // SetUnconfirmedTransaction set unconfirmed tx by txID
-func (store *WalletStore) SetUnconfirmedTransaction(txID string, rawTx []byte) {
+func (store *WalletStore) SetUnconfirmedTransaction(txID string, tx *query.AnnotatedTx) error {
+       rawTx, err := json.Marshal(tx)
+       if err != nil {
+               return err
+       }
        if store.batch == nil {
                store.walletDB.Set(calcUnconfirmedTxKey(txID), rawTx)
        } else {
                store.batch.Set(calcUnconfirmedTxKey(txID), rawTx)
        }
+       return nil
 }
 
 // DeleteStardardUTXO delete stardard utxo by outputID
index 13b2963..9478a1d 100644 (file)
@@ -26,7 +26,7 @@ type WalletStorer interface {
        GetTransactions() ([]*query.AnnotatedTx, error)
        GetUnconfirmedTransactions() ([]*query.AnnotatedTx, error)
        GetUnconfirmedTransaction(string) (*query.AnnotatedTx, error)
-       SetUnconfirmedTransaction(string, []byte)
+       SetUnconfirmedTransaction(string, *query.AnnotatedTx) error
        DeleteStardardUTXO(bc.Hash)
        DeleteContractUTXO(bc.Hash)
        SetStandardUTXO(bc.Hash, []byte)
index 5942965..2df04d7 100644 (file)
@@ -1,7 +1,6 @@
 package wallet
 
 import (
-       "encoding/json"
        "fmt"
        "sort"
        "time"
@@ -143,12 +142,9 @@ func (w *Wallet) saveUnconfirmedTx(tx *types.Tx) error {
        annotatedTxs = append(annotatedTxs, annotatedTx)
        annotateTxsAccount(annotatedTxs, w.store)
 
-       rawTx, err := json.Marshal(annotatedTxs[0])
-       if err != nil {
+       if err := w.store.SetUnconfirmedTransaction(tx.ID.String(), annotatedTxs[0]); err != nil {
                return err
        }
-
-       w.store.SetUnconfirmedTransaction(tx.ID.String(), rawTx)
        return nil
 }