Skip to main content

fluentbase_types/
native_api.rs

1use crate::{BytecodeOrHash, ExitCode};
2use alloc::borrow::Cow;
3
4/// A trait for providing shared API functionality.
5#[rustfmt::skip]
6pub trait NativeAPI {
7    /// Low-level function that terminates the execution of the program and exits with the specified
8    /// exit code.
9    fn exit(&self, exit_code: ExitCode) -> !;
10    fn state(&self) -> u32;
11    fn read(&self, target: &mut [u8], offset: u32);
12    /// Returns the size of the input data provided to the runtime environment.
13    fn input_size(&self) -> u32;
14    fn write(&self, value: &[u8]);
15    fn output_size(&self) -> u32;
16    fn read_output(&self, target: &mut [u8], offset: u32);
17    /// Executes a nested call with specified bytecode poseidon hash.
18    fn exec(
19        &self,
20        code_hash: BytecodeOrHash,
21        input: Cow<'_, [u8]>,
22        fuel_limit: Option<u64>,
23        state: u32,
24    ) -> (u64, i64, i32);
25    /// Resumes the execution of a previously suspended function call.
26    fn resume(
27        &self,
28        call_id: u32,
29        return_data: &[u8],
30        exit_code: i32,
31        fuel_consumed: u64,
32        fuel_refunded: i64,
33    ) -> (u64, i64, i32);
34    fn forward_output(&self, offset: u32, len: u32);
35    fn fuel(&self) -> u64;
36    fn debug_log(message: &str);
37    /// Charges specified amount of fuel.
38    /// In contrast to `_charge_fuel_manually`, can be called from untrusted code since it can only
39    /// charge fuel.
40    fn charge_fuel(&self, fuel_consumed: u64);
41    fn enter_unconstrained(&self);
42    fn exit_unconstrained(&self);
43    fn write_fd(&self, fd: u32, slice: &[u8]);
44}