use crate::errors::TonCoreResult;
use crate::traits::state_provider::ContractState;
use crate::types::{TonAddress, TxLTHash};
use async_trait::async_trait;
use std::sync::Arc;
use std::time::Duration;
#[derive(Clone, Debug)]
#[non_exhaustive]
pub enum EmulatorContractState {
Address {
address: TonAddress,
tx_id: Option<TxLTHash>,
},
Custom(Arc<ContractState>),
}
#[derive(Clone, Debug)]
#[non_exhaustive]
pub struct EmulatorGetMethodRequest {
pub contract_state: EmulatorContractState,
pub method_id: i32,
pub stack_boc: Arc<Vec<u8>>,
}
impl EmulatorGetMethodRequest {
pub fn new_with_address(
address: TonAddress,
tx_id: Option<TxLTHash>,
method_id: i32,
stack_boc: Arc<Vec<u8>>,
) -> Self {
Self {
contract_state: EmulatorContractState::Address { address, tx_id },
method_id,
stack_boc,
}
}
pub fn new_with_state(state: Arc<ContractState>, method_id: i32, stack_boc: Arc<Vec<u8>>) -> Self {
Self {
contract_state: EmulatorContractState::Custom(state),
method_id,
stack_boc,
}
}
}
#[derive(Clone, Debug)]
#[non_exhaustive]
pub struct EmulatorGetMethodSuccess {
pub vm_exit_code: i32,
pub stack_boc: Vec<u8>,
pub vm_log: Option<String>,
pub gas_used: Option<i32>,
pub raw_response: Option<String>,
}
impl EmulatorGetMethodSuccess {
pub fn new(vm_exit_code: i32, stack_boc: Vec<u8>) -> Self {
Self {
vm_exit_code,
stack_boc,
vm_log: None,
gas_used: None,
raw_response: None,
}
}
pub fn with_diagnostic(mut self, vm_log: Option<String>, gas_used: i32, raw_response: String) -> Self {
self.vm_log = vm_log;
self.gas_used = Some(gas_used);
self.raw_response = Some(raw_response);
self
}
}
#[async_trait]
pub trait EmulationProvider: Send + Sync + 'static {
async fn emulate_get_method(
&self,
request: EmulatorGetMethodRequest,
timeout: Option<Duration>,
) -> TonCoreResult<EmulatorGetMethodSuccess>;
fn requires_resolved_state(&self) -> bool {
false
}
}