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

all: Fix Typing and JSON Conversion #207

Merged
merged 18 commits into from
Jul 18, 2023

Conversation

marioevz
Copy link
Member

@marioevz marioevz commented Jul 15, 2023

Changes Included

  • Homogenizes the typing of all fields in common/types.py, with the goal of making JSON conversion more streamlined:
    • Every field in each type now has JSON metadata that instructs the JSON encoder how to convert the type before inserting it into the output, with the following possible types:
      • Number: int, str or bytes that converts into a string when inserted into the JSON output
      • HexNumber: int, str or bytes that converts into a hex string when inserted into the JSON output
      • ZeroPaddedHexNumber: int, str or bytes that converts into a zero padded hex string when inserted into the JSON output, where zeroes are added to make the string of an even length.
      • Bytes: str or bytes that converts into an hex representation of the bytes described by the input (e.g. in tx data, extraData in the block header)
      • FixedSizeBytes: base class that is used to represent bytes of a fixed length (e.g. addresses, hashes, or header nonces)
      • Address: Fixed size bytes of length 20
      • Hash: Fixed size bytes of length 32
      • Bloom: Fixed size bytes of length 256
      • HeaderNonce: Fixed size bytes of length 8
    • common/json.py contains all JSON encoder logic.
    • Appropriate tests have been added to verify that the output of the new JSON encoding logic matches the previous output
  • Code base class and derivatives do no longer contain assemble method, and now implement SupportsBytes and Sized types.
  • Most methods in common/conversions.py have been removed, in favor of the standardized JSON encoder routines.
  • Adds Alloc type, which is a Mapping subclass that automatically converts all keys to appropriate address strings, while accepting strings, integers or bytes as key inputs, which would allow us to remove to_address usage across most tests.

@marioevz marioevz marked this pull request as ready for review July 17, 2023 20:07
@marioevz marioevz mentioned this pull request Jul 18, 2023
Copy link
Member

@danceratopz danceratopz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a few commits after comparing fixture output.

This really adds consistency to our json formatting! Thanks for this!

@marioevz marioevz merged commit cb4dd7d into ethereum:main Jul 18, 2023
3 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