Skip to content

Commit

Permalink
account tool bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-marinica committed Oct 25, 2024
1 parent 536ecb4 commit 2cd0255
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
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()
}

0 comments on commit 2cd0255

Please sign in to comment.