fuel_abi_types/
error_codes.rs1use thiserror::Error;
2
3pub const FAILED_REQUIRE_SIGNAL: u64 = 0xffff_ffff_ffff_0000;
5
6pub const FAILED_TRANSFER_TO_ADDRESS_SIGNAL: u64 = 0xffff_ffff_ffff_0001;
8
9pub const FAILED_SEND_MESSAGE_SIGNAL: u64 = 0xffff_ffff_ffff_0002;
11
12pub const FAILED_ASSERT_EQ_SIGNAL: u64 = 0xffff_ffff_ffff_0003;
14
15pub const FAILED_ASSERT_SIGNAL: u64 = 0xffff_ffff_ffff_0004;
17
18pub const FAILED_ASSERT_NE_SIGNAL: u64 = 0xffff_ffff_ffff_0005;
20
21pub const REVERT_WITH_LOG_SIGNAL: u64 = 0xffff_ffff_ffff_0006;
23
24#[derive(Error, Debug)]
25pub enum ErrorSignal {
26 #[error("Failing call to `std::revert::require`.")]
27 Require,
28 #[error("Failing call to `std::token::transfer_to_address`.")]
29 TransferToAddress,
30 #[error("Failing call to `std::message::send_message`.")]
31 SendMessage,
32 #[error("Failing call to `std::assert::assert_eq`.")]
33 AssertEq,
34 #[error("Failing call to `std::assert::assert`.")]
35 Assert,
36 #[error("Failing call to `std::assert::assert_ne`.")]
37 AssertNe,
38 #[error("Failing call to `std::revert::revert_with_log`.")]
39 RevertWithLog,
40}
41
42#[derive(Error, Debug)]
43pub enum Error {
44 #[error("Unknown revert code: {0}")]
45 UnknownRevertCode(u64),
46}
47
48impl ErrorSignal {
49 pub fn try_from_revert_code(revert_code: u64) -> Result<Self, Error> {
51 if revert_code == FAILED_REQUIRE_SIGNAL {
52 Ok(Self::Require)
53 } else if revert_code == FAILED_TRANSFER_TO_ADDRESS_SIGNAL {
54 Ok(Self::TransferToAddress)
55 } else if revert_code == FAILED_SEND_MESSAGE_SIGNAL {
56 Ok(Self::SendMessage)
57 } else if revert_code == FAILED_ASSERT_EQ_SIGNAL {
58 Ok(Self::AssertEq)
59 } else if revert_code == FAILED_ASSERT_SIGNAL {
60 Ok(Self::Assert)
61 } else if revert_code == FAILED_ASSERT_NE_SIGNAL {
62 Ok(Self::AssertNe)
63 } else if revert_code == REVERT_WITH_LOG_SIGNAL {
64 Ok(Self::RevertWithLog)
65 } else {
66 Err(Error::UnknownRevertCode(revert_code))
67 }
68 }
69
70 pub fn to_revert_code(self) -> u64 {
73 match self {
74 ErrorSignal::Require => FAILED_REQUIRE_SIGNAL,
75 ErrorSignal::TransferToAddress => FAILED_TRANSFER_TO_ADDRESS_SIGNAL,
76 ErrorSignal::SendMessage => FAILED_SEND_MESSAGE_SIGNAL,
77 ErrorSignal::AssertEq => FAILED_ASSERT_EQ_SIGNAL,
78 ErrorSignal::Assert => FAILED_ASSERT_SIGNAL,
79 ErrorSignal::AssertNe => FAILED_ASSERT_NE_SIGNAL,
80 ErrorSignal::RevertWithLog => REVERT_WITH_LOG_SIGNAL,
81 }
82 }
83}