Skip to content

Commit

Permalink
fix: update tx and its outputs in different sqls
Browse files Browse the repository at this point in the history
  • Loading branch information
classicalliu committed Nov 15, 2019
1 parent 7cb8ad3 commit b8fe366
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion packages/neuron-wallet/src/services/tx/transaction-persistor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,25 @@ export class TransactionPersistor {
txEntity.blockHash = transaction.blockHash
txEntity.blockNumber = transaction.blockNumber
txEntity.status = TransactionStatus.Success
await connection.manager.save([txEntity, ...outputs.concat(previousOutputs)])

const sliceSize = 100
const queryRunner = connection.createQueryRunner()
await TransactionPersistor.waitUntilTransactionFinished(queryRunner)
await queryRunner.startTransaction()
try {
await queryRunner.manager.save(txEntity)
for (const slice of Utils.eachSlice(previousOutputs, sliceSize)) {
await queryRunner.manager.save(slice)
}
for (const slice of Utils.eachSlice(outputs, sliceSize)) {
await queryRunner.manager.save(slice)
}
await queryRunner.commitTransaction()
} catch (err) {
await queryRunner.rollbackTransaction()
} finally {
await queryRunner.release()
}

return txEntity
}
Expand Down

0 comments on commit b8fe366

Please sign in to comment.