Skip to content

Commit

Permalink
Much more resiliant FallbackProvider which can ignore properties that…
Browse files Browse the repository at this point in the history
… are only approximate and supports per-provider priorities (ethers-io#635, ethers-io#588).
  • Loading branch information
ricmoo committed Jan 19, 2020
1 parent 8df435c commit 7b90124
Show file tree
Hide file tree
Showing 2 changed files with 412 additions and 244 deletions.
22 changes: 21 additions & 1 deletion src.ts/base-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,23 @@ export class BaseProvider extends Provider {

// Add transactions
if (includeTransactions) {
let blockNumber: number = null;
for (let i = 0; i < block.transactions.length; i++) {
const tx = block.transactions[i];
if (tx.blockNumber == null) {
tx.confirmations = 0;

} else if (tx.confirmations == null) {
if (blockNumber == null) {
blockNumber = await this._getInternalBlockNumber(100 + 2 * this.pollingInterval);
}

// Add the confirmations using the fast block number (pessimistic)
let confirmations = (blockNumber - tx.blockNumber) + 1;
if (confirmations <= 0) { confirmations = 1; }
tx.confirmations = confirmations;
}
}
return this.formatter.blockWithTransactions(block);
}

Expand Down Expand Up @@ -777,7 +794,10 @@ export class BaseProvider extends Provider {
async getLogs(filter: Filter | FilterByBlockHash | Promise<Filter | FilterByBlockHash>): Promise<Array<Log>> {
await this.ready;
const params = await resolveProperties({ filter: this._getFilter(filter) });
const logs = await this.perform("getLogs", params);
const logs: Array<Log> = await this.perform("getLogs", params);
logs.forEach((log) => {
if (log.removed == null) { log.removed = false; }
});
return Formatter.arrayOf(this.formatter.filterLog.bind(this.formatter))(logs);
}

Expand Down

0 comments on commit 7b90124

Please sign in to comment.