Skip to content

Commit

Permalink
docs: added info on transaction order within a block and commify migr…
Browse files Browse the repository at this point in the history
…ation info (#4343, #4352)
  • Loading branch information
ricmoo committed Sep 13, 2023
1 parent 77fcc7f commit bc6cfbf
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
24 changes: 24 additions & 0 deletions docs.wrm/migrating.wrm
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
10 changes: 7 additions & 3 deletions src.ts/providers/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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> {
Expand Down

0 comments on commit bc6cfbf

Please sign in to comment.