1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#![cfg_attr(not(feature = "std"), no_std)]

extern crate alloc;

use alloc::vec::Vec;
use core::marker::PhantomData;
use fp_evm::{
    ExitError, ExitSucceed, Precompile as EvmPrecompile, PrecompileFailure, PrecompileHandle,
    PrecompileOutput, PrecompileResult,
};
use t3rn_primitives::threevm::Precompile;

// TODO: build this for the next phase of evm artifacts.
pub struct ThreeVmDispatch<T> {
    _marker: PhantomData<T>,
}

impl<T> EvmPrecompile for ThreeVmDispatch<T>
where
    T: pallet_evm::Config,
{
    fn execute(handle: &mut impl PrecompileHandle) -> PrecompileResult {
        let input = handle.input();
        let _target_gas = handle.gas_limit();
        let _context = handle.context();

        let mut output = Vec::new();
        T::ThreeVm::invoke_raw(&55_u8, input, &mut output); // TODO: dummy ptr for now

        if !output.is_empty() {
            Ok(PrecompileOutput {
                exit_status: ExitSucceed::Stopped,
                output,
            })
        } else {
            Err(PrecompileFailure::Error {
                exit_status: ExitError::Other("invalid output".into()),
            })
        }
    }
}