docs: added info on transaction order within a block and commify migration info (#4343, #4352)

This commit is contained in:
Richard Moore 2023-09-12 21:18:39 -04:00
parent 77fcc7fdab
commit bc6cfbf2cc
2 changed files with 31 additions and 3 deletions

@ -363,6 +363,30 @@ _code: property manipulation @lang<script>
// v6
ethers.defineProperties(obj, { name: value });
_code: commify @lang<script>
// v5
ethers.utils.commify("1234.5")
// v6; we removed some of these local-specific utilities,
// however the functionality can be easily replicated
// and adjusted depending on your desired output format,
// for which everyone wanted their own tweaks anyways.
//
// However, to mimic v5 functionality, this can be used:
function commify(value) {
const match = value.match(/^(-?)([0-9]*)(\.?)([0-9]*)$/);
if (!match || (!match[2] && !match[4])) {
throw new Error(`bad formatted number: ${ JSON.stringify(value) }`);
}
const neg = match[1];
const whole = BigInt(match[2] || 0).toLocaleString("en-us");
const frac = match[4] ? match[4].match(/^(.*?)0*$/)[1]: "0";
return `${ neg }${ whole }.${ frac }`;
}
commify("1234.5");
_subsection: Removed Classes and functions @<migrate-missing>

@ -526,7 +526,8 @@ export class Block implements BlockParams, Iterable<string> {
}
/**
* Returns the list of transaction hashes.
* Returns the list of transaction hashes, in the order
* they were executed within the block.
*/
get transactions(): ReadonlyArray<string> {
return this.#transactions.map((tx) => {
@ -536,8 +537,11 @@ export class Block implements BlockParams, Iterable<string> {
}
/**
* Returns the complete transactions for blocks which
* prefetched them, by passing ``true`` to %%prefetchTxs%%
* Returns the complete transactions, in the order they
* were executed within the block.
*
* This is only available for blocks which prefetched
* transactions, by passing ``true`` to %%prefetchTxs%%
* into [[Provider-getBlock]].
*/
get prefetchedTransactions(): Array<TransactionResponse> {