Skip to content

Commit

Permalink
Skeleton impl of add_pool extrinsic
Browse files Browse the repository at this point in the history
  • Loading branch information
NunoAlexandre committed Jul 21, 2022
1 parent 9b7f34f commit 65d7075
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 24 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion libs/common-traits/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ pub trait PoolNAV<PoolId, Amount> {

/// A trait that support pool inspection operations such as pool existence checks and pool admin of permission set.
pub trait PoolInspect<AccountId> {
type PoolId: Parameter + Member + Debug + Copy + Default + TypeInfo;
type PoolId: Parameter + Member + Debug + Copy + Default + TypeInfo + Encode + Decode;

/// check if the pool exists
fn pool_exists(pool_id: Self::PoolId) -> bool;
Expand Down
4 changes: 3 additions & 1 deletion pallets/connectors/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pallet-uniques = { git = "https://github.com/paritytech/substrate", default-fea
orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", default-features = false, optional = true, branch = "polkadot-v0.9.24" }
orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", default-features = false, optional = true, branch = "polkadot-v0.9.24" }
common-types = { path = "../../libs/common-types", default-features = false, optional = true }
common-traits = { path = "../../libs/common-traits", default-features = false, optional = true }
runtime-common = { path = "../../runtime/common", default-features = false, optional = true }

[dev-dependencies]
Expand All @@ -43,21 +44,22 @@ orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-li

# Local crates
runtime-common = { path = "../../runtime/common", default-features = true }
common-types = { path = "../../libs/common-types", default-features = false }

[features]
default = ['std']
runtime-benchmarks = [
"frame-benchmarking",
"pallet-balances",
"common-types",
"common-traits",
"runtime-common",
"orml-tokens",
"orml-traits",
]
std = [
'codec/std',
'common-types/std',
'common-traits/std',
'frame-support/std',
'frame-system/std',
'sp-std/std',
Expand Down
44 changes: 25 additions & 19 deletions pallets/connectors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
//!
#![cfg_attr(not(feature = "std"), no_std)]
use codec::{Decode, Encode, HasCompact};
use common_traits::PoolInspect;
use frame_support::dispatch::DispatchResult;
use frame_system::ensure_signed;
use scale_info::TypeInfo;
Expand All @@ -22,12 +23,16 @@ mod routers;
pub use routers::*;

// Type aliases
type PoolIdOf<T> = <T as pallet::Config>::PoolId;
pub type PoolIdOf<T> =
<<T as Config>::PoolInspect as PoolInspect<<T as frame_system::Config>::AccountId>>::PoolId;
pub type MessageOf<T> =
Message<PoolIdOf<T>>;

#[frame_support::pallet]
pub mod pallet {
use super::*;
use crate::weights::WeightInfo;
use common_traits::PoolInspect;
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
use sp_core::TypeId;
Expand All @@ -53,17 +58,6 @@ pub mod pallet {

type CurrencyId: Parameter + Member + Copy + MaybeSerializeDeserialize + Ord + TypeInfo;

type PoolId: Member
+ Parameter
+ Default
+ Copy
+ HasCompact
+ MaxEncodedLen
+ core::fmt::Debug
+ Encode
+ Decode
+ Into<u64>;

type TrancheId: Member
+ Parameter
+ Default
Expand All @@ -78,7 +72,7 @@ pub mod pallet {
type Permissions: Member;

//TODO(nuno)
type PoolInspect: Member;
type PoolInspect: PoolInspect<Self::AccountId>;
}

#[pallet::event]
Expand All @@ -87,7 +81,7 @@ pub mod pallet {
/// A pool was added to the domain
MessageSent {
domain: Domain,
message: Message<T::PoolId>,
message: Message<PoolIdOf<T>>,
},
}

Expand Down Expand Up @@ -133,7 +127,8 @@ pub mod pallet {

#[pallet::error]
pub enum Error<T> {
ToDo,
/// A pool could not be found
PoolNotFound,
}

#[pallet::call]
Expand All @@ -142,18 +137,29 @@ pub mod pallet {
#[pallet::weight(<T as Config>::WeightInfo::add_pool())]
pub fn add_pool(
origin: OriginFor<T>,
_pool_id: T::PoolId,
_domain: Domain,
pool_id: PoolIdOf<T>,
domain: Domain,
) -> DispatchResult {
let _who = ensure_signed(origin.clone())?;
ensure_signed(origin.clone())?;

// Check the pool exists
ensure!(
T::PoolInspect::pool_exists(pool_id),
Error::<T>::PoolNotFound
);

//TODO(nuno)
// Send the message through the router
Self::do_send_message(Message::AddPool { pool_id }, domain)?;

Ok(())
}
}

impl<T: Config> Pallet<T> {
// skeleton

pub fn do_send_message(message: MessageOf<T>, domain: Domain) -> Result<(), Error<T>> {
todo!("nuno")
}
}
}
7 changes: 5 additions & 2 deletions pallets/connectors/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ use crate::*;

#[derive(Decode, Clone, PartialEq, TypeInfo)]
#[cfg_attr(feature = "std", derive(Debug))]
pub enum Message<PoolId> where PoolId: Encode + Decode {
pub enum Message<PoolId>
where
PoolId: Encode + Decode,
{
Invalid,
AddPool { pool_id: PoolId }, // More to come...
}
Expand All @@ -11,7 +14,7 @@ impl<PoolId: Encode + Decode> Message<PoolId> {
fn call_type(&self) -> u8 {
match self {
Self::Invalid => 0,
Self::AddPool { .. } => 1,
Self::AddPool { .. } => 1,
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion pallets/connectors/src/routers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ pub struct NomadRouter {
#[cfg_attr(feature = "std", derive(Debug))]
pub struct XCMRouter {
multilocations: (), // TODO(nuno): make it a Map<Domain, MultiLocation>
}
}

0 comments on commit 65d7075

Please sign in to comment.