-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Contracts expose pallet-xcm #1248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
251e8cd
3b1cc37
22430a3
c6e1f49
bf66839
a348bd9
b2a9f4e
d20d6ca
8388585
4bae246
0675899
2049b57
be04741
b7875ad
c312b98
5983dbd
7484d32
b40f92c
c3f7d40
a08e41b
376a6b3
5b883d6
967616c
d2b5ba3
d7fe1bc
c15adab
e15c7eb
971b167
3dba8d1
be1a46d
a4d706c
b15ea88
b938df4
fcc37f5
9cc990f
7ff220b
bdf0ae7
14e1514
e9d2cdf
c9f8f35
151175b
43f38d2
4583e03
ceb3fc8
db7c479
cd8281e
c004909
526abbd
0a98a89
1d1f40a
e01cb2c
2c7735b
4e3de86
e52f85f
d78ec47
435de45
c4d87ff
4363e6d
ac39a50
0bf6e1a
ddf485a
975ef56
448c9d4
132e203
7bf716d
6a7a8bd
8c1c118
06a5c9a
b47f660
06cf121
0949455
14fed0e
e694941
72f15c1
c8f39e7
54e2803
ce637dc
582467d
79535cb
0a02451
262e17c
9413874
18c6bb4
b9b2ccc
198d692
e3ce2e0
6342962
a2fde63
0ae8763
034150c
7848e2f
b7155b6
34329e5
07439dd
b37d169
de8f1a9
7cd84a2
8ac21da
7ee5d08
e13b51b
2359fa0
41215d3
e515180
8b0f8ac
3526658
784f8df
0b5517a
7b3ad3d
0b4c840
80e0c53
59d67a0
9a9d572
3adde14
c70aca5
5d63636
57b7ca5
10f22fb
162ad54
3a4a251
dab8314
e3161c9
4128aa6
f0df85b
b48a8f9
7c72e24
b34e245
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,19 +19,17 @@ use crate::{ | |
| xcm::{CallOf, WeightInfo, XCM}, | ||
| AccountIdOf, Box, Config, RawOrigin, | ||
| }; | ||
| use frame_support::{ | ||
| dispatch::PostDispatchInfo, pallet_prelude::DispatchResultWithPostInfo, weights::Weight, | ||
| }; | ||
| use frame_support::{pallet_prelude::DispatchResultWithPostInfo, weights::Weight}; | ||
| use frame_system::pallet_prelude::BlockNumberFor; | ||
| use pallet_xcm::WeightInfo as XcmWeightInfo; | ||
| use sp_runtime::{DispatchError, DispatchErrorWithPostInfo, DispatchResult}; | ||
| use sp_runtime::{DispatchError, DispatchResult}; | ||
| use xcm::{v3::MultiLocation, VersionedMultiLocation, VersionedXcm}; | ||
| use xcm_executor::traits::{QueryHandler, QueryResponseStatus}; | ||
|
|
||
| /// A pallet-xcm adapter for the XCM trait. | ||
| pub struct PalletXCMAdapter<T: pallet_xcm::Config>(sp_std::marker::PhantomData<T>); | ||
| pub struct XCMAdapter<T: pallet_xcm::Config>(sp_std::marker::PhantomData<T>); | ||
pgherveou marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| impl<T> WeightInfo for PalletXCMAdapter<T> | ||
| impl<T> WeightInfo for XCMAdapter<T> | ||
| where | ||
| T: pallet_xcm::Config, | ||
| { | ||
|
|
@@ -49,8 +47,8 @@ where | |
| } | ||
| } | ||
|
|
||
| impl<T: Config + pallet_xcm::Config> PalletXCMAdapter<T> { | ||
| /// Ensure that the message is executable, by checking that it does not contain any Transact | ||
| impl<T: Config + pallet_xcm::Config> XCMAdapter<T> { | ||
| /// Ensure that the message is executable, by checking that it does not contain any [`Transact`] | ||
| /// instruction with a call that is not allowed by the CallFilter. | ||
|
||
| fn ensure_executable( | ||
| message: VersionedXcm<CallOf<T>>, | ||
|
|
@@ -76,7 +74,7 @@ impl<T: Config + pallet_xcm::Config> PalletXCMAdapter<T> { | |
| } | ||
| } | ||
|
|
||
| impl<T: Config + pallet_xcm::Config> XCM<T> for PalletXCMAdapter<T> { | ||
| impl<T: Config + pallet_xcm::Config> XCM<T> for XCMAdapter<T> { | ||
| type QueryId = <pallet_xcm::Pallet<T> as QueryHandler>::QueryId; | ||
| type WeightInfo = Self; | ||
|
|
||
|
|
@@ -85,16 +83,7 @@ impl<T: Config + pallet_xcm::Config> XCM<T> for PalletXCMAdapter<T> { | |
| message: VersionedXcm<CallOf<T>>, | ||
| max_weight: Weight, | ||
| ) -> DispatchResultWithPostInfo { | ||
| // TODO since we are doing more than just calling pallet_xcm::Pallet::<T>::execute, we | ||
| // should benchmark this ensure_executable | ||
| let msg = Self::ensure_executable(message).map_err(|err| DispatchErrorWithPostInfo { | ||
| post_info: PostDispatchInfo { | ||
| actual_weight: Some(Weight::zero()), | ||
| pays_fee: Default::default(), | ||
| }, | ||
| error: err.into(), | ||
| })?; | ||
|
|
||
| let msg = Self::ensure_executable(message)?; | ||
| let origin = RawOrigin::Signed(origin.clone()).into(); | ||
| pallet_xcm::Pallet::<T>::execute(origin, msg, max_weight) | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, what's the purpose of the
Xcmtrait in this file? I'm not sure I'm following just by reading the code here...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than tight coupling
pallet_contracts::Configwithpallet_xcm::Config, we are exposing a subset of the function we want to expose to contracts through this trait.This is exposed in the config here:
polkadot-sdk/substrate/frame/contracts/src/lib.rs
Lines 407 to 411 in d78ec47
XcmAdapter<Self>implement this trait and forward the calls to pallet-xcm.This is exposed to SC through the new host fn (
xcm_*) methods:polkadot-sdk/substrate/frame/contracts/src/wasm/runtime.rs
Lines 2651 to 2690 in d78ec47
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with loosely coupling vs tightly coupling. We already do this all over the place when we need the pallet-xcm for something, so we have a bunch of traits that represent certain subsets of functionality. I'm in favor of reusing those and if no one suits your needs then modify it at the source because that should be the way to do this.