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

View File

@ -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) => {
if (tx === null) { return undefined; } // Send the transaction
return this.provider._wrapTransaction(tx, hash); const hash = await this.sendUncheckedTransaction(transaction);
});
}, { oncePoll: this.provider }).catch((error: Error) => { try {
(<any>error).transactionHash = hash; // Unfortunately, JSON-RPC only provides and opaque transaction hash
throw error; // 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; }
return this.provider._wrapTransaction(tx, hash, blockNumber);
}, { oncePoll: this.provider });
} catch (error) {
(<any>error).transactionHash = hash;
throw error;
}
} }
async signMessage(message: Bytes | string): Promise<string> { async signMessage(message: Bytes | string): Promise<string> {