Skip to content

Commit

Permalink
fix: skip the cellbase tx, not the first input
Browse files Browse the repository at this point in the history
  • Loading branch information
classicalliu committed Nov 8, 2019
1 parent 7e8a578 commit aeeb464
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions packages/neuron-wallet/src/services/sync/get-blocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,27 +42,25 @@ export default class GetBlocks {
const cachedPreviousTxs = new Map()
for (const block of blocks) {
logger.debug(`checking block #${block.header.number}, ${block.transactions.length} txs`)
for (const tx of block.transactions) {
for (let i = 0; i < block.transactions.length; ++i) {
const tx = block.transactions[i]
const checkTx = new CheckTx(tx, this.url)
const addresses = await checkTx.check(lockHashes)
if (addresses.length > 0) {
const inputs = tx.inputs!
for (let i = 0; i < inputs.length; ++i) {
if (i === 0) {
continue
if (i > 0) {
for (const input of tx.inputs!) {
const previousTxHash = input.previousOutput!.txHash
let previousTxWithStatus = cachedPreviousTxs.get(previousTxHash)
if (!previousTxWithStatus) {
previousTxWithStatus = await this.getTransaction(previousTxHash)
cachedPreviousTxs.set(previousTxHash, previousTxWithStatus)
}
const previousTx = TypeConvert.toTransaction(previousTxWithStatus.transaction)
const previousOutput = previousTx.outputs![+input.previousOutput!.index]
input.lock = previousOutput.lock
input.lockHash = LockUtils.lockScriptToHash(input.lock)
input.capacity = previousOutput.capacity
}
const input = inputs[i]
const previousTxHash = input.previousOutput!.txHash
let previousTxWithStatus = cachedPreviousTxs.get(previousTxHash)
if (!previousTxWithStatus) {
previousTxWithStatus = await this.getTransaction(previousTxHash)
cachedPreviousTxs.set(previousTxHash, previousTxWithStatus)
}
const previousTx = TypeConvert.toTransaction(previousTxWithStatus.transaction)
const previousOutput = previousTx.outputs![+input.previousOutput!.index]
input.lock = previousOutput.lock
input.lockHash = LockUtils.lockScriptToHash(input.lock)
input.capacity = previousOutput.capacity
}
await TransactionPersistor.saveFetchTx(tx)
addressesUsedSubject.next({
Expand Down

0 comments on commit aeeb464

Please sign in to comment.