Skip to content

Commit a92db28

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

File tree

259 files changed

+221295
-1499
lines changed

Some content is hidden

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

259 files changed

+221295
-1499
lines changed

src/0/source/changes.diff

+213,521
Large diffs are not rendered by default.

src/10/solution/README.md

+2-4

src/10/solution/fundamentals/src/xcm_executor.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,6 @@ impl<Config: XcmConfig> ExecuteXcm for XcmExecutor<Config> {
194194
/// Execute an XCM from a given `origin`.
195195
fn execute(origin: impl Into<Location>, xcm: Xcm<()>) -> XcmResult {
196196
log::trace!(target: "xcm::execute", "xcm: {:?}", xcm);
197-
let origin: Location = origin.into();
198-
let mut vm = Self::new(origin);
199-
vm.process(xcm)
197+
todo!("{:?}", origin.into())
200198
}
201199
}

src/10/solution/solution.diff

+54-11
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,57 @@
11
diff --git a/fundamentals/src/xcm_executor.rs b/fundamentals/src/xcm_executor.rs
2-
index f03d79b..f7e8d2e 100644
2+
index d50d85a..f03d79b 100644
33
--- a/fundamentals/src/xcm_executor.rs
44
+++ b/fundamentals/src/xcm_executor.rs
5-
@@ -194,6 +194,8 @@ impl<Config: XcmConfig> ExecuteXcm for XcmExecutor<Config> {
6-
/// Execute an XCM from a given `origin`.
7-
fn execute(origin: impl Into<Location>, xcm: Xcm<()>) -> XcmResult {
8-
log::trace!(target: "xcm::execute", "xcm: {:?}", xcm);
9-
- todo!("{:?}", origin.into())
10-
+ let origin: Location = origin.into();
11-
+ let mut vm = Self::new(origin);
12-
+ vm.process(xcm)
13-
}
14-
}
5+
@@ -132,14 +132,50 @@ impl<Config: XcmConfig> XcmExecutor<Config> {
6+
// - `assets`: The asset(s) to remove from holding.
7+
// - `beneficiary`: The new owner for the assets.
8+
DepositAsset { assets, beneficiary } => {
9+
- todo!("{:?} {:?}", assets, beneficiary)
10+
+ let old_holding = self.holding.clone();
11+
+ let result = Config::TransactionalProcessor::process(|| {
12+
+ // Take assets from the holding registrar...
13+
+ let deposited = self.holding.saturating_take(assets);
14+
+ // ... and deposit them to the `beneficiary`.
15+
+ for asset in deposited.into_assets_iter() {
16+
+ Config::AssetTransactor::deposit_asset(
17+
+ &asset,
18+
+ &beneficiary,
19+
+ Some(&self.context),
20+
+ )?;
21+
+ }
22+
+ Ok(())
23+
+ });
24+
+ // If we were unable to execute `deposit_asset` in the `AssetTransactor`, we reset
25+
+ // the XCM Executor holding registrar since no operations took place.
26+
+ if Config::TransactionalProcessor::IS_TRANSACTIONAL && result.is_err() {
27+
+ self.holding = old_holding;
28+
+ }
29+
+ result
30+
},
31+
// Asset(s) (`assets`) have been destroyed on the `origin` system and equivalent assets
32+
// should be created and placed into the Holding Register.
33+
//
34+
// - `assets`: The asset(s) that are minted into the Holding Register.
35+
ReceiveTeleportedAsset(assets) => {
36+
- todo!("{:?}", assets)
37+
+ Config::TransactionalProcessor::process(|| {
38+
+ let origin = self.origin_ref().ok_or(XcmError::BadOrigin)?;
39+
+ // check whether we trust origin to teleport this asset to us via config trait.
40+
+ for asset in assets.inner() {
41+
+ // We should check that the asset can actually be teleported in (for this to
42+
+ // be in error, there would need to be an accounting violation by one of the
43+
+ // trusted chains, so it's unlikely, but we don't want to punish a possibly
44+
+ // innocent chain/user).
45+
+ Config::AssetTransactor::can_check_in(origin, asset, &self.context)?;
46+
+ Config::AssetTransactor::check_in(origin, asset, &self.context);
47+
+ }
48+
+ Ok(())
49+
+ })
50+
+ .and_then(|_| {
51+
+ // ...and place into holding.
52+
+ self.holding.subsume_assets(assets.into());
53+
+ Ok(())
54+
+ })
55+
},
56+
// In this workshop, we won't be implementing every instruction, just the ones above...
57+
// Our executor will simply panic if you try to execute other instructions.

src/10/template/README.md

+46-3

src/10/template/fundamentals/src/xcm_executor.rs

+2-38
Original file line numberDiff line numberDiff line change
@@ -132,50 +132,14 @@ impl<Config: XcmConfig> XcmExecutor<Config> {
132132
// - `assets`: The asset(s) to remove from holding.
133133
// - `beneficiary`: The new owner for the assets.
134134
DepositAsset { assets, beneficiary } => {
135-
let old_holding = self.holding.clone();
136-
let result = Config::TransactionalProcessor::process(|| {
137-
// Take assets from the holding registrar...
138-
let deposited = self.holding.saturating_take(assets);
139-
// ... and deposit them to the `beneficiary`.
140-
for asset in deposited.into_assets_iter() {
141-
Config::AssetTransactor::deposit_asset(
142-
&asset,
143-
&beneficiary,
144-
Some(&self.context),
145-
)?;
146-
}
147-
Ok(())
148-
});
149-
// If we were unable to execute `deposit_asset` in the `AssetTransactor`, we reset
150-
// the XCM Executor holding registrar since no operations took place.
151-
if Config::TransactionalProcessor::IS_TRANSACTIONAL && result.is_err() {
152-
self.holding = old_holding;
153-
}
154-
result
135+
todo!("{:?} {:?}", assets, beneficiary)
155136
},
156137
// Asset(s) (`assets`) have been destroyed on the `origin` system and equivalent assets
157138
// should be created and placed into the Holding Register.
158139
//
159140
// - `assets`: The asset(s) that are minted into the Holding Register.
160141
ReceiveTeleportedAsset(assets) => {
161-
Config::TransactionalProcessor::process(|| {
162-
let origin = self.origin_ref().ok_or(XcmError::BadOrigin)?;
163-
// check whether we trust origin to teleport this asset to us via config trait.
164-
for asset in assets.inner() {
165-
// We should check that the asset can actually be teleported in (for this to
166-
// be in error, there would need to be an accounting violation by one of the
167-
// trusted chains, so it's unlikely, but we don't want to punish a possibly
168-
// innocent chain/user).
169-
Config::AssetTransactor::can_check_in(origin, asset, &self.context)?;
170-
Config::AssetTransactor::check_in(origin, asset, &self.context);
171-
}
172-
Ok(())
173-
})
174-
.and_then(|_| {
175-
// ...and place into holding.
176-
self.holding.subsume_assets(assets.into());
177-
Ok(())
178-
})
142+
todo!("{:?}", assets)
179143
},
180144
// In this workshop, we won't be implementing every instruction, just the ones above...
181145
// Our executor will simply panic if you try to execute other instructions.

src/11/README.md

+61-2
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/11/solution/README.md

+5
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/11/solution/solution.diff

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
diff --git a/fundamentals/src/xcm_executor.rs b/fundamentals/src/xcm_executor.rs
2+
index f03d79b..f7e8d2e 100644
3+
--- a/fundamentals/src/xcm_executor.rs
4+
+++ b/fundamentals/src/xcm_executor.rs
5+
@@ -194,6 +194,8 @@ impl<Config: XcmConfig> ExecuteXcm for XcmExecutor<Config> {
6+
/// Execute an XCM from a given `origin`.
7+
fn execute(origin: impl Into<Location>, xcm: Xcm<()>) -> XcmResult {
8+
log::trace!(target: "xcm::execute", "xcm: {:?}", xcm);
9+
- todo!("{:?}", origin.into())
10+
+ let origin: Location = origin.into();
11+
+ let mut vm = Self::new(origin);
12+
+ vm.process(xcm)
13+
}
14+
}
File renamed without changes.

src/11/source/README.md

-3
This file was deleted.

src/11/source/changes.diff

Whitespace-only changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/11/template/README.md

+5

src/6/solution/fundamentals/src/xcm_executor.rs src/11/template/fundamentals/src/xcm_executor.rs

+71-5
Original file line numberDiff line numberDiff line change
@@ -79,37 +79,103 @@ impl<Config: XcmConfig> XcmExecutor<Config> {
7979
// - `assets`: The asset(s) to be withdrawn.
8080
// - `beneficiary`: The new owner for the assets.
8181
TransferAsset { assets, beneficiary } => {
82-
todo!("{:?} {:?}", assets, beneficiary)
82+
Config::TransactionalProcessor::process(|| {
83+
// Take `assets` from the origin account (on-chain) and place into dest account.
84+
let origin = self.origin_ref().ok_or(XcmError::BadOrigin)?;
85+
// Transfer each asset using the `AssetTransactor`.
86+
for asset in assets.inner() {
87+
Config::AssetTransactor::transfer_asset(
88+
&asset,
89+
origin,
90+
&beneficiary,
91+
&self.context,
92+
)?;
93+
}
94+
Ok(())
95+
})
8396
},
8497
// Withdraw asset(s) (`assets`) from the ownership of `origin` and place them into the
8598
// Holding Register.
8699
//
87100
// - `assets`: The asset(s) to be withdrawn into holding.
88101
WithdrawAsset(assets) => {
89-
todo!("{:?}", assets)
102+
Config::TransactionalProcessor::process(|| {
103+
let origin = self.origin_ref().ok_or(XcmError::BadOrigin)?;
104+
// Take `assets` from the origin account (on-chain)...
105+
for asset in assets.inner() {
106+
Config::AssetTransactor::withdraw_asset(
107+
asset,
108+
origin,
109+
Some(&self.context),
110+
)?;
111+
}
112+
Ok(())
113+
})
114+
.and_then(|_| {
115+
// ...and place into holding.
116+
self.holding.subsume_assets(assets.into());
117+
Ok(())
118+
})
90119
},
91120
// Reduce Holding by up to the given assets.
92121
//
93122
// Holding is reduced by as much as possible up to the assets in the parameter. It is
94123
// not an error if the Holding does not contain the assets (to make this an error, use
95124
// `ExpectAsset` prior).
96125
BurnAsset(assets) => {
97-
todo!("{:?}", assets)
126+
self.holding.saturating_take(assets.into());
127+
Ok(())
98128
},
99129
// Remove the asset(s) (`assets`) from the Holding Register and place equivalent assets
100130
// under the ownership of `beneficiary` within this consensus system.
101131
//
102132
// - `assets`: The asset(s) to remove from holding.
103133
// - `beneficiary`: The new owner for the assets.
104134
DepositAsset { assets, beneficiary } => {
105-
todo!("{:?} {:?}", assets, beneficiary)
135+
let old_holding = self.holding.clone();
136+
let result = Config::TransactionalProcessor::process(|| {
137+
// Take assets from the holding registrar...
138+
let deposited = self.holding.saturating_take(assets);
139+
// ... and deposit them to the `beneficiary`.
140+
for asset in deposited.into_assets_iter() {
141+
Config::AssetTransactor::deposit_asset(
142+
&asset,
143+
&beneficiary,
144+
Some(&self.context),
145+
)?;
146+
}
147+
Ok(())
148+
});
149+
// If we were unable to execute `deposit_asset` in the `AssetTransactor`, we reset
150+
// the XCM Executor holding registrar since no operations took place.
151+
if Config::TransactionalProcessor::IS_TRANSACTIONAL && result.is_err() {
152+
self.holding = old_holding;
153+
}
154+
result
106155
},
107156
// Asset(s) (`assets`) have been destroyed on the `origin` system and equivalent assets
108157
// should be created and placed into the Holding Register.
109158
//
110159
// - `assets`: The asset(s) that are minted into the Holding Register.
111160
ReceiveTeleportedAsset(assets) => {
112-
todo!("{:?}", assets)
161+
Config::TransactionalProcessor::process(|| {
162+
let origin = self.origin_ref().ok_or(XcmError::BadOrigin)?;
163+
// check whether we trust origin to teleport this asset to us via config trait.
164+
for asset in assets.inner() {
165+
// We should check that the asset can actually be teleported in (for this to
166+
// be in error, there would need to be an accounting violation by one of the
167+
// trusted chains, so it's unlikely, but we don't want to punish a possibly
168+
// innocent chain/user).
169+
Config::AssetTransactor::can_check_in(origin, asset, &self.context)?;
170+
Config::AssetTransactor::check_in(origin, asset, &self.context);
171+
}
172+
Ok(())
173+
})
174+
.and_then(|_| {
175+
// ...and place into holding.
176+
self.holding.subsume_assets(assets.into());
177+
Ok(())
178+
})
113179
},
114180
// In this workshop, we won't be implementing every instruction, just the ones above...
115181
// Our executor will simply panic if you try to execute other instructions.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)