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