HostQuery

Trait HostQuery 

Source
pub trait HostQuery: Send + Sync {
    // Required methods
    fn deserialize_and_price(
        &self,
        arg_buf: &[u8],
        arg: &mut Box<dyn Any>,
    ) -> u64;
    fn execute(&self, arg: &Box<dyn Any>, arg_buf: &mut [u8]) -> u32;
}
Expand description

A query executable on the host.

The buffer containing the argument the contract used to call the query, together with the argument’s length, are passed as arguments to the function, and should be processed first. Once this is done, the implementor should emplace the return of the query in the same buffer, and return the length written.

Implementers of Fn(&mut [u8], u32) -> u32 can be used as a HostQuery, but the cost will be 0.

Required Methods§

Source

fn deserialize_and_price(&self, arg_buf: &[u8], arg: &mut Box<dyn Any>) -> u64

Deserialize the argument buffer and return the price of the query.

The buffer passed will be of the length of the argument the contract used to call the query.

Any information needed to perform the query after deserializing the argument should be stored in arg, and will be passed to execute, if there’s enough gas to execute the query.

Source

fn execute(&self, arg: &Box<dyn Any>, arg_buf: &mut [u8]) -> u32

Perform the query and return the length of the result written to the argument buffer.

The whole argument buffer is passed, together with any information stored in arg previously, during deserialize_and_price.

Implementors§

Source§

impl<F> HostQuery for F
where F: Send + Sync + Fn(&mut [u8], u32) -> u32,

An implementer of Fn(&mut [u8], u32) -> u32 can be used as a HostQuery, and the cost will be 0.