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};
40pub use signal::SignalMessage;
41pub use stored::{StoredDelayedDispatch, StoredDispatch, StoredMessage};
42pub use user::{UserMessage, UserStoredMessage};
43
44use core::fmt::Debug;
45use gear_wasm_instrument::syscalls::SyscallName;
46use parity_scale_codec::{Decode, Encode};
47use scale_info::TypeInfo;
48
49pub type GasLimit = u64;
51
52pub type Value = u128;
54
55pub type Salt = crate::buffer::Payload;
57
58#[derive(
60 Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Decode, Encode, 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}