decode_variable_value

Function decode_variable_value 

Source
pub fn decode_variable_value(
    user_defined_types: &HashMap<usize, UserDefinedTypeRef>,
    variable: &VariableRef,
    data: &[u8],
) -> Result<DynSolValue>
Expand description

Decode the variable value from the given ABI-encoded data according to the variable declaration.

This function takes raw ABI-encoded data and decodes it according to the variable’s type information from its declaration. It handles both primitive Solidity types (uint, address, bool, etc.) and user-defined types (structs, enums).

§Arguments

  • user_defined_types - Mapping of type IDs to user-defined type references for resolving custom types
  • variable - The variable reference containing the declaration and type information
  • data - The ABI-encoded variable value as raw bytes

§Returns

The decoded variable value as a DynSolValue that can be used in expression evaluation

§Errors

Returns an error if:

  • The variable declaration lacks type information
  • The type cannot be resolved from the declaration
  • The data cannot be ABI-decoded according to the resolved type

§Example

let decoded = decode_variable_value(&user_types, &variable_ref, &encoded_data)?;
match decoded {
    DynSolValue::Uint(val, _) => println!("Uint value: {}", val),
    DynSolValue::Address(addr) => println!("Address: {}", addr),
    _ => println!("Other type: {:?}", decoded),
}