@@ -42,27 +42,25 @@ export default class GetBlocks {
4242 const cachedPreviousTxs = new Map ( )
4343 for ( const block of blocks ) {
4444 logger . debug ( `checking block #${ block . header . number } , ${ block . transactions . length } txs` )
45- for ( const tx of block . transactions ) {
45+ for ( let i = 0 ; i < block . transactions . length ; ++ i ) {
46+ const tx = block . transactions [ i ]
4647 const checkTx = new CheckTx ( tx , this . url )
4748 const addresses = await checkTx . check ( lockHashes )
4849 if ( addresses . length > 0 ) {
49- const inputs = tx . inputs !
50- for ( let i = 0 ; i < inputs . length ; ++ i ) {
51- if ( i === 0 ) {
52- continue
50+ if ( i > 0 ) {
51+ for ( const input of tx . inputs ! ) {
52+ const previousTxHash = input . previousOutput ! . txHash
53+ let previousTxWithStatus = cachedPreviousTxs . get ( previousTxHash )
54+ if ( ! previousTxWithStatus ) {
55+ previousTxWithStatus = await this . getTransaction ( previousTxHash )
56+ cachedPreviousTxs . set ( previousTxHash , previousTxWithStatus )
57+ }
58+ const previousTx = TypeConvert . toTransaction ( previousTxWithStatus . transaction )
59+ const previousOutput = previousTx . outputs ! [ + input . previousOutput ! . index ]
60+ input . lock = previousOutput . lock
61+ input . lockHash = LockUtils . lockScriptToHash ( input . lock )
62+ input . capacity = previousOutput . capacity
5363 }
54- const input = inputs [ i ]
55- const previousTxHash = input . previousOutput ! . txHash
56- let previousTxWithStatus = cachedPreviousTxs . get ( previousTxHash )
57- if ( ! previousTxWithStatus ) {
58- previousTxWithStatus = await this . getTransaction ( previousTxHash )
59- cachedPreviousTxs . set ( previousTxHash , previousTxWithStatus )
60- }
61- const previousTx = TypeConvert . toTransaction ( previousTxWithStatus . transaction )
62- const previousOutput = previousTx . outputs ! [ + input . previousOutput ! . index ]
63- input . lock = previousOutput . lock
64- input . lockHash = LockUtils . lockScriptToHash ( input . lock )
65- input . capacity = previousOutput . capacity
6664 }
6765 await TransactionPersistor . saveFetchTx ( tx )
6866 addressesUsedSubject . next ( {
0 commit comments