Fixed replacement transaction detection for JsonRpcSigner (#1658).

This commit is contained in:
Richard Moore 2021-06-10 18:22:02 -04:00
parent 376cf3cdbf
commit ee82e86ccc
No known key found for this signature in database
GPG Key ID: 665176BE8E9DC651

@ -207,18 +207,26 @@ export class JsonRpcSigner extends Signer implements TypedDataSigner {
}); });
} }
sendTransaction(transaction: Deferrable<TransactionRequest>): Promise<TransactionResponse> { async sendTransaction(transaction: Deferrable<TransactionRequest>): Promise<TransactionResponse> {
return this.sendUncheckedTransaction(transaction).then((hash) => { // This cannot be mined any earlier than any recent block
return poll(() => { const blockNumber = await this.provider._getInternalBlockNumber(100 + 2 * this.provider.pollingInterval);
return this.provider.getTransaction(hash).then((tx: TransactionResponse) => {
// Send the transaction
const hash = await this.sendUncheckedTransaction(transaction);
try {
// Unfortunately, JSON-RPC only provides and opaque transaction hash
// for a response, and we need the actual transaction, so we poll
// for it; it should show up very quickly
return await poll(async () => {
const tx = await this.provider.getTransaction(hash);
if (tx === null) { return undefined; } if (tx === null) { return undefined; }
return this.provider._wrapTransaction(tx, hash); return this.provider._wrapTransaction(tx, hash, blockNumber);
}); }, { oncePoll: this.provider });
}, { oncePoll: this.provider }).catch((error: Error) => { } catch (error) {
(<any>error).transactionHash = hash; (<any>error).transactionHash = hash;
throw error; throw error;
}); }
});
} }
async signMessage(message: Bytes | string): Promise<string> { async signMessage(message: Bytes | string): Promise<string> {