/// Reads a storage entry from the VM's storage into Wasm memory
Reads a storage entry from the VM's storage into Wasm memory
Reads a storage entry from the VM ' s storage into Wasm memory
pub fn do_read<S: Storage, Q: Querier>(ctx: &mut Ctx, key_ptr: u32) -> VmResult<u32> {
    let key = read_region(ctx, key_ptr, MAX_LENGTH_DB_KEY)?;
    // `Ok(expr?)` used to convert the error variant.
    let (value, used_gas): (Option<Vec<u8>>, u64) =
        with_storage_from_context::<S, Q, _, _>(ctx, |store| Ok(store.get(&key)?))?;
    try_consume_gas::<S, Q>(ctx, used_gas)?;
    let out_data = match value {
        Some(data) => data,
        None => return Ok(0),
    };
    let out_ptr = with_func_from_context::<S, Q, u32, u32, _, _>(ctx, "allocate", |allocate| {
        let out_size = to_u32(out_data.len())?;
        let ptr = allocate.call(out_size)?;
        if ptr == 0 {
            return Err(CommunicationError::zero_address().into());
        }
        Ok(ptr)
    })?;
    write_region(ctx, out_ptr, &out_data)?;
    Ok(out_ptr)
}
pub fn do_read < S : Storage , Q : Querier > ( ctx : & mut Ctx , key_ptr : u32 ) -> VmResult < u32 > { let key = read_region ( ctx , key_ptr , MAX_LENGTH_DB_KEY ) ? ; // `Ok(expr?)` used to convert the error variant. let ( value , used_gas ) : ( Option < Vec < u8 > > , u64 ) = with_storage_from_context :: < S , Q , _ , _ > ( ctx , | store | Ok ( store . get ( & key ) ? ) ) ? ; try_consume_gas :: < S , Q > ( ctx , used_gas ) ? ; let out_data = match value { Some ( data ) => data , None => return Ok ( 0 ) , } ; let out_ptr = with_func_from_context :: < S , Q , u32 , u32 , _ , _ > ( ctx , " " , | allocate | { let out_size = to_u32 ( out_data . len ( ) ) ? ; let ptr = allocate . call ( out_size ) ? ; if ptr == 0 { return Err ( CommunicationError :: zero_address ( ) . into ( ) ) ; } Ok ( ptr ) } ) ? ; write_region ( ctx , out_ptr , & out_data ) ? ; Ok ( out_ptr ) }
Reads a storage entry from the VM's storage into Wasm memory
Reads a storage entry from the VM ' s storage into Wasm memory
ctx
&mut Ctx
key_ptr
u32