#[cfg(not(feature = "std"))]
extern crate alloc;
#[cfg(not(feature = "std"))]
use alloc::vec::Vec;
use codec::{Decode, Encode};
use frame_support::weights::Weight;
use frame_support::Parameter;
use scale_info::TypeInfo;
use sp_domains::ChainId;
use sp_runtime::traits::Member;
use sp_runtime::{DispatchError, DispatchResult};
pub type EndpointId = u64;
#[derive(Debug, Encode, Decode, Clone, Eq, PartialEq, TypeInfo)]
pub enum Endpoint {
Id(EndpointId),
}
pub type EndpointPayload = Vec<u8>;
#[derive(Debug, Encode, Decode, Clone, Eq, PartialEq, TypeInfo)]
pub struct EndpointRequest {
pub src_endpoint: Endpoint,
pub dst_endpoint: Endpoint,
pub payload: EndpointPayload,
}
pub type EndpointResponse = Result<EndpointPayload, DispatchError>;
pub trait Sender<AccountId> {
type MessageId: Parameter + Member + Copy + Default;
fn send_message(
sender: &AccountId,
dst_chain_id: ChainId,
req: EndpointRequest,
) -> Result<Self::MessageId, DispatchError>;
#[cfg(feature = "runtime-benchmarks")]
fn unchecked_open_channel(dst_chain_id: ChainId) -> Result<(), DispatchError>;
}
pub trait EndpointHandler<MessageId> {
fn message(
&self,
src_chain_id: ChainId,
message_id: MessageId,
req: EndpointRequest,
) -> EndpointResponse;
fn message_weight(&self) -> Weight;
fn message_response(
&self,
dst_chain_id: ChainId,
message_id: MessageId,
req: EndpointRequest,
resp: EndpointResponse,
) -> DispatchResult;
fn message_response_weight(&self) -> Weight;
}
#[cfg(feature = "runtime-benchmarks")]
pub struct BenchmarkEndpointHandler;
#[cfg(feature = "runtime-benchmarks")]
impl<MessageId> EndpointHandler<MessageId> for BenchmarkEndpointHandler {
fn message(
&self,
_src_chain_id: ChainId,
_message_id: MessageId,
_req: EndpointRequest,
) -> EndpointResponse {
Ok(Vec::new())
}
fn message_weight(&self) -> Weight {
Weight::zero()
}
fn message_response(
&self,
_dst_chain_id: ChainId,
_message_id: MessageId,
_req: EndpointRequest,
_resp: EndpointResponse,
) -> DispatchResult {
Ok(())
}
fn message_response_weight(&self) -> Weight {
Weight::zero()
}
}