Skip to content

Commit

Permalink
mdBook generated from gitorial
Browse files Browse the repository at this point in the history
  • Loading branch information
shawntabrizi committed Aug 4, 2024
1 parent e81f794 commit 94facbe
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 20 deletions.
4 changes: 1 addition & 3 deletions src/12/template/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<
Expand Down
9 changes: 4 additions & 5 deletions src/2/source/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 --
}
Expand Down Expand Up @@ -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

Expand All @@ -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<T>(core::marker::PhantomData<T>);
Expand Down
2 changes: 1 addition & 1 deletion src/25/source/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
11 changes: 6 additions & 5 deletions src/30/solution/solution.diff
Original file line number Diff line number Diff line change
@@ -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<T: Config> Pallet<T> {
@@ -79,22 +79,14 @@ impl<T: Config> Pallet<T> {
kitty_id: [u8; 32],
price: BalanceOf<T>,
) -> DispatchResult {
Expand All @@ -24,14 +27,12 @@ index 72c76b0..85ff781 100644
+ ensure!(price >= real_price, Error::<T>::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)?;

Expand Down
2 changes: 1 addition & 1 deletion src/30/solution/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -82,7 +83,6 @@ impl<T: Config> Pallet<T> {
let real_price = kitty.price.ok_or(Error::<T>::NotForSale)?;
ensure!(price >= real_price, Error::<T>::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)?;

Expand Down
2 changes: 1 addition & 1 deletion src/30/template/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
3 changes: 2 additions & 1 deletion src/30/template/src/impls.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -84,7 +86,6 @@ impl<T: Config> Pallet<T> {
*/

/* 🚧 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.
Expand Down
14 changes: 11 additions & 3 deletions src/30/template/template.diff
Original file line number Diff line number Diff line change
@@ -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<T: Config> Pallet<T> {
@@ -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<T: Config> Pallet<T> {
kitty_id: [u8; 32],
price: BalanceOf<T>,
) -> DispatchResult {
Expand All @@ -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.
Expand Down

0 comments on commit 94facbe

Please sign in to comment.