wtxmgr: update rangeBlockTransactions to use minedTxDetails

Code is duplicated across these two functions, so update
rangeBlockTransactions to use minedTxDetails. When iterating through
a block, we do have the block metadata already (which is looked up by
minedTxDetails). This change can be further optimized to split
minedTxDetails into minedTxDetails and minedTxDetailsWithoutBlock to
reduce this redundancy.
This commit is contained in:
carla 2020-04-30 09:08:11 +02:00
parent 9e2f2ce157
commit 9aed49070d
No known key found for this signature in database
GPG key ID: 4CA7FE54A6213C91

View file

@ -296,52 +296,13 @@ func (s *Store) rangeBlockTransactions(ns walletdb.ReadBucket, begin, end int32,
"block %v", txHash, block.Height) "block %v", txHash, block.Height)
return false, storeError(ErrData, str, nil) return false, storeError(ErrData, str, nil)
} }
detail := TxDetails{
Block: BlockMeta{ detail, err := s.minedTxDetails(ns, &txHash, k, v)
Block: block.Block,
Time: block.Time,
},
}
err := readRawTxRecord(&txHash, v, &detail.TxRecord)
if err != nil { if err != nil {
return false, err return false, err
} }
credIter := makeReadCreditIterator(ns, k) details = append(details, *detail)
for credIter.next() {
if int(credIter.elem.Index) >= len(detail.MsgTx.TxOut) {
str := "saved credit index exceeds number of outputs"
return false, storeError(ErrData, str, nil)
}
// The credit iterator does not record whether
// this credit was spent by an unmined
// transaction, so check that here.
if !credIter.elem.Spent {
k := canonicalOutPoint(&txHash, credIter.elem.Index)
spent := existsRawUnminedInput(ns, k) != nil
credIter.elem.Spent = spent
}
detail.Credits = append(detail.Credits, credIter.elem)
}
if credIter.err != nil {
return false, credIter.err
}
debIter := makeReadDebitIterator(ns, k)
for debIter.next() {
if int(debIter.elem.Index) >= len(detail.MsgTx.TxIn) {
str := "saved debit index exceeds number of inputs"
return false, storeError(ErrData, str, nil)
}
detail.Debits = append(detail.Debits, debIter.elem)
}
if debIter.err != nil {
return false, debIter.err
}
details = append(details, detail)
} }
// Every block record must have at least one transaction, so it // Every block record must have at least one transaction, so it