Skip to content

Commit

Permalink
add xcm message struct and execution logic
Browse files Browse the repository at this point in the history
  • Loading branch information
freddyli7 committed Nov 28, 2023
1 parent 077a55d commit da30fb9
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
19 changes: 19 additions & 0 deletions Cargo.lock

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

45 changes: 45 additions & 0 deletions xcm-bridge/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ pub mod pallet {
#[pallet::config]
pub trait Config: frame_system::Config {
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;

type Weigher: WeightBounds<Self::RuntimeCall>;

type XcmExecutor: ExecuteXcm<Self::RuntimeCall>;
}

#[pallet::event]
Expand All @@ -23,6 +27,47 @@ pub mod pallet {
XCMTransferSend {},
}

#[pallet::error]
pub enum Error<T> {
FailToWeightMessage,
XcmExecutionFailed,
}

struct Xcm<T: Config>{
asset: MultiAsset,
origin: MultiLocation,
dest: MultiLocation,
recipient: MultiLocation,
weight: XCMWeight,
}

pub trait XcmHandler {
fn create_message(&self) -> Result<Xcm<T::RuntimeCall>, DispatchError>;
fn execute_message(&self, xcm_message: Xcm<T::RuntimeCall>) -> DispatchResult;
}

impl XcmHandler for Xcm {
fn create_message(&self) {

}

fn execute_message(&self, xcm_message: Xcm<T::RuntimeCall>) {
let message_weight = T::Weigher::weight(xcm_message).map_err(|()| Error::<T>::FailToWeightMessage)?;

let hash = xcm_message.using_encoded(sp_io::hashing::blake2_256);

T::XcmExecutor::execute_xcm_in_credit(
self.origin.clone(),
xcm_message.clone(),
hash,
message_weight,
message_weight
).ensure_complete().map_err(|_| Error::<T>::XcmExecutionFailed)?;

oK(())
}
}

#[pallet::call]
impl<T: Config> Bridge for Pallet<T> {
#[pallet::call_index(0)]
Expand Down

0 comments on commit da30fb9

Please sign in to comment.