Correctly set last emitted block for WebSocketProvider (#856).
This commit is contained in:
parent
8efd8d2031
commit
1b0ad5aa69
@ -823,7 +823,7 @@ export class BaseProvider extends Provider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return this.formatter.block(block);
|
return this.formatter.block(block);
|
||||||
}, { onceBlock: this });
|
}, { oncePoll: this });
|
||||||
}
|
}
|
||||||
|
|
||||||
getBlock(blockHashOrBlockTag: BlockTag | string | Promise<BlockTag | string>): Promise<Block> {
|
getBlock(blockHashOrBlockTag: BlockTag | string | Promise<BlockTag | string>): Promise<Block> {
|
||||||
@ -865,7 +865,7 @@ export class BaseProvider extends Provider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return this._wrapTransaction(tx);
|
return this._wrapTransaction(tx);
|
||||||
}, { onceBlock: this });
|
}, { oncePoll: this });
|
||||||
}
|
}
|
||||||
|
|
||||||
async getTransactionReceipt(transactionHash: string | Promise<string>): Promise<TransactionReceipt> {
|
async getTransactionReceipt(transactionHash: string | Promise<string>): Promise<TransactionReceipt> {
|
||||||
@ -903,7 +903,7 @@ export class BaseProvider extends Provider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return receipt;
|
return receipt;
|
||||||
}, { onceBlock: this });
|
}, { oncePoll: this });
|
||||||
}
|
}
|
||||||
|
|
||||||
async getLogs(filter: Filter | FilterByBlockHash | Promise<Filter | FilterByBlockHash>): Promise<Array<Log>> {
|
async getLogs(filter: Filter | FilterByBlockHash | Promise<Filter | FilterByBlockHash>): Promise<Array<Log>> {
|
||||||
|
@ -108,6 +108,14 @@ export class WebSocketProvider extends JsonRpcProvider {
|
|||||||
console.warn("this should not happen");
|
console.warn("this should not happen");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// This Provider does not actually poll, but we want to trigger
|
||||||
|
// poll events for things that depend on them (like stalling for
|
||||||
|
// block and transaction lookups)
|
||||||
|
const fauxPoll = setInterval(() => {
|
||||||
|
this.emit("poll");
|
||||||
|
}, 1000);
|
||||||
|
if (fauxPoll.unref) { fauxPoll.unref(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
get pollingInterval(): number {
|
get pollingInterval(): number {
|
||||||
@ -180,7 +188,9 @@ export class WebSocketProvider extends JsonRpcProvider {
|
|||||||
switch (event.type) {
|
switch (event.type) {
|
||||||
case "block":
|
case "block":
|
||||||
this._subscribe("block", [ "newHeads" ], (result: any) => {
|
this._subscribe("block", [ "newHeads" ], (result: any) => {
|
||||||
this.emit("block", BigNumber.from(result.number).toNumber());
|
const blockNumber = BigNumber.from(result.number).toNumber();
|
||||||
|
this._emitted.block = blockNumber;
|
||||||
|
this.emit("block", blockNumber);
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -221,6 +231,9 @@ export class WebSocketProvider extends JsonRpcProvider {
|
|||||||
|
|
||||||
// Nothing is needed
|
// Nothing is needed
|
||||||
case "debug":
|
case "debug":
|
||||||
|
case "poll":
|
||||||
|
case "willPoll":
|
||||||
|
case "didPoll":
|
||||||
case "error":
|
case "error":
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user