mod common;
mod context;
mod handle;
mod incoming;
mod init;
mod reply;
mod signal;
mod stored;
mod user;
pub use common::{Dispatch, Message, MessageDetails, ReplyDetails, SignalDetails};
pub use context::{
ContextOutcome, ContextOutcomeDrain, ContextSettings, ContextStore, MessageContext,
};
pub use gear_core_errors::{ErrorReplyReason, ReplyCode, SuccessReplyReason};
pub use handle::{HandleMessage, HandlePacket};
pub use incoming::{IncomingDispatch, IncomingMessage};
pub use init::{InitMessage, InitPacket};
pub use reply::{ReplyMessage, ReplyPacket};
use scale_decode::DecodeAsType;
use scale_encode::EncodeAsType;
pub use signal::SignalMessage;
pub use stored::{StoredDelayedDispatch, StoredDispatch, StoredMessage};
pub use user::{UserMessage, UserStoredMessage};
use core::fmt::Debug;
use gear_wasm_instrument::syscalls::SyscallName;
use parity_scale_codec::{Decode, Encode};
use scale_info::TypeInfo;
pub type GasLimit = u64;
pub type Value = u128;
pub type Salt = crate::buffer::Payload;
#[derive(
Clone,
Copy,
Debug,
Default,
PartialEq,
Eq,
PartialOrd,
Ord,
Hash,
Decode,
DecodeAsType,
Encode,
EncodeAsType,
TypeInfo,
)]
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
pub enum DispatchKind {
Init,
#[default]
Handle,
Reply,
Signal,
}
impl DispatchKind {
pub fn is_init(&self) -> bool {
matches!(self, Self::Init)
}
pub fn is_handle(&self) -> bool {
matches!(self, Self::Handle)
}
pub fn is_reply(&self) -> bool {
matches!(self, Self::Reply)
}
pub fn is_signal(&self) -> bool {
matches!(self, Self::Signal)
}
pub fn forbids(&self, syscall_name: SyscallName) -> bool {
match self {
DispatchKind::Signal => matches!(
syscall_name,
SyscallName::Source
| SyscallName::Reply
| SyscallName::ReplyPush
| SyscallName::ReplyCommit
| SyscallName::ReplyCommitWGas
| SyscallName::ReplyInput
| SyscallName::ReplyInputWGas
| SyscallName::ReservationReply
| SyscallName::ReservationReplyCommit
| SyscallName::SystemReserveGas
),
_ => false,
}
}
}
pub trait Packet {
fn payload_bytes(&self) -> &[u8];
fn payload_len(&self) -> u32;
fn gas_limit(&self) -> Option<GasLimit>;
fn value(&self) -> Value;
fn kind() -> DispatchKind;
}