Skip to content

Commit

Permalink
transact xcm test
Browse files Browse the repository at this point in the history
  • Loading branch information
yrong committed May 17, 2021
1 parent da4c3ba commit 4cdf87d
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
.vscode
.DS_Store
/.cargo/config
data
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 rococo-parachains/pallets/ping/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ version = "0.1.0"
[dependencies]
codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = ["derive"] }
serde = { version = "1.0.101", optional = true, features = ["derive"] }

log = "0.4.14"
sp-std = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-v1" }
sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-v1" }
frame-support = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-v1" }
Expand Down
50 changes: 50 additions & 0 deletions rococo-parachains/pallets/ping/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,22 @@ use frame_system::Config as SystemConfig;
use cumulus_primitives_core::ParaId;
use cumulus_pallet_xcm::{Origin as CumulusOrigin, ensure_sibling_para};
use xcm::v0::{Xcm, Error as XcmError, SendXcm, OriginKind, MultiLocation, Junction};
use codec::{Decode, Encode};

pub use pallet::*;

#[derive(Encode, Decode)]
pub enum RelayTemplatePalletCall {
#[codec(index = 100)] // the index should match the position of the module in `construct_runtime!`
DoSomething(DoSomethingCall),
}

#[derive(Encode, Decode)]
pub enum DoSomethingCall {
#[codec(index = 0)] // the index should match the position of the dispatchable in the target pallet
Something(u32),
}

#[frame_support::pallet]
pub mod pallet {
use frame_support::pallet_prelude::*;
Expand Down Expand Up @@ -88,6 +101,8 @@ pub mod pallet {
ErrorSendingPing(XcmError, ParaId, u32, Vec<u8>),
ErrorSendingPong(XcmError, ParaId, u32, Vec<u8>),
UnknownPong(ParaId, u32, Vec<u8>),
TestMsg(u32),
ErrorSendingTest(),
}

#[pallet::error]
Expand Down Expand Up @@ -117,6 +132,41 @@ pub mod pallet {
}
}
}
log::info!(
target: "ping",
"Begin construct relay transact"
);
let some_value:u32 = 10;
let call = RelayTemplatePalletCall::DoSomething(DoSomethingCall::Something(some_value)).encode();

let msg = Xcm::Transact {
origin_type: OriginKind::SovereignAccount,
require_weight_at_most: 1_000,
call:call.into(),
};

log::info!(
target: "ping",
"Relay transact {:?}",
msg,
);

match T::XcmSender::send_xcm(MultiLocation::X1(Junction::Parent), msg){
Ok(()) => {
Self::deposit_event(Event::TestMsg(some_value));
log::info!(
target: "ping",
"Relay transact sent success!"
);
},
Err(e) => {
Self::deposit_event(Event::ErrorSendingTest());
log::error!(
target: "ping",
"Relay transact sent failed!"
);
}
}
}
}

Expand Down

0 comments on commit 4cdf87d

Please sign in to comment.