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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
use crate::scope::*;
use evm_state::ExitError;
use hex::FromHexError;
use solana_sdk::instruction::InstructionError;

use snafu::Snafu;
#[derive(Debug, Snafu)]
#[snafu(visibility = "pub(crate)")]
pub enum PrecompileErrors {
    #[snafu(display("Cannot parse function {} abi = {}", name, source))]
    FailedToParse { name: String, source: ethabi::Error },

    #[snafu(display("Cannot parse function input {} error = {}", arg_type, source))]
    FailedToParseInput {
        arg_type: String,
        source: FromHexError,
    },

    #[snafu(display(
        "Input len lesser than 4 bytes, expected to be function hash, input_len = {}",
        input_len
    ))]
    InputToShort { input_len: usize },

    #[snafu(display("Function hash, not equal, expected = {}, got = {}", expected, got))]
    MismatchFunctionHash { expected: String, got: String },

    #[snafu(display(
        "Received different params count, expected = {}, got = {}",
        expected,
        got
    ))]
    ParamsCountMismatch { expected: usize, got: usize },

    #[snafu(display(
        "Function received unexpected input, expected = {}, got = {}",
        expected,
        got
    ))]
    UnexpectedInput { expected: String, got: String },

    #[snafu(display("Failed to find account, account_pk = {}", public_key))]
    AccountNotFound { public_key: solana::Address },

    #[snafu(display(
        "No enough tokens, on EVM state account, to credit request = {}",
        lamports
    ))]
    InsufficientFunds { lamports: u64 },

    #[snafu(display("Native chain Instruction error source = {}", source))]
    NativeChainInstructionError { source: InstructionError },
}

impl From<PrecompileErrors> for ExitError {
    fn from(rhs: PrecompileErrors) -> Self {
        ExitError::Other(rhs.to_string().into())
    }
}