Fixed waitForTransaction and removeListener (#410).

This commit is contained in:
Richard Moore 2019-02-12 00:54:32 -05:00
parent e4a2f8ac6c
commit 72edcd054f
No known key found for this signature in database
GPG Key ID: 525F70A6FCABC295

View File

@ -776,15 +776,19 @@ export class BaseProvider extends Provider {
waitForTransaction(transactionHash: string, confirmations?: number): Promise<TransactionReceipt> { waitForTransaction(transactionHash: string, confirmations?: number): Promise<TransactionReceipt> {
if (confirmations == null) { confirmations = 1; } if (confirmations == null) { confirmations = 1; }
return poll(() => {
return this.getTransactionReceipt(transactionHash).then((receipt) => { if (confirmations === 0) {
if (confirmations === 0) { return receipt; } return this.getTransactionReceipt(transactionHash);
if (receipt == null || receipt.confirmations < confirmations) { }
return undefined;
} return new Promise((resolve) => {
return receipt; let handler = (receipt: TransactionReceipt) => {
}); if (receipt.confirmations < confirmations) { return; }
}, { onceBlock: this }); this.removeListener(transactionHash, handler);
resolve(receipt);
}
this.on(transactionHash, handler);
});
} }
getBlockNumber(): Promise<number> { getBlockNumber(): Promise<number> {
@ -1306,13 +1310,18 @@ export class BaseProvider extends Provider {
}); });
} }
removeAllListeners(eventName: EventType): Provider { removeAllListeners(eventName?: EventType): Provider {
let eventTag = getEventTag(eventName); if (eventName == null) {
this._events = this._events.filter((event) => { this._events = [ ];
return (event.tag !== eventTag); this._stopPending();
}); } else {
let eventTag = getEventTag(eventName);
this._events = this._events.filter((event) => {
return (event.tag !== eventTag);
});
if (eventName === 'pending') { this._stopPending(); }
}
if (eventName === 'pending') { this._stopPending(); }
if (this._events.length === 0) { this.polling = false; } if (this._events.length === 0) { this.polling = false; }
return this; return this;
@ -1323,9 +1332,9 @@ export class BaseProvider extends Provider {
let eventTag = getEventTag(eventName); let eventTag = getEventTag(eventName);
this._events = this._events.filter((event) => { this._events = this._events.filter((event) => {
if (event.tag !== eventTag) { return true; } if (event.tag !== eventTag || event.listener != listener) { return true; }
if (found) { return true; } if (found) { return true; }
found = false; found = true;
return false; return false;
}); });