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

core: decode account from E3 encoded storage #2251

Merged
merged 1 commit into from
Aug 21, 2024

Conversation

canepat
Copy link
Member

@canepat canepat commented Aug 20, 2024

No description provided.

@canepat canepat added the erigon3 Erigon3 feature label Aug 20, 2024
@canepat canepat marked this pull request as ready for review August 20, 2024 12:47
Comment on lines +157 to +169
for (int i{0}; i < 4; ++i) {
uint8_t len = encoded_payload[pos++];
if (len == 0) {
if (encoded_payload.length() == pos && i < 3) {
return tl::unexpected{DecodingError::kUnexpectedLength};
}
continue;
}
if (encoded_payload.length() < pos + len) {
return tl::unexpected{DecodingError::kInputTooShort};
}
const auto encoded_value{encoded_payload.substr(pos, len)};
switch (i) {
Copy link
Contributor

Choose a reason for hiding this comment

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

this loop with a switch is a smart hack to structure the code
it took me a while to figure it out

a more basic way would be to extract this preambule into a helper function or a local lambda,
and then call it before each decoding attempt

Copy link
Member Author

Choose a reason for hiding this comment

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

I did it this way for similarity with the code already present in Account::from_encoded_storage

@canepat canepat merged commit 9aace13 into master Aug 21, 2024
5 checks passed
@canepat canepat deleted the core_account_from_encoded_storage_v3 branch August 21, 2024 08:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
erigon3 Erigon3 feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants