From 94facbefda975c88bf27939baac1ade5dd9c6c37 Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Sat, 3 Aug 2024 21:28:06 -0400 Subject: [PATCH] mdBook generated from gitorial --- src/12/template/README.md | 4 +--- src/2/source/README.md | 9 ++++----- src/25/source/README.md | 2 +- src/30/solution/solution.diff | 11 ++++++----- src/30/solution/src/impls.rs | 2 +- src/30/template/README.md | 2 +- src/30/template/src/impls.rs | 3 ++- src/30/template/template.diff | 14 +++++++++++--- 8 files changed, 27 insertions(+), 20 deletions(-) diff --git a/src/12/template/README.md b/src/12/template/README.md index 12a08ba9..09453cad 100644 --- a/src/12/template/README.md +++ b/src/12/template/README.md @@ -6,9 +6,7 @@ But there are actually more ways you can configure the `StorageValue` to increas ## Storage Value Definition -Let's look at the definition of a `StorageValue`: - -https://docs.rs/frame-support/37.0.0/frame_support/storage/types/struct.StorageValue.html +Let's look at the definition of a [`StorageValue`](https://docs.rs/frame-support/37.0.0/frame_support/storage/types/struct.StorageValue.html): ```rust pub struct StorageValue< diff --git a/src/2/source/README.md b/src/2/source/README.md index 149e9ab0..5cbefa1a 100644 --- a/src/2/source/README.md +++ b/src/2/source/README.md @@ -45,7 +45,7 @@ Our starting template includes all the basic macros used for developing a FRAME The entrypoint for all the FRAME macros is can be seen here: ```rust -#[frame_support::pallet(dev_mode)] +#[frame::pallet(dev_mode)] pub mod pallet { // -- snip -- } @@ -78,7 +78,7 @@ pub mod pallet { We can now design the `#[macro_entrypoint]` to keep track of all data inside of the `mod pallet` container, and that means we can now design `#[macro_1]` and `#[macro_2]` to have context of one another, and interact with each other too. -The unfortunate limitation here is that wherever we want to use FRAME macros, we must basically do it in a single file and all enclosed by the `#[frame_support::pallet]` macro entrypoint. +The unfortunate limitation here is that wherever we want to use FRAME macros, we must basically do it in a single file and all enclosed by the `#[frame::pallet]` macro entrypoint. We will go over each of the FRAME macros throughout this tutorial @@ -89,10 +89,9 @@ While the template is already very minimal, you can mentally break it down like: ```rust pub use pallet::*; -#[frame_support::pallet] +#[frame::pallet] pub mod pallet { - use frame_support::pallet_prelude::*; - use frame_system::pallet_prelude::*; + use frame::prelude::*; #[pallet::pallet] pub struct Pallet(core::marker::PhantomData); diff --git a/src/25/source/README.md b/src/25/source/README.md index 71ebb72a..3d253304 100644 --- a/src/25/source/README.md +++ b/src/25/source/README.md @@ -107,7 +107,7 @@ The power of loose coupling may not be immediately obvious, but as you get deepe ## Your Turn -Import the `Inspect` and `Mutate` traits from `frame_support::traits::fungible`. +Import the `Inspect` and `Mutate` traits from `frame::traits::fungible`. Introduce the `NativeBalance` associated type to your `trait Config` using these traits. diff --git a/src/30/solution/solution.diff b/src/30/solution/solution.diff index 648b88d7..b9c05319 100644 --- a/src/30/solution/solution.diff +++ b/src/30/solution/solution.diff @@ -1,16 +1,19 @@ diff --git a/src/impls.rs b/src/impls.rs -index 72c76b0..85ff781 100644 +index 1561bdd..f8d2cb6 100644 --- a/src/impls.rs +++ b/src/impls.rs -@@ -1,6 +1,7 @@ +@@ -1,8 +1,8 @@ use super::*; use frame::prelude::*; use frame::primitives::BlakeTwo256; +-/* 🚧 TODO 🚧: Import `frame::traits::fungible::Mutate`. */ +-/* 🚧 TODO 🚧: Import `frame::traits::tokens::Preservation`. */ +use frame::traits::fungible::Mutate; ++use frame::traits::tokens::Preservation; use frame::traits::Hash; // Learn about internal functions. -@@ -77,23 +78,15 @@ impl Pallet { +@@ -79,22 +79,14 @@ impl Pallet { kitty_id: [u8; 32], price: BalanceOf, ) -> DispatchResult { @@ -24,14 +27,12 @@ index 72c76b0..85ff781 100644 + ensure!(price >= real_price, Error::::MaxPriceTooLow); - /* 🚧 TODO 🚧: Execute the transfers: -- - Import `use frame_support::traits::tokens::Preservation;`, which is used for balance transfer. - - Use `T::NativeBalance` to `transfer` from the `buyer` to the `kitty.owner`. - - The amount transferred should be the `real_price`. - - Use `Preservation::Preserve` to ensure the buyer account stays alive. - - Use `Self::do_transfer` to transfer from the `kitty.owner` to the `buyer` with `kitty_id`. - - Remember to propagate up all results from these functions with `?`. - */ -+ use frame::traits::tokens::Preservation; + T::NativeBalance::transfer(&buyer, &kitty.owner, real_price, Preservation::Preserve)?; + Self::do_transfer(kitty.owner, buyer.clone(), kitty_id)?; diff --git a/src/30/solution/src/impls.rs b/src/30/solution/src/impls.rs index 85ff7813..f8d2cb6a 100644 --- a/src/30/solution/src/impls.rs +++ b/src/30/solution/src/impls.rs @@ -2,6 +2,7 @@ use super::*; use frame::prelude::*; use frame::primitives::BlakeTwo256; use frame::traits::fungible::Mutate; +use frame::traits::tokens::Preservation; use frame::traits::Hash; // Learn about internal functions. @@ -82,7 +83,6 @@ impl Pallet { let real_price = kitty.price.ok_or(Error::::NotForSale)?; ensure!(price >= real_price, Error::::MaxPriceTooLow); - use frame::traits::tokens::Preservation; T::NativeBalance::transfer(&buyer, &kitty.owner, real_price, Preservation::Preserve)?; Self::do_transfer(kitty.owner, buyer.clone(), kitty_id)?; diff --git a/src/30/template/README.md b/src/30/template/README.md index c9d24512..30f07c1f 100644 --- a/src/30/template/README.md +++ b/src/30/template/README.md @@ -37,7 +37,7 @@ fn transfer( > NOTE: To access this function, you will need import the trait to bring it in scope. Otherwise you will get an error that the function does not exist. So don't forget to include: > > ```rust -> use frame_support::traits::fungible::Mutate; +> use frame::traits::fungible::Mutate; > ``` The first 3 parameters here are easy enough to understand: `source`, `dest`, and `amount`. diff --git a/src/30/template/src/impls.rs b/src/30/template/src/impls.rs index 72c76b04..1561bddd 100644 --- a/src/30/template/src/impls.rs +++ b/src/30/template/src/impls.rs @@ -1,6 +1,8 @@ use super::*; use frame::prelude::*; use frame::primitives::BlakeTwo256; +/* 🚧 TODO 🚧: Import `frame::traits::fungible::Mutate`. */ +/* 🚧 TODO 🚧: Import `frame::traits::tokens::Preservation`. */ use frame::traits::Hash; // Learn about internal functions. @@ -84,7 +86,6 @@ impl Pallet { */ /* 🚧 TODO 🚧: Execute the transfers: - - Import `use frame_support::traits::tokens::Preservation;`, which is used for balance transfer. - Use `T::NativeBalance` to `transfer` from the `buyer` to the `kitty.owner`. - The amount transferred should be the `real_price`. - Use `Preservation::Preserve` to ensure the buyer account stays alive. diff --git a/src/30/template/template.diff b/src/30/template/template.diff index eea7cbd8..a3672f6b 100644 --- a/src/30/template/template.diff +++ b/src/30/template/template.diff @@ -1,8 +1,17 @@ diff --git a/src/impls.rs b/src/impls.rs -index f7fda1e..72c76b0 100644 +index f7fda1e..1561bdd 100644 --- a/src/impls.rs +++ b/src/impls.rs -@@ -77,6 +77,22 @@ impl Pallet { +@@ -1,6 +1,8 @@ + use super::*; + use frame::prelude::*; + use frame::primitives::BlakeTwo256; ++/* 🚧 TODO 🚧: Import `frame::traits::fungible::Mutate`. */ ++/* 🚧 TODO 🚧: Import `frame::traits::tokens::Preservation`. */ + use frame::traits::Hash; + + // Learn about internal functions. +@@ -77,6 +79,21 @@ impl Pallet { kitty_id: [u8; 32], price: BalanceOf, ) -> DispatchResult { @@ -13,7 +22,6 @@ index f7fda1e..72c76b0 100644 + */ + + /* 🚧 TODO 🚧: Execute the transfers: -+ - Import `use frame_support::traits::tokens::Preservation;`, which is used for balance transfer. + - Use `T::NativeBalance` to `transfer` from the `buyer` to the `kitty.owner`. + - The amount transferred should be the `real_price`. + - Use `Preservation::Preserve` to ensure the buyer account stays alive.