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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#![feature(non_exhaustive)]
#[macro_use]
extern crate derive_more;
mod address;
mod balance;
pub use address::Address;
pub use balance::Balance;
#[derive(PartialEq, Eq, Debug)]
#[repr(u32)]
#[non_exhaustive]
#[doc(hidden)]
pub enum ExtStatusCode {
Success,
InsufficientFunds,
InvalidInput,
NoAccount,
}
#[derive(Clone, Default, Debug, PartialEq, Eq)]
pub struct AccountMeta {
pub balance: u128,
pub expiry: Option<std::time::Duration>,
}
#[derive(Clone, Default, Debug, PartialEq, Eq)]
pub struct Event {
pub emitter: Address,
pub topics: Vec<[u8; 32]>,
pub data: Vec<u8>,
}
#[derive(Debug, thiserror::Error)]
#[cfg_attr(target_os = "wasi", derive(Clone))]
#[cfg_attr(
all(target_os = "wasi", feature = "serde"),
derive(oasis_borsh::BorshSerialize, oasis_borsh::BorshDeserialize)
)]
pub enum RpcError {
#[error("invalid callee")]
InvalidCallee,
#[error("caller does not have enough balance to cover transaction")]
InsufficientFunds,
#[error("not enough gas provided to transaction")]
InsufficientGas,
#[error("transaction received invalid input")]
InvalidInput,
#[error("transaction returned invalid output")]
InvalidOutput(Vec<u8>),
#[error("an application error occurred")]
Execution(Vec<u8>),
#[cfg(not(target_os = "wasi"))]
#[error("gateway error. {0}")]
GatewayError(anyhow::Error),
}
impl RpcError {
pub fn execution(&self) -> Option<&[u8]> {
match self {
RpcError::Execution(output) => Some(&output),
_ => None,
}
}
}