Skip to content

Commit

Permalink
router support
Browse files Browse the repository at this point in the history
  • Loading branch information
lemunozm committed Aug 12, 2024
1 parent e4595a5 commit c224c1e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
6 changes: 6 additions & 0 deletions libs/traits/src/liquidity_pools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub trait LPEncoding: Sized {
}

/// The trait required for sending outbound messages.
/// TODO: remove this
pub trait Router {
/// The sender type of the outbound message.
type Sender;
Expand All @@ -50,6 +51,11 @@ pub trait Router {
fn send(&self, sender: Self::Sender, message: Vec<u8>) -> DispatchResultWithPostInfo;
}

pub trait RouterSupport<Domain>: Sized {
/// Returns a list of routers supported for the given domain.
fn for_domain(domain: Domain) -> Vec<Self>;
}

/// The behavior of an entity that can send messages
pub trait MessageSender {
/// The middleware by where this message is sent
Expand Down
13 changes: 11 additions & 2 deletions runtime/common/src/routing.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use cfg_traits::liquidity_pools::{MessageReceiver, MessageSender};
use cfg_traits::liquidity_pools::{MessageReceiver, MessageSender, RouterSupport};
use cfg_types::domain_address::{Domain, DomainAddress};
use frame_support::{
dispatch::{DispatchResult, DispatchResultWithPostInfo},
Expand All @@ -11,7 +11,7 @@ use sp_std::marker::PhantomData;
/// RouterId is more specific than Domain, because RouterId also identify by
/// where the message is sent/received
pub enum RouterId {
/// The message must be sent/received by EVM using axelar
/// The message must be sent/received by EVM using Axelar
Axelar(AxelarId),
}

Expand All @@ -23,6 +23,15 @@ impl From<RouterId> for Domain {
}
}

impl RouterSupport<Domain> for RouterId {
fn for_domain(domain: Domain) -> Vec<Self> {
match domain {
Domain::EVM(chain_id) => vec![RouterId::Axelar(AxelarId::Evm(chain_id))],
Domain::Centrifuge => vec![],
}
}
}

/// This type choose the correct router implementation given a router id
struct RouterDispatcher<Routers>(PhantomData<Routers>);

Expand Down

0 comments on commit c224c1e

Please sign in to comment.