diff --git a/src.ts/providers/provider.ts b/src.ts/providers/provider.ts index 72c29610e..c7f3b12c9 100644 --- a/src.ts/providers/provider.ts +++ b/src.ts/providers/provider.ts @@ -382,6 +382,25 @@ export class Block implements BlockParams, Iterable { }); } + /** + * Returns the complete transactions for blocks which + * prefetched them, by passing ``true`` to %%prefetchTxs%% + * into [[provider_getBlock]]. + */ + get transactionResponses(): Array { + const txs = this.#transactions.slice(); + + // Doesn't matter... + if (txs.length === 0) { return [ ]; } + + // Make sure we prefetched the transactions + assert(typeof(txs[0]) === "object", "transactions were not prefetched with block request", "UNSUPPORTED_OPERATION", { + operation: "transactionResponses()" + }); + + return >txs; + } + /** * Returns a JSON-friendly value. */ @@ -462,6 +481,20 @@ export class Block implements BlockParams, Iterable { } } + getTransactionResponse(indexOrHash: number | string): TransactionResponse { + const txs = this.transactionResponses; + if (typeof(indexOrHash) === "number") { + return txs[indexOrHash]; + } + + indexOrHash = indexOrHash.toLowerCase(); + for (const tx of txs) { + if (tx.hash === indexOrHash) { return tx; } + } + + throw new Error("no such tx"); + } + /** * Has this block been mined. * @@ -797,6 +830,7 @@ export interface MinedTransactionResponse extends TransactionResponse { date: Date; } +/* export type ReplacementDetectionSetup = { to: string; from: string; @@ -805,7 +839,7 @@ export type ReplacementDetectionSetup = { nonce: number; block: number; }; - +*/ export class TransactionResponse implements TransactionLike, TransactionResponseParams { readonly provider: Provider;