Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): get block by number #112

Merged
merged 8 commits into from
Jan 10, 2024

Conversation

czar0
Copy link
Contributor

@czar0 czar0 commented Dec 29, 2023

Description

Initial implementation of the eth_getBlockByNumber JSON-RPC call for ethkit CLI.

Depends on #111

Key features

  • Support for block header
  • Support for full block
  • Support for JSON formatted result
  • Support for single-field results (case-insensitive)

TODOs & known issues

  • The totalDifficulty field has to be implemented
  • Currently, the withdrawals field returns an empty list when a non-empty result is expected - fixed in 4663b82
  • Tags - earliest, latest, pending, finalized, safe - are currently not supported
  • extraData is printed as a string encoded in base64 (expected: hex-encoded) - fixed in e3cf353
  • The order of printed fields is not maintained at each iteration. This is a known behaviour for looping through map structures. If ordering is required (for deterministic results), this can be easily fixed

Examples

Retrieve the block header for block 18855325 on mainnet network via https://nodes.sequence.app/mainnet RPC endpoint and print the result in console formatted in columns with the same width:

ethkit block 18855325 -r https://nodes.sequence.app/mainnet

Retrieve the timestamp for block 18855325 on mainnet network via https://nodes.sequence.app/mainnet RPC endpoint and print the result in console as a single-value field:

ethkit block 18855325 -r https://nodes.sequence.app/mainnet -f timestamp

Retrieve the full block information for block 18855325 on mainnet network via https://nodes.sequence.app/mainnet RPC endpoint and print the result in console formatted in columns with the same width:

ethkit block 18855325 -r https://nodes.sequence.app/mainnet --full

Retrieve the full block information for block 18855325 on mainnet network via https://nodes.sequence.app/mainnet RPC endpoint and print the result in console as a prettified JSON:

ethkit block 18855325 -r https://nodes.sequence.app/mainnet --full --json

- Columnize() is using text/tabwriter standard library to print fields and vertically aligned in columns, split by the `|` delimiter character.
- GetValueByJSONTag() recursively search for a string key within the JSON tags of a given object to return the value associated with it. This metho
d is used with command flags like `--field` where a single return value is expected.
- The format for the printing - minwidth, tabwidth, padding, padchar - is configurable.
- FromStruct() converts a struct into a Printable using, when available, JSON field names as keys.
- customFormat() is an utility function to format numbers and avoid scientific notation and ensure they are printed as integers.
- Support for block header
- Support for full block
- Support for JSON formatted result
- Support for single-field result
@pkieltyka pkieltyka merged commit 3f76064 into 0xsequence:master Jan 10, 2024
6 checks passed
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.

2 participants