From e820586849a27b99d76dc89fe65104bf6b271428 Mon Sep 17 00:00:00 2001 From: Chengcheng Zhang <943420582@qq.com> Date: Sat, 22 Jun 2019 15:50:14 +0800 Subject: [PATCH] update GetTransaction --- wallet/indexer.go | 7 +++---- wallet/store.go | 17 ++++++++--------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/wallet/indexer.go b/wallet/indexer.go index e3995176..d3db27ab 100644 --- a/wallet/indexer.go +++ b/wallet/indexer.go @@ -174,12 +174,11 @@ func (w *Wallet) GetTransactionByTxID(txID string) (*query.AnnotatedTx, error) { func (w *Wallet) getAccountTxByTxID(txID string) (*query.AnnotatedTx, error) { annotatedTx := &query.AnnotatedTx{} - formatKey := w.store.GetTransactionIndex(txID) - if formatKey == nil { - return nil, errAccntTxIDNotFound + txInfo, err := w.store.GetTransaction(txID) + if err != nil { + return nil, err } - txInfo := w.store.GetTransaction(formatKey) if err := json.Unmarshal(txInfo, annotatedTx); err != nil { return nil, err } diff --git a/wallet/store.go b/wallet/store.go index 6638d046..b95b3af3 100644 --- a/wallet/store.go +++ b/wallet/store.go @@ -23,8 +23,7 @@ type Store interface { DeleteUnconfirmedTransaction(string) SetGlobalTransactionIndex(string, *bc.Hash, uint64) GetStandardUTXO(bc.Hash) []byte - GetTransactionIndex(string) []byte - GetTransaction([]byte) []byte + GetTransaction(string) ([]byte, error) GetGlobalTransaction(string) []byte GetTransactions() ([]*query.AnnotatedTx, error) GetUnconfirmedTransactions() ([]*query.AnnotatedTx, error) @@ -121,14 +120,14 @@ func (store *LevelDBStore) GetStandardUTXO(outid bc.Hash) []byte { return store.DB.Get(account.StandardUTXOKey(outid)) } -// GetTransactionIndex get tx index by txID -func (store *LevelDBStore) GetTransactionIndex(txID string) []byte { - return store.DB.Get(calcTxIndexKey(txID)) -} - // GetTransaction get tx by tx index -func (store *LevelDBStore) GetTransaction(txIndex []byte) []byte { - return store.DB.Get(calcAnnotatedKey(string(txIndex))) +func (store *LevelDBStore) GetTransaction(txID string) ([]byte, error) { + formatKey := store.DB.Get(calcTxIndexKey(txID)) + if formatKey == nil { + return nil, errAccntTxIDNotFound + } + txInfo := store.DB.Get(calcAnnotatedKey(string(formatKey))) + return txInfo, nil } // GetGlobalTransaction get global tx by txID -- 2.11.0