Add confirmations to TransactionResponse (#4094).
This commit is contained in:
parent
3c1bad2fb7
commit
bb8685b112
@ -1345,6 +1345,26 @@ export class TransactionResponse implements TransactionLike<string>, Transaction
|
||||
return this.provider.getTransaction(this.hash);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve to the number of confirmations this transaction has.
|
||||
*/
|
||||
async confirmations(): Promise<number> {
|
||||
if (this.blockNumber == null) {
|
||||
const { tx, blockNumber } = await resolveProperties({
|
||||
tx: this.getTransaction(),
|
||||
blockNumber: this.provider.getBlockNumber()
|
||||
});
|
||||
|
||||
// Not mined yet...
|
||||
if (tx == null || tx.blockNumber == null) { return 0; }
|
||||
|
||||
return blockNumber - tx.blockNumber + 1;
|
||||
}
|
||||
|
||||
const blockNumber = await this.provider.getBlockNumber();
|
||||
return blockNumber - this.blockNumber + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves once this transaction has been mined and has
|
||||
* %%confirms%% blocks including it (default: ``1``) with an
|
||||
|
Loading…
Reference in New Issue
Block a user