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(serde): StorageKeyKind #1597

Merged
merged 5 commits into from
Nov 6, 2024
Merged

feat(serde): StorageKeyKind #1597

merged 5 commits into from
Nov 6, 2024

Conversation

yash-atreya
Copy link
Member

@yash-atreya yash-atreya commented Oct 31, 2024

Motivation

Closes #1553

Solution

Introduce the enum StorageKeyKind with variants Hash(B256) and Number(U256). Used in JsonStorageKey.
Tries to deserialize a string into the Hash variant first.

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

#[serde(from = "U256", into = "String")]
pub struct JsonStorageKey(pub B256);
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize)]
#[serde(into = "String")]
Copy link
Member

Choose a reason for hiding this comment

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

@Rjected isn't all of this now just serde(untagged) ?

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah I think so

crates/serde/src/storage.rs Outdated Show resolved Hide resolved
Comment on lines 12 to 13
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub enum StorageKeyKind {
Copy link
Member

Choose a reason for hiding this comment

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

I think this is now just #[serde(untagged)] then we no longer need any serialization on JsonStorageKey

Copy link
Member

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

I simplified this and converted the jsonstoragekey type to an enum instead

@mattsse mattsse merged commit 23357f2 into main Nov 6, 2024
26 checks passed
@mattsse mattsse deleted the yash/storage-key-enum branch November 6, 2024 08:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

[Feature] Support truncated key for JsonStorageKey
3 participants