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

account tool bugfix #1832

Merged
merged 4 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ pub struct BytesKey {
pub original: String,
}

impl BytesKey {
pub fn from_hex(hex_value: &str) -> Self {
Self {
value: hex::decode(hex_value).expect("could not decode hex value"),
original: format!("0x{hex_value}"),
}
}
}

impl From<Vec<u8>> for BytesKey {
fn from(v: Vec<u8>) -> Self {
BytesKey {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ impl BytesValue {
original: ValueSubTree::Str(String::default()),
}
}

pub fn from_hex(hex_value: &str) -> Self {
Self {
value: hex::decode(hex_value).expect("could not decode hex value"),
original: ValueSubTree::Str(format!("0x{hex_value}")),
}
}
}

impl InterpretableFrom<ValueSubTree> for BytesValue {
Expand Down
4 changes: 2 additions & 2 deletions framework/snippets-base/src/account_tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ fn set_account(
let mut account_state = Account::new()
.nonce(account.nonce)
.balance(account.balance.as_str())
.code(account.code);
.code(BytesValue::from_hex(&account.code));
account_state.username = Some(format!("str:{}", account.username.as_str()).into());
account_state.storage = convert_storage(account_storage);

Expand All @@ -112,6 +112,6 @@ fn convert_storage(account_storage: HashMap<String, String>) -> BTreeMap<BytesKe
account_storage
.into_iter()
.filter(|(k, _)| !k.starts_with("454c524f4e44"))
.map(|(k, v)| (BytesKey::from(k.as_str()), BytesValue::from(v)))
.map(|(k, v)| (BytesKey::from_hex(&k), BytesValue::from_hex(&v)))
.collect()
}
Loading