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: add dynamic array encoding for encodeData #394

Merged
merged 9 commits into from
Mar 22, 2024

Conversation

fhildeb
Copy link
Collaborator

@fhildeb fhildeb commented Mar 20, 2024

What kind of change does this PR introduce?

Feature: Dynamically encode ERC725 storage keys of type Array.

What is the current behavior?

The library only allows users to define the full array they want to encode and set to a contract. For updates, developers must read through all existing elements and pay the gas for re-setting elements in the list, even if only a few of them are actually updated. This is highly impractical.

What is the new behavior?

Within the encodeData(...) function, developers can define a startingIndex and an arrayLenght parameter to dynamically adjust the output, which can be used for more gradient storage updates. Both parameters are optional. If not provided, the encoding falls back to the default behavior as before, starting from index 0 and using the length of the provided elements in the array.

@codecov-commenter
Copy link

codecov-commenter commented Mar 20, 2024

Codecov Report

Attention: Patch coverage is 84.61538% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 82.05%. Comparing base (9640d9f) to head (0fea642).
Report is 139 commits behind head on develop.

Files Patch % Lines
src/lib/utils.ts 84.61% 1 Missing and 1 partial ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #394      +/-   ##
===========================================
- Coverage    83.71%   82.05%   -1.66%     
===========================================
  Files           18       19       +1     
  Lines         1130     1332     +202     
  Branches       255      313      +58     
===========================================
+ Hits           946     1093     +147     
- Misses          98      130      +32     
- Partials        86      109      +23     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@Hugoo Hugoo left a comment

Choose a reason for hiding this comment

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

Can you also update the function JSDoc at lines 231, 232. It is missing the 2 new inputs.

Can you update the docs and add examples on this new feature?

Nice tests

src/lib/utils.ts Outdated Show resolved Hide resolved
src/lib/utils.ts Outdated Show resolved Hide resolved
@Hugoo
Copy link
Contributor

Hugoo commented Mar 20, 2024

Here this page needs to be updated:

https://docs.lukso.tech/tools/erc725js/classes/ERC725#encodedata

Source: https://github.com/lukso-network/docs/blob/main/docs/tools/erc725js/classes/ERC725.md#encodedata

Btw, I see we have 2 infos inside of each other, could you also fix that in this PR?

image

@Hugoo Hugoo changed the title Feat: Add dynamic array encoding feat: add dynamic array encoding for encodeData Mar 20, 2024
src/lib/utils.test.ts Outdated Show resolved Hide resolved
docs/classes/ERC725.md Outdated Show resolved Hide resolved
@fhildeb
Copy link
Collaborator Author

fhildeb commented Mar 21, 2024

Thanks for the review and feedback 🙏🏻

I renamed arrayLength to totalArrayLength for better clarification. I also added a new info box and warning regarding the usage of these elements.

I think it's important to eliminate all questions, as this will be the second "big update" for dynamic user inputs, besides the already existing dynamicKeyParts... which also has some extended explanation in the docs. 👍🏻

Copy link
Collaborator

@CJ42 CJ42 left a comment

Choose a reason for hiding this comment

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

LGTM

src/index.test.ts Outdated Show resolved Hide resolved
src/lib/utils.ts Outdated Show resolved Hide resolved
src/lib/utils.ts Outdated Show resolved Hide resolved
@fhildeb fhildeb force-pushed the feat/dynamic-array-encoding branch from 6d8eb41 to 7270593 Compare March 21, 2024 18:01
@fhildeb fhildeb added the enhancement New feature or request label Mar 21, 2024
@fhildeb
Copy link
Collaborator Author

fhildeb commented Mar 22, 2024

Alright, I figured out how to adjust the error messages. Had to adjust the tests to also include these brackets, as they were looking for a close match.

@fhildeb fhildeb merged commit 5fca5be into ERC725Alliance:develop Mar 22, 2024
2 checks passed
@fhildeb fhildeb deleted the feat/dynamic-array-encoding branch March 22, 2024 10:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants