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

extractAsBytesFromArray method for JSON precompile #2054

Merged
merged 6 commits into from
Jan 30, 2025

Conversation

dssei
Copy link
Contributor

@dssei dssei commented Jan 25, 2025

Describe your changes and provide context

extractAsBytesFromArray method for JSON precompile to allow elements extraction from JSON arrays.

This additional method is needed for cases like

{
  "data": {
    "exchange_rates": [
      [
        1727762390,
        "1.033207463698531844"
      ],
      [
        1727545459,
        "1.032887092691178063"
      ]
    ],
    "apr": "0.000101145698240442"
  }
}

We do have methods allowing extracting data by key or array(list) by key, but no way to extract element from array.
E.g. data.exchange_rates[0][0]

Testing performed to validate your change

  • unit test

Copy link

codecov bot commented Jan 25, 2025

Codecov Report

Attention: Patch coverage is 81.81818% with 6 lines in your changes missing coverage. Please review.

Project coverage is 61.30%. Comparing base (d50f236) to head (b7e6152).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
precompiles/json/json.go 81.81% 4 Missing and 2 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2054      +/-   ##
==========================================
- Coverage   61.50%   61.30%   -0.20%     
==========================================
  Files         264      264              
  Lines       24593    24626      +33     
==========================================
- Hits        15125    15098      -27     
- Misses       8335     8395      +60     
  Partials     1133     1133              
Files with missing lines Coverage Δ
precompiles/json/json.go 57.77% <81.81%> (+7.77%) ⬆️

... and 2 files with indirect coverage changes

Copy link
Contributor

@jewei1997 jewei1997 left a comment

Choose a reason for hiding this comment

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

I think you might need migration handlers to properly roll this out

@dssei
Copy link
Contributor Author

dssei commented Jan 27, 2025

I think you might need migration handlers to properly roll this out

I see. Thought migration handlers are for modules related changes. Looked into similar PRs but have not seen any examples of handlers changes. Do you have one by any chance?

@jewei1997
Copy link
Contributor

yeah I think you can look at this PR as an example. Basically you need migration handlers to update the precompile contracts #2043

@dssei dssei merged commit 3ca49df into main Jan 30, 2025
49 checks passed
@dssei dssei deleted the json_precompile_array_method branch January 30, 2025 18:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants