1mod common;
7mod context;
8mod handle;
9mod incoming;
10mod init;
11mod reply;
12mod signal;
13mod stored;
14mod user;
15
16pub use common::{Dispatch, Message, MessageDetails, ReplyDetails, SignalDetails};
17pub use context::{
18 ContextOutcome, ContextOutcomeDrain, ContextSettings, ContextStore, MessageContext,
19};
20pub use gear_core_errors::{ErrorReplyReason, ReplyCode, SuccessReplyReason};
21pub use handle::{HandleMessage, HandlePacket};
22pub use incoming::{IncomingDispatch, IncomingMessage};
23pub use init::{InitMessage, InitPacket};
24pub use reply::{ReplyMessage, ReplyPacket};
25use scale_decode::DecodeAsType;
26use scale_encode::EncodeAsType;
27pub use signal::SignalMessage;
28pub use stored::{StoredDelayedDispatch, StoredDispatch, StoredMessage};
29pub use user::{UserMessage, UserStoredMessage};
30
31use core::fmt::Debug;
32use gear_wasm_instrument::syscalls::SyscallName;
33use parity_scale_codec::{Decode, Encode};
34use scale_info::TypeInfo;
35
36pub type GasLimit = u64;
38
39pub type Value = u128;
41
42pub type Salt = crate::buffer::Payload;
44
45#[derive(
47 Clone,
48 Copy,
49 Debug,
50 Default,
51 PartialEq,
52 Eq,
53 PartialOrd,
54 Ord,
55 Hash,
56 Decode,
57 DecodeAsType,
58 Encode,
59 EncodeAsType,
60 TypeInfo,
61)]
62#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
63pub enum DispatchKind {
64 Init,
66 #[default]
68 Handle,
69 Reply,
71 Signal,
73}
74
75impl DispatchKind {
76 pub fn is_init(&self) -> bool {
78 matches!(self, Self::Init)
79 }
80
81 pub fn is_handle(&self) -> bool {
83 matches!(self, Self::Handle)
84 }
85
86 pub fn is_reply(&self) -> bool {
88 matches!(self, Self::Reply)
89 }
90
91 pub fn is_signal(&self) -> bool {
93 matches!(self, Self::Signal)
94 }
95
96 pub fn forbids(&self, syscall_name: SyscallName) -> bool {
98 match self {
99 DispatchKind::Signal => matches!(
100 syscall_name,
101 SyscallName::Source
102 | SyscallName::Reply
103 | SyscallName::ReplyPush
104 | SyscallName::ReplyCommit
105 | SyscallName::ReplyCommitWGas
106 | SyscallName::ReplyInput
107 | SyscallName::ReplyInputWGas
108 | SyscallName::ReservationReply
109 | SyscallName::ReservationReplyCommit
110 | SyscallName::SystemReserveGas
111 ),
112 _ => false,
113 }
114 }
115}
116
117pub trait Packet {
121 fn payload_bytes(&self) -> &[u8];
123
124 fn payload_len(&self) -> u32;
126
127 fn gas_limit(&self) -> Option<GasLimit>;
129
130 fn value(&self) -> Value;
132
133 fn kind() -> DispatchKind;
135}