Skip to content

Commit d7ff109

Browse files
committed
mdBook generated from gitorial
1 parent e225747 commit d7ff109

File tree

126 files changed

+7190
-574
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

126 files changed

+7190
-574
lines changed

src/11/README.md

+1-44
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,6 @@
11

2-
<div class="content-row">
3-
<div class="content-col">
2+
<div class="content-section">
43

54
{{#include ./source/README.md}}
65

76
</div>
8-
<div class="content-col">
9-
10-
<div class="tab">
11-
<button class="maintab tablinks active" onclick="switchMainTab(event, 'Source')">Source</button>
12-
<button class="maintab tablinks" onclick="switchMainTab(event, 'Diff')">Diff</button>
13-
</div>
14-
15-
<div id="Source" class="maintab tabcontent active">
16-
17-
<div class="tab">
18-
<button class="subtab tablinks file-source file-modified active" onclick="switchSubTab(event, 'fundamentals/src/pallet_xcm.rs')" data-id="fundamentals/src/pallet_xcm.rs">fundamentals/src/pallet_xcm.rs</button>
19-
</div>
20-
<div id="source/fundamentals/src/pallet_xcm.rs" class="subtab tabcontent active" data-id="fundamentals/src/pallet_xcm.rs">
21-
22-
```rust
23-
{{#include ./source/fundamentals/src/pallet_xcm.rs}}
24-
```
25-
26-
</div>
27-
28-
29-
30-
</div>
31-
32-
<div id="Diff" class="maintab tabcontent">
33-
34-
35-
<div class="tab">
36-
<button class="difftab tablinks active" onclick="switchDiff(event, 'changes.diff')" data-id="changes.diff">changes.diff</button>
37-
</div>
38-
<div id="changes.diff" class="difftab tabcontent active" data-id="changes.diff">
39-
40-
```diff
41-
{{#include ./source/changes.diff}}
42-
```
43-
44-
</div>
45-
46-
</div>
47-
48-
</div>
49-
</div>

src/11/source/changes.diff

-171
Original file line numberDiff line numberDiff line change
@@ -1,171 +0,0 @@
1-
diff --git a/fundamentals/src/pallet_xcm.rs b/fundamentals/src/pallet_xcm.rs
2-
index 8b13789..7be7118 100644
3-
--- a/fundamentals/src/pallet_xcm.rs
4-
+++ b/fundamentals/src/pallet_xcm.rs
5-
@@ -1 +1,166 @@
6-
+//! # Fundamentals lesson 6: Pallet XCM
7-
+//!
8-
+//! Implement the core functionality of Pallet XCM
9-
10-
+use crate::xcm_executor::ExecuteXcm;
11-
+use frame_support::pallet_prelude::*;
12-
+use frame_system::pallet_prelude::*;
13-
+use xcm::{prelude::*, VersionedAssets, VersionedLocation, VersionedXcm};
14-
+
15-
+pub use pallet::*;
16-
+
17-
+#[frame_support::pallet]
18-
+pub mod pallet {
19-
+ use super::*;
20-
+
21-
+ #[pallet::pallet]
22-
+ pub struct Pallet<T>(_);
23-
+
24-
+ #[pallet::config]
25-
+ pub trait Config: frame_system::Config {
26-
+ /// Something to execute an XCM message.
27-
+ type XcmExecutor: ExecuteXcm;
28-
+ /// Required origin for executing XCM messages, including the teleport functionality. If
29-
+ /// successful, then it resolves to `Location` which exists as an interior location
30-
+ /// within this chain's XCM context.
31-
+ type ExecuteXcmOrigin: EnsureOrigin<
32-
+ <Self as frame_system::Config>::RuntimeOrigin,
33-
+ Success = Location,
34-
+ >;
35-
+ /// Required origin for sending XCM messages. If successful, it resolves to `Location`
36-
+ /// which exists as an interior location within this chain's XCM context.
37-
+ type SendXcmOrigin: EnsureOrigin<
38-
+ <Self as frame_system::Config>::RuntimeOrigin,
39-
+ Success = Location,
40-
+ >;
41-
+ /// The type used to actually dispatch an XCM to its destination.
42-
+ type XcmRouter: SendXcm;
43-
+ /// This chain's Universal Location.
44-
+ type UniversalLocation: Get<InteriorLocation>;
45-
+ }
46-
+
47-
+ #[pallet::error]
48-
+ pub enum Error<T> {
49-
+ /// The version of the `Versioned` value used is not able to be interpreted.
50-
+ BadVersion,
51-
+ /// Origin is invalid for sending.
52-
+ InvalidOrigin,
53-
+ /// Could not re-anchor the assets to declare the fees for the destination chain.
54-
+ CannotReanchor,
55-
+ /// A general error indicating something went wrong with the XCM Executor.
56-
+ ExecutorError,
57-
+ /// A general error indicating something went wrong with the XCM Router.
58-
+ RouterError,
59-
+ }
60-
+
61-
+ #[pallet::call]
62-
+ impl<T: Config> Pallet<T> {
63-
+ /// Execute an XCM from a local, signed, origin.
64-
+ #[pallet::call_index(0)]
65-
+ #[pallet::weight(Weight::default())]
66-
+ pub fn execute(
67-
+ origin: OriginFor<T>,
68-
+ message: Box<VersionedXcm<()>>,
69-
+ _max_weight: Weight,
70-
+ ) -> DispatchResult {
71-
+ let message = (*message).try_into().map_err(|()| Error::<T>::BadVersion)?;
72-
+ // Actually execute the XCM.
73-
+ Self::do_execute(origin, message)
74-
+ }
75-
+
76-
+ /// Send an XCM to another consensus system.
77-
+ #[pallet::call_index(1)]
78-
+ #[pallet::weight(Weight::default())]
79-
+ pub fn send(
80-
+ origin: OriginFor<T>,
81-
+ dest: Box<VersionedLocation>,
82-
+ message: Box<VersionedXcm<()>>,
83-
+ ) -> DispatchResult {
84-
+ let dest = Location::try_from(*dest).map_err(|()| Error::<T>::BadVersion)?;
85-
+ let message: Xcm<()> = (*message).try_into().map_err(|()| Error::<T>::BadVersion)?;
86-
+ // Actually send the XCM.
87-
+ Self::do_send(origin, dest, message)
88-
+ }
89-
+
90-
+ /// Teleport some assets from the local chain to some destination chain.
91-
+ #[pallet::call_index(2)]
92-
+ #[pallet::weight(Weight::default())]
93-
+ pub fn teleport_assets(
94-
+ origin: OriginFor<T>,
95-
+ dest: Box<VersionedLocation>,
96-
+ beneficiary: Box<VersionedLocation>,
97-
+ assets: Box<VersionedAssets>,
98-
+ fee_asset_item: u32,
99-
+ ) -> DispatchResult {
100-
+ let dest: Location = (*dest).try_into().map_err(|()| Error::<T>::BadVersion)?;
101-
+ let beneficiary: Location =
102-
+ (*beneficiary).try_into().map_err(|()| Error::<T>::BadVersion)?;
103-
+ let assets: Assets = (*assets).try_into().map_err(|()| Error::<T>::BadVersion)?;
104-
+ // Actually teleport the assets.
105-
+ Self::do_teleport_assets(origin, dest, beneficiary, assets, fee_asset_item)
106-
+ }
107-
+
108-
+ /// Transfer some assets from the local chain to the destination chain through their local,
109-
+ /// destination or remote reserve.
110-
+ #[pallet::call_index(3)]
111-
+ #[pallet::weight(Weight::default())]
112-
+ pub fn reserve_transfer_assets(
113-
+ origin: OriginFor<T>,
114-
+ dest: Box<VersionedLocation>,
115-
+ beneficiary: Box<VersionedLocation>,
116-
+ assets: Box<VersionedAssets>,
117-
+ fee_asset_item: u32,
118-
+ ) -> DispatchResult {
119-
+ let dest: Location = (*dest).try_into().map_err(|()| Error::<T>::BadVersion)?;
120-
+ let beneficiary: Location =
121-
+ (*beneficiary).try_into().map_err(|()| Error::<T>::BadVersion)?;
122-
+ let assets: Assets = (*assets).try_into().map_err(|()| Error::<T>::BadVersion)?;
123-
+ // Actually reserve transfer the assets.
124-
+ Self::do_reserve_transfer_assets(origin, dest, beneficiary, assets, fee_asset_item)
125-
+ }
126-
+ }
127-
+}
128-
+
129-
+impl<T: Config> Pallet<T> {
130-
+ pub fn do_execute(origin: OriginFor<T>, message: Xcm<()>) -> DispatchResult {
131-
+ todo!("{:?}", message)
132-
+ }
133-
+
134-
+ /// Relay an XCM `message` from a given `interior` location in this context to a given `dest`
135-
+ /// location.
136-
+ pub fn do_send(origin: OriginFor<T>, dest: Location, mut message: Xcm<()>) -> DispatchResult {
137-
+ todo!("{:?} {:?}", dest, message)
138-
+ }
139-
+
140-
+ pub fn do_teleport_assets(
141-
+ origin: OriginFor<T>,
142-
+ dest: Location,
143-
+ beneficiary: Location,
144-
+ assets: Assets,
145-
+ // The index into `assets` of the item which should be used to pay fees.
146-
+ // We don't use this in our naive implementation.
147-
+ _fee_asset_item: u32,
148-
+ ) -> DispatchResult {
149-
+ todo!("{:?} {:?} {:?}", dest, beneficiary, assets)
150-
+ }
151-
+
152-
+ pub fn do_reserve_transfer_assets(
153-
+ _origin: OriginFor<T>,
154-
+ _dest: Location,
155-
+ _beneficiary: Location,
156-
+ _assets: Assets,
157-
+ _fee_asset_item: u32,
158-
+ ) -> DispatchResult {
159-
+ // There are 3 different reserve transfer scenarios:
160-
+ // - A local reserve transfer: reserve-transfer `asset` to `dest`, using local chain as
161-
+ // reserve.
162-
+ // - A destination reserve transfer: reserve-transfer `asset` to `dest`, using `dest` as
163-
+ // reserve.
164-
+ // - A remote reserve transfer: reserve-transfer `asset` to `dest`, using remote chain
165-
+ // `Location` as reserve.
166-
+ //
167-
+ // This is a lot to do in this workshop, but a welcome challenge for the reader to
168-
+ // implement.
169-
+ unimplemented!()
170-
+ }
171-
+}
Original file line numberDiff line numberDiff line change
@@ -1,166 +1 @@
1-
//! # Fundamentals lesson 6: Pallet XCM
2-
//!
3-
//! Implement the core functionality of Pallet XCM
41

5-
use crate::xcm_executor::ExecuteXcm;
6-
use frame_support::pallet_prelude::*;
7-
use frame_system::pallet_prelude::*;
8-
use xcm::{prelude::*, VersionedAssets, VersionedLocation, VersionedXcm};
9-
10-
pub use pallet::*;
11-
12-
#[frame_support::pallet]
13-
pub mod pallet {
14-
use super::*;
15-
16-
#[pallet::pallet]
17-
pub struct Pallet<T>(_);
18-
19-
#[pallet::config]
20-
pub trait Config: frame_system::Config {
21-
/// Something to execute an XCM message.
22-
type XcmExecutor: ExecuteXcm;
23-
/// Required origin for executing XCM messages, including the teleport functionality. If
24-
/// successful, then it resolves to `Location` which exists as an interior location
25-
/// within this chain's XCM context.
26-
type ExecuteXcmOrigin: EnsureOrigin<
27-
<Self as frame_system::Config>::RuntimeOrigin,
28-
Success = Location,
29-
>;
30-
/// Required origin for sending XCM messages. If successful, it resolves to `Location`
31-
/// which exists as an interior location within this chain's XCM context.
32-
type SendXcmOrigin: EnsureOrigin<
33-
<Self as frame_system::Config>::RuntimeOrigin,
34-
Success = Location,
35-
>;
36-
/// The type used to actually dispatch an XCM to its destination.
37-
type XcmRouter: SendXcm;
38-
/// This chain's Universal Location.
39-
type UniversalLocation: Get<InteriorLocation>;
40-
}
41-
42-
#[pallet::error]
43-
pub enum Error<T> {
44-
/// The version of the `Versioned` value used is not able to be interpreted.
45-
BadVersion,
46-
/// Origin is invalid for sending.
47-
InvalidOrigin,
48-
/// Could not re-anchor the assets to declare the fees for the destination chain.
49-
CannotReanchor,
50-
/// A general error indicating something went wrong with the XCM Executor.
51-
ExecutorError,
52-
/// A general error indicating something went wrong with the XCM Router.
53-
RouterError,
54-
}
55-
56-
#[pallet::call]
57-
impl<T: Config> Pallet<T> {
58-
/// Execute an XCM from a local, signed, origin.
59-
#[pallet::call_index(0)]
60-
#[pallet::weight(Weight::default())]
61-
pub fn execute(
62-
origin: OriginFor<T>,
63-
message: Box<VersionedXcm<()>>,
64-
_max_weight: Weight,
65-
) -> DispatchResult {
66-
let message = (*message).try_into().map_err(|()| Error::<T>::BadVersion)?;
67-
// Actually execute the XCM.
68-
Self::do_execute(origin, message)
69-
}
70-
71-
/// Send an XCM to another consensus system.
72-
#[pallet::call_index(1)]
73-
#[pallet::weight(Weight::default())]
74-
pub fn send(
75-
origin: OriginFor<T>,
76-
dest: Box<VersionedLocation>,
77-
message: Box<VersionedXcm<()>>,
78-
) -> DispatchResult {
79-
let dest = Location::try_from(*dest).map_err(|()| Error::<T>::BadVersion)?;
80-
let message: Xcm<()> = (*message).try_into().map_err(|()| Error::<T>::BadVersion)?;
81-
// Actually send the XCM.
82-
Self::do_send(origin, dest, message)
83-
}
84-
85-
/// Teleport some assets from the local chain to some destination chain.
86-
#[pallet::call_index(2)]
87-
#[pallet::weight(Weight::default())]
88-
pub fn teleport_assets(
89-
origin: OriginFor<T>,
90-
dest: Box<VersionedLocation>,
91-
beneficiary: Box<VersionedLocation>,
92-
assets: Box<VersionedAssets>,
93-
fee_asset_item: u32,
94-
) -> DispatchResult {
95-
let dest: Location = (*dest).try_into().map_err(|()| Error::<T>::BadVersion)?;
96-
let beneficiary: Location =
97-
(*beneficiary).try_into().map_err(|()| Error::<T>::BadVersion)?;
98-
let assets: Assets = (*assets).try_into().map_err(|()| Error::<T>::BadVersion)?;
99-
// Actually teleport the assets.
100-
Self::do_teleport_assets(origin, dest, beneficiary, assets, fee_asset_item)
101-
}
102-
103-
/// Transfer some assets from the local chain to the destination chain through their local,
104-
/// destination or remote reserve.
105-
#[pallet::call_index(3)]
106-
#[pallet::weight(Weight::default())]
107-
pub fn reserve_transfer_assets(
108-
origin: OriginFor<T>,
109-
dest: Box<VersionedLocation>,
110-
beneficiary: Box<VersionedLocation>,
111-
assets: Box<VersionedAssets>,
112-
fee_asset_item: u32,
113-
) -> DispatchResult {
114-
let dest: Location = (*dest).try_into().map_err(|()| Error::<T>::BadVersion)?;
115-
let beneficiary: Location =
116-
(*beneficiary).try_into().map_err(|()| Error::<T>::BadVersion)?;
117-
let assets: Assets = (*assets).try_into().map_err(|()| Error::<T>::BadVersion)?;
118-
// Actually reserve transfer the assets.
119-
Self::do_reserve_transfer_assets(origin, dest, beneficiary, assets, fee_asset_item)
120-
}
121-
}
122-
}
123-
124-
impl<T: Config> Pallet<T> {
125-
pub fn do_execute(origin: OriginFor<T>, message: Xcm<()>) -> DispatchResult {
126-
todo!("{:?}", message)
127-
}
128-
129-
/// Relay an XCM `message` from a given `interior` location in this context to a given `dest`
130-
/// location.
131-
pub fn do_send(origin: OriginFor<T>, dest: Location, mut message: Xcm<()>) -> DispatchResult {
132-
todo!("{:?} {:?}", dest, message)
133-
}
134-
135-
pub fn do_teleport_assets(
136-
origin: OriginFor<T>,
137-
dest: Location,
138-
beneficiary: Location,
139-
assets: Assets,
140-
// The index into `assets` of the item which should be used to pay fees.
141-
// We don't use this in our naive implementation.
142-
_fee_asset_item: u32,
143-
) -> DispatchResult {
144-
todo!("{:?} {:?} {:?}", dest, beneficiary, assets)
145-
}
146-
147-
pub fn do_reserve_transfer_assets(
148-
_origin: OriginFor<T>,
149-
_dest: Location,
150-
_beneficiary: Location,
151-
_assets: Assets,
152-
_fee_asset_item: u32,
153-
) -> DispatchResult {
154-
// There are 3 different reserve transfer scenarios:
155-
// - A local reserve transfer: reserve-transfer `asset` to `dest`, using local chain as
156-
// reserve.
157-
// - A destination reserve transfer: reserve-transfer `asset` to `dest`, using `dest` as
158-
// reserve.
159-
// - A remote reserve transfer: reserve-transfer `asset` to `dest`, using remote chain
160-
// `Location` as reserve.
161-
//
162-
// This is a lot to do in this workshop, but a welcome challenge for the reader to
163-
// implement.
164-
unimplemented!()
165-
}
166-
}

0 commit comments

Comments
 (0)