Skip to content

Commit

Permalink
Merge pull request #5 from evannetwork/feature/CORE-528-fix-missing-b…
Browse files Browse the repository at this point in the history
…locks-from-infura

fix missing blocks from infura in signer tx handling
  • Loading branch information
S3bb1 authored Sep 25, 2019
2 parents fca9f2f + 8087548 commit a5a4342
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
1 change: 1 addition & 0 deletions VERSIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
### Features

### Fixes
- fix missing blocks, that could not be retrieved after `newBlockHeaders` was triggered

### Deprecations

Expand Down
27 changes: 18 additions & 9 deletions src/contracts/signer-internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,25 @@ export class SignerInternal extends Logger implements SignerInterface {

// only load block details, when pending transactions are open
if (pendingTransactionHashes.length !== 0) {
const blockDetails = await this.web3.eth.getBlock(blockHeader.number);

// iterate through all pending transactions and check if transaction was finished
Object.keys(this.pendingTransactions).forEach((transactionHash: string) => {
// if transaction was finished, call all the callbacks and delete the subscription
if (blockDetails.transactions.indexOf(transactionHash) !== -1) {
this.pendingTransactions[transactionHash].forEach(callback => callback(blockHeader));
delete this.pendingTransactions[transactionHash];
const blockNumber = blockHeader.number;
const blockStart = Date.now();
const checkInterval = setInterval(async () => {
this.log(`checking for block ${blockNumber}`, 'debug');
const blockDetails = await this.web3.eth.getBlock(blockHeader.number);
if (blockDetails) {
clearInterval(checkInterval);
this.log(`received block details for block ${blockNumber} after ${Date.now() - blockStart}ms`, 'debug');

// iterate through all pending transactions and check if transaction was finished
Object.keys(this.pendingTransactions).forEach((transactionHash: string) => {
// if transaction was finished, call all the callbacks and delete the subscription
if (blockDetails.transactions.indexOf(transactionHash) !== -1) {
this.pendingTransactions[transactionHash].forEach(callback => callback(blockHeader));
delete this.pendingTransactions[transactionHash];
}
});
}
});
}, 500);
}
});
}
Expand Down

0 comments on commit a5a4342

Please sign in to comment.