Skip to content

feat: add initial chain formatters - #5

Merged
jxom merged 10 commits into
mainfrom
jxom/chain-formatters
Dec 15, 2022
Merged

feat: add initial chain formatters#5
jxom merged 10 commits into
mainfrom
jxom/chain-formatters

Conversation

@jxom

@jxom jxom commented Dec 14, 2022

Copy link
Copy Markdown
Member

Adding support for a formatters attribute on the Chain type. Useful for non-Ethereum chains that have different block, transaction, etc shapes.

Example:

export const celo = defineChain({
  id: 42220,
  name: 'Celo',
  network: 'celo',
  nativeCurrency: { name: 'Celo', symbol: 'CELO', decimals: 18 },
  rpcUrls: {
    default: { http: ['https://rpc.ankr.com/celo'] },
  },
  formatters: {
    block: defineBlock({
      exclude: ['difficulty', 'gasLimit', 'mixHash', 'nonce', 'uncles'],
      include: (block) => ({
        randomness: block.randomness as { committed: Data; revealed: Data },
      }),
    }),
    transaction: defineTransaction({
      include: (transaction) => ({
        feeCurrency: transaction.feeCurrency as Address | null,
        gatewayFee: transaction.gatewayFee
          ? BigInt(transaction.gatewayFee as Quantity)
          : null,
        gatewayFeeRecipient: transaction.gatewayFeeRecipient as Address | null,
      }),
    }),
    transactionRequest: defineTransactionRequest({
      include: (transactionRequest) => ({
        feeCurrency: transactionRequest.feeCurrency as Address | undefined,
        gatewayFee: transactionRequest.gatewayFee as Quantity | undefined,
        gatewayFeeRecipient: transactionRequest.gatewayFeeRecipient as
          | Address
          | undefined,
      }),
    }),
  },
})

@changeset-bot

changeset-bot Bot commented Dec 14, 2022

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 10dfc19

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel

vercel Bot commented Dec 14, 2022

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
viem-benchmark ✅ Ready (Inspect) Visit Preview Dec 15, 2022 at 4:23AM (UTC)
viem-playground ✅ Ready (Inspect) Visit Preview Dec 15, 2022 at 4:23AM (UTC)

@codecov

codecov Bot commented Dec 14, 2022

Copy link
Copy Markdown

Codecov Report

Merging #5 (10dfc19) into main (fe30d27) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##              main        #5    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files           57        57            
  Lines         2188      2372   +184     
  Branches       209       260    +51     
==========================================
+ Hits          2188      2372   +184     
Impacted Files Coverage Δ
packages/core/src/actions/block/fetchBlock.ts 100.00% <100.00%> (ø)
packages/core/src/actions/block/watchBlocks.ts 100.00% <100.00%> (ø)
...s/core/src/actions/transaction/fetchTransaction.ts 100.00% <100.00%> (ø)
...es/core/src/actions/transaction/sendTransaction.ts 100.00% <100.00%> (ø)
packages/core/src/chains.ts 100.00% <100.00%> (ø)
packages/core/src/clients/createClient.ts 100.00% <100.00%> (ø)
...ges/core/src/clients/transports/createTransport.ts 100.00% <100.00%> (ø)
packages/core/src/clients/transports/http.ts 100.00% <100.00%> (ø)
packages/core/src/clients/transports/webSocket.ts 100.00% <100.00%> (ø)
packages/core/src/utils/formatters/block.ts 100.00% <100.00%> (ø)
... and 5 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant