Skip to content

Commit

Permalink
skeleton impl of router send_msg
Browse files Browse the repository at this point in the history
  • Loading branch information
NunoAlexandre committed Jul 21, 2022
1 parent 65d7075 commit ac9b3c7
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
14 changes: 11 additions & 3 deletions pallets/connectors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ pub use routers::*;
// Type aliases
pub type PoolIdOf<T> =
<<T as Config>::PoolInspect as PoolInspect<<T as frame_system::Config>::AccountId>>::PoolId;
pub type MessageOf<T> =
Message<PoolIdOf<T>>;
pub type MessageOf<T> = Message<PoolIdOf<T>>;

#[frame_support::pallet]
pub mod pallet {
Expand Down Expand Up @@ -129,6 +128,12 @@ pub mod pallet {
pub enum Error<T> {
/// A pool could not be found
PoolNotFound,

/// The specified domain has no associated router
InvalidDomain,

/// Failed to send a message
SendFailure,
}

#[pallet::call]
Expand Down Expand Up @@ -159,7 +164,10 @@ pub mod pallet {
// skeleton

pub fn do_send_message(message: MessageOf<T>, domain: Domain) -> Result<(), Error<T>> {
todo!("nuno")
let router = <Routers<T>>::get(domain.clone()).ok_or(Error::<T>::InvalidDomain)?;
router
.send(domain, message)
.map_err(|_| Error::<T>::SendFailure)
}
}
}
40 changes: 40 additions & 0 deletions pallets/connectors/src/routers.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
use crate::{Domain, Message};
use codec::{Decode, Encode};
use scale_info::TypeInfo;
use sp_runtime::DispatchResult;

pub trait ConnectorRouter<Message>
where
Message: Encode + Decode,
{
fn send(target: Domain, message: Message) -> DispatchResult;
}

#[derive(Encode, Decode, Clone, PartialEq, TypeInfo)]
#[cfg_attr(feature = "std", derive(Debug))]
Expand All @@ -8,14 +17,45 @@ pub enum Router {
XCM(XCMRouter),
}

impl Router {
pub fn send<Message: Encode + Decode>(
&self,
domain: Domain,
message: Message,
) -> DispatchResult {
match self {
Router::XCM(xcm_router) => XCMRouter::send(domain, message),
Router::Nomad(nomad_router) => NomadRouter::send(domain, message),
}
}
}

#[derive(Encode, Decode, Default, Clone, PartialEq, TypeInfo)]
#[cfg_attr(feature = "std", derive(Debug))]
pub struct NomadRouter {
forwarding_contract: String, // TODO(nuno): make it a MultiLocation
}

impl<Message> ConnectorRouter<Message> for NomadRouter
where
Message: Encode + Decode,
{
fn send(target: Domain, message: Message) -> DispatchResult {
todo!()
}
}

#[derive(Encode, Decode, Default, Clone, PartialEq, TypeInfo)]
#[cfg_attr(feature = "std", derive(Debug))]
pub struct XCMRouter {
multilocations: (), // TODO(nuno): make it a Map<Domain, MultiLocation>
}

impl<Message> ConnectorRouter<Message> for XCMRouter
where
Message: Encode + Decode,
{
fn send(target: Domain, message: Message) -> DispatchResult {
todo!()
}
}

0 comments on commit ac9b3c7

Please sign in to comment.