use oasis_contract_sdk_types::{message::Reply, ExecutionOk};
use oasis_runtime_sdk::{
context::Context,
types::{address::Address, token, transaction::CallFormat},
};
use super::{types, Error, Parameters};
pub mod gas;
pub mod oasis;
pub trait Abi<C: Context> {
fn validate(&self, module: &mut walrus::Module, params: &Parameters) -> Result<Info, Error>;
fn link(
&self,
instance: &mut wasm3::Instance<'_, '_, ExecutionContext<'_, C>>,
) -> Result<(), Error>;
fn set_gas_limit(
&self,
instance: &mut wasm3::Instance<'_, '_, ExecutionContext<'_, C>>,
gas_limit: u64,
) -> Result<(), Error>;
fn instantiate<'ctx>(
&self,
ctx: &mut ExecutionContext<'ctx, C>,
instance: &wasm3::Instance<'_, '_, ExecutionContext<'ctx, C>>,
request: &[u8],
deposited_tokens: &[token::BaseUnits],
) -> ExecutionResult;
fn call<'ctx>(
&self,
ctx: &mut ExecutionContext<'ctx, C>,
instance: &wasm3::Instance<'_, '_, ExecutionContext<'ctx, C>>,
request: &[u8],
deposited_tokens: &[token::BaseUnits],
) -> ExecutionResult;
fn handle_reply<'ctx>(
&self,
ctx: &mut ExecutionContext<'ctx, C>,
instance: &wasm3::Instance<'_, '_, ExecutionContext<'ctx, C>>,
reply: Reply,
) -> ExecutionResult;
fn pre_upgrade<'ctx>(
&self,
ctx: &mut ExecutionContext<'ctx, C>,
instance: &wasm3::Instance<'_, '_, ExecutionContext<'ctx, C>>,
request: &[u8],
deposited_tokens: &[token::BaseUnits],
) -> ExecutionResult;
fn post_upgrade<'ctx>(
&self,
ctx: &mut ExecutionContext<'ctx, C>,
instance: &wasm3::Instance<'_, '_, ExecutionContext<'ctx, C>>,
request: &[u8],
deposited_tokens: &[token::BaseUnits],
) -> ExecutionResult;
fn query<'ctx>(
&self,
ctx: &mut ExecutionContext<'ctx, C>,
instance: &wasm3::Instance<'_, '_, ExecutionContext<'ctx, C>>,
request: &[u8],
) -> ExecutionResult;
}
pub struct Info {
pub abi_sv: u32,
}
pub struct ExecutionContext<'ctx, C: Context> {
pub tx_context: &'ctx C,
pub params: &'ctx Parameters,
pub code_info: &'ctx types::Code,
pub instance_info: &'ctx types::Instance,
pub gas_limit: u64,
pub caller_address: Address,
pub read_only: bool,
pub call_format: CallFormat,
pub aborted: Option<Error>,
}
impl<'ctx, C: Context> ExecutionContext<'ctx, C> {
#[allow(clippy::too_many_arguments)]
pub fn new(
params: &'ctx Parameters,
code_info: &'ctx types::Code,
instance_info: &'ctx types::Instance,
gas_limit: u64,
caller_address: Address,
read_only: bool,
call_format: CallFormat,
tx_context: &'ctx C,
) -> Self {
Self {
tx_context,
params,
code_info,
instance_info,
gas_limit,
caller_address,
read_only,
call_format,
aborted: None,
}
}
}
#[must_use]
pub struct ExecutionResult {
pub inner: Result<ExecutionOk, Error>,
pub gas_used: u64,
}