Skip to content

Commit

Permalink
finish the transfer kind logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Freddy Li committed Dec 5, 2023
1 parent 3939b6c commit f094d6b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
4 changes: 4 additions & 0 deletions traits/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,7 @@ pub trait Bridge {
dest: MultiLocation,
) -> DispatchResult;
}

pub trait AssetReserveLocationParser {
fn reserved_location(asset: &MultiAsset) -> Option<MultiLocation>;
}
23 changes: 16 additions & 7 deletions xcm-bridge/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ pub mod pallet {
type Weigher: WeightBounds<Self::RuntimeCall>;

type XcmExecutor: ExecuteXcm<Self::RuntimeCall>;

#[pallet::constant]
type SelfLocation: Get<MultiLocation>;

type ReserveLocationParser: AssetReserveLocationParser;
}

enum TransferKind {
Expand Down Expand Up @@ -51,18 +56,22 @@ pub mod pallet {
}

pub trait XcmHandler {
fn transfer_kind(&self) -> Result<Xcm<T::RuntimeCall>, DispatchError>;
fn transfer_kind(&self) -> Result<TransferKind, DispatchError>;
fn create_instructions(&self) -> Result<Xcm<T::RuntimeCall>, DispatchError>;
fn execute_instructions(&self, xcm_message: Xcm<T::RuntimeCall>) -> DispatchResult;
}

impl XcmHandler for Xcm {
/// Get the transfer kind.
fn transfer_kind(&self) -> Result<Xcm<T::RuntimeCall>, DispatchError> {
// todo: impl the xcm kind logic, return the following:
// SelfReserveAsset,
// ToReserve,
// ToNonReserve,
fn transfer_kind(&self) -> Result<TransferKind, DispatchError> {
let asset_location = T::ReserveLocationParser::reserved_location(&self.asset).ok_or()?;
if asset_location == T::SelfLocation {
TransferKind::SelfReserveAsset
} else if asset_location == self.dest {
TransferKind::ToReserve
} else {
TransferKind::ToNonReserve
}
}
fn create_instructions(&self) {
let kind = Self::transfer_kind(&self)?;
Expand Down Expand Up @@ -120,7 +129,7 @@ pub mod pallet {
weight: XCMWeight::from_parts(6_000_000_000u64, 2_000_000u64),
};
let mut msg = xcm.create_instructions()?;
// TODO: execute xcm message

xcm.execute_instructions(msg)?;

Ok(())
Expand Down

0 comments on commit f094d6b

Please sign in to comment.