Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 7 additions & 7 deletions evm/src/executor/inspector/cheatcodes/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,19 +239,19 @@ fn value_to_token(value: &Value) -> Result<Token, Token> {
if let Some(boolean) = value.as_bool() {
Ok(Token::Bool(boolean))
} else if let Some(string) = value.as_str() {
// If it can decoded as an address, it's an address
if let Ok(addr) = H160::from_str(string) {
Ok(Token::Address(addr))
} else if let Some(val) = string.strip_prefix("0x") {
// If incornrect length, pad 0 at the beginning
if hex::decode(val).is_ok() {
if let Some(val) = string.strip_prefix("0x") {
// If it can decoded as an address, it's an address
if let Ok(addr) = H160::from_str(string) {
Ok(Token::Address(addr))
} else if hex::decode(val).is_ok() {
// if length == 32 bytes, then encode as Bytes32, else Bytes
Ok(if val.len() == 64 {
Token::FixedBytes(Vec::from_hex(val).unwrap())
} else {
Token::Bytes(Vec::from_hex(val).unwrap())
})
} else {
// If incornrect length, pad 0 at the beginning
let arr = format!("0{}", val);
Ok(Token::Bytes(Vec::from_hex(arr).unwrap()))
}
Expand All @@ -271,7 +271,7 @@ fn value_to_token(value: &Value) -> Result<Token, Token> {
object.values().map(|val| value_to_token(val).unwrap()).collect::<Vec<Token>>();
Ok(Token::Tuple(values))
} else if value.is_null() {
Ok(Token::FixedBytes(Vec::with_capacity(32)))
Ok(Token::FixedBytes(vec![0; 32]))
} else {
Err(Token::String("Could not decode field".to_string()))
}
Expand Down
Loading