From f0f8246cd8980cc7f6002940198b295c9d1ce5d3 Mon Sep 17 00:00:00 2001 From: "Yung Beef 4.2" <89395745+Yung-Beef@users.noreply.github.com> Date: Mon, 28 Oct 2024 15:00:41 -0300 Subject: [PATCH 01/33] Update tests.rs I guess this one will need to be copied to all of the future steps --- steps/13/src/tests.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/steps/13/src/tests.rs b/steps/13/src/tests.rs index d3e7ab78..e271b018 100644 --- a/steps/13/src/tests.rs +++ b/steps/13/src/tests.rs @@ -127,5 +127,7 @@ fn count_for_kitties_created_correctly() { CountForKitties::::set(Some(1337u32)); // You can `put` the value directly with a `u32`. CountForKitties::::put(1337u32); + // Check that the value is now in storage. + assert_eq!(CountForKitties::::get(), Some(1337u32)); }) } From 08e5bba8e40c32ad5558fb27a6a879c10d8b2871 Mon Sep 17 00:00:00 2001 From: "Yung Beef 4.2" <89395745+Yung-Beef@users.noreply.github.com> Date: Mon, 28 Oct 2024 15:02:42 -0300 Subject: [PATCH 02/33] Update README.md --- steps/11/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/steps/11/README.md b/steps/11/README.md index e077a903..dda62b5b 100644 --- a/steps/11/README.md +++ b/steps/11/README.md @@ -29,7 +29,7 @@ These properties make hash functions key for ensuring data integrity and uniquen Due to the properties of a Hash, it is often referred to as a fingerprint. -For context, a 32-byte hash has 2^32 different possible outputs. This nearly as many atoms as there are in the whole universe! +For context, a 32-byte hash has 2^32 different possible outputs. This is nearly as many atoms as there are in the whole universe! This uniqueness property helps blockchain nodes come to consensus with one another. From ee7cb24070ecc0f55af68296b8ea8e3e93fa3319 Mon Sep 17 00:00:00 2001 From: "Yung Beef 4.2" <89395745+Yung-Beef@users.noreply.github.com> Date: Mon, 28 Oct 2024 15:15:12 -0300 Subject: [PATCH 03/33] Update README.md --- steps/16/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/steps/16/README.md b/steps/16/README.md index 849975fb..316589e6 100644 --- a/steps/16/README.md +++ b/steps/16/README.md @@ -2,7 +2,7 @@ If you look into the history of "hacks" and "bugs" that happen in the blockchain world, a lot of it is associated with some kind of "unsafe" code. -Keeping our blockchain logic safe, and Rust is designed to handle it well. +We need to keep our blockchain logic safe, and Rust is designed to handle it well. ## Errors From edfb8ab15e2c5ddf2a21ea484b29e0004e5b54be Mon Sep 17 00:00:00 2001 From: "Yung Beef 4.2" <89395745+Yung-Beef@users.noreply.github.com> Date: Tue, 29 Oct 2024 11:22:53 -0300 Subject: [PATCH 04/33] Update README.md --- steps/20/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/steps/20/README.md b/steps/20/README.md index 7b1ddf71..6a62e06a 100644 --- a/steps/20/README.md +++ b/steps/20/README.md @@ -19,6 +19,8 @@ Each `Key` can store a separate `Value`, which makes maps super useful. In this case `[u8; 32]` represents some unique identifier for each Kitty we will store, and `()` is simply a placeholder type for now. +Note that each storage instance needs its own `#[pallet::storage]` macro. + ## Conceptual The key difference between a `StorageValue` and a `StorageMap` is: From 3d49eea40e011c884998a69ed514c3e5975c4bd1 Mon Sep 17 00:00:00 2001 From: "Yung Beef 4.2" <89395745+Yung-Beef@users.noreply.github.com> Date: Tue, 29 Oct 2024 11:31:20 -0300 Subject: [PATCH 05/33] Update lib.rs --- steps/22/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/steps/22/src/lib.rs b/steps/22/src/lib.rs index 2a83b473..ec51fe3a 100644 --- a/steps/22/src/lib.rs +++ b/steps/22/src/lib.rs @@ -40,8 +40,8 @@ pub mod pallet { pub fn create_kitty(origin: OriginFor) -> DispatchResult { let who = ensure_signed(origin)?; /* 🚧 TODO 🚧: - - Create `const default_id`, which type `[u8; 32]` and has value `[0u8; 32]`. - - Pass `default_id` to the `mint` function as a second parameter. + - Create `const DEFAULT_ID`, which type `[u8; 32]` and has value `[0u8; 32]`. + - Pass `DEFAULT_ID` to the `mint` function as a second parameter. */ Self::mint(who)?; Ok(()) From f1bfdde0393f80d76f49abbad2fee88526a73ae8 Mon Sep 17 00:00:00 2001 From: "Yung Beef 4.2" <89395745+Yung-Beef@users.noreply.github.com> Date: Tue, 29 Oct 2024 11:40:43 -0300 Subject: [PATCH 06/33] Update lib.rs id suddenly changes to dna in the next step with no mention of it --- steps/22/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/steps/22/src/lib.rs b/steps/22/src/lib.rs index ec51fe3a..780e6bc6 100644 --- a/steps/22/src/lib.rs +++ b/steps/22/src/lib.rs @@ -40,8 +40,8 @@ pub mod pallet { pub fn create_kitty(origin: OriginFor) -> DispatchResult { let who = ensure_signed(origin)?; /* 🚧 TODO 🚧: - - Create `const DEFAULT_ID`, which type `[u8; 32]` and has value `[0u8; 32]`. - - Pass `DEFAULT_ID` to the `mint` function as a second parameter. + - Create a `dna` variable that this kitty will have, which has a value of `[0u8; 32]`. + - Pass `dna` to the `mint` function as a second parameter. */ Self::mint(who)?; Ok(()) From 2b2771d58c357617d9473ee9279e99b2eaaa3121 Mon Sep 17 00:00:00 2001 From: "Yung Beef 4.2" <89395745+Yung-Beef@users.noreply.github.com> Date: Tue, 29 Oct 2024 11:41:07 -0300 Subject: [PATCH 07/33] Update impls.rs --- steps/22/src/impls.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/steps/22/src/impls.rs b/steps/22/src/impls.rs index 89c7306a..44437026 100644 --- a/steps/22/src/impls.rs +++ b/steps/22/src/impls.rs @@ -2,11 +2,11 @@ use super::*; use frame::prelude::*; impl Pallet { - /* 🚧 TODO 🚧: Update this function signature to include `id` which is type `[u8; 32]`. */ + /* 🚧 TODO 🚧: Update this function signature to include `dna` which is type `[u8; 32]`. */ pub fn mint(owner: T::AccountId) -> DispatchResult { let current_count: u32 = CountForKitties::::get(); let new_count = current_count.checked_add(1).ok_or(Error::::TooManyKitties)?; - /* 🚧 TODO 🚧: In the `Kitties` map, under the key `id`, insert `()`. */ + /* 🚧 TODO 🚧: In the `Kitties` map, under the key `dna`, insert `()`. */ CountForKitties::::set(new_count); Self::deposit_event(Event::::Created { owner }); Ok(()) From c0914b353c5197ff4aa35de19dd61d47ab963a1a Mon Sep 17 00:00:00 2001 From: "Yung Beef 4.2" <89395745+Yung-Beef@users.noreply.github.com> Date: Tue, 29 Oct 2024 11:53:52 -0300 Subject: [PATCH 08/33] Update README.md Couldn't create a kitty struct in tests.rs without making the struct fields public --- steps/27/README.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/steps/27/README.md b/steps/27/README.md index 9662b30f..dea845d6 100644 --- a/steps/27/README.md +++ b/steps/27/README.md @@ -8,8 +8,8 @@ Creating a new struct in Rust is pretty straight forward. ```rust pub struct Kitty { - dna: [u8; 32], - owner: u32, + pub dna: [u8; 32], + pub owner: u32, } ``` @@ -38,8 +38,8 @@ The first, and most verbose option in our situation is to make the struct generi ```rust pub struct Kitty { - dna: [u8; 32], - owner: AccountId, + pub dna: [u8; 32], + pub owner: AccountId, } ``` @@ -47,9 +47,9 @@ If we want to use multiple generic types, we could just keep extending this patt ```rust pub struct Kitty { - dna: [u8; 32], - owner: AccountId, - created: BlockNumber, + pub dna: [u8; 32], + pub owner: AccountId, + pub created: BlockNumber, } ``` @@ -69,8 +69,8 @@ Let's look how that might look like: ```rust pub struct Kitty { - dna: [u8; 32], - owner: T::AccountId, + pub dna: [u8; 32], + pub owner: T::AccountId, } ``` From 42828766fdd3994b11011d798723085507368d53 Mon Sep 17 00:00:00 2001 From: "Yung Beef 4.2" <89395745+Yung-Beef@users.noreply.github.com> Date: Tue, 29 Oct 2024 11:55:51 -0300 Subject: [PATCH 09/33] Update tests.rs --- steps/27/src/tests.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/steps/27/src/tests.rs b/steps/27/src/tests.rs index 5caa1349..38392b03 100644 --- a/steps/27/src/tests.rs +++ b/steps/27/src/tests.rs @@ -27,6 +27,9 @@ type Block = frame_system::mocking::MockBlock; // We create the constants `ALICE` and `BOB` to make it clear when we are representing users below. const ALICE: u64 = 1; const BOB: u64 = 2; +/* 🚧 TODO 🚧: + - Create `const DEFAULT_KITTY` with a `dna` of [0u8; 32] and an `owner` of 0 };. +*/ // Our blockchain tests only need 3 Pallets: // 1. System: Which is included with every FRAME runtime. From ecfe48834b061c37e86eb9e8137f0d68a82536a6 Mon Sep 17 00:00:00 2001 From: "Yung Beef 4.2" <89395745+Yung-Beef@users.noreply.github.com> Date: Tue, 29 Oct 2024 12:50:44 -0300 Subject: [PATCH 10/33] Update README.md --- steps/31/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/steps/31/README.md b/steps/31/README.md index 48680d7e..37f9a647 100644 --- a/steps/31/README.md +++ b/steps/31/README.md @@ -37,7 +37,7 @@ let unique_payload = (item1, item2, item3); // To use the `hash_of` API, we need to bring the `Hash` trait into scope. use frame::traits::Hash; // Hash that object to get a unique identifier. -let hash: [u8; 32] = BlakeTwo256::hash_of(&unique_payload).into(). +let hash: [u8; 32] = BlakeTwo256::hash_of(&unique_payload).into(); ``` The `hash_of` API comes from the `Hash` trait and takes any `encode`-able object, and returns a `H256`, which is a 256-bit hash. As you can see in the code above, it is easy to convert that to a `[u8; 32]` by just calling `.into()`, since these two types are equivalent. From ed6c010b3644546cec73325217baee236c1e1dd6 Mon Sep 17 00:00:00 2001 From: "Yung Beef 4.2" <89395745+Yung-Beef@users.noreply.github.com> Date: Tue, 29 Oct 2024 12:53:49 -0300 Subject: [PATCH 11/33] Update impls.rs --- steps/33/src/impls.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/steps/33/src/impls.rs b/steps/33/src/impls.rs index 71b538b6..05c43d7a 100644 --- a/steps/33/src/impls.rs +++ b/steps/33/src/impls.rs @@ -4,7 +4,7 @@ use frame::primitives::BlakeTwo256; use frame::traits::Hash; impl Pallet { - // Generates and returns DNA and Sex + // Generates and returns DNA pub fn gen_dna() -> [u8; 32] { // Create randomness payload. Multiple kitties can be generated in the same block, // retaining uniqueness. From 32e980429598c4ea72ddee9a4f895fc3578ca281 Mon Sep 17 00:00:00 2001 From: "Yung Beef 4.2" <89395745+Yung-Beef@users.noreply.github.com> Date: Tue, 29 Oct 2024 15:46:20 -0300 Subject: [PATCH 12/33] Update impls.rs --- steps/35/src/impls.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/steps/35/src/impls.rs b/steps/35/src/impls.rs index 9e79118b..f8f58b46 100644 --- a/steps/35/src/impls.rs +++ b/steps/35/src/impls.rs @@ -4,7 +4,7 @@ use frame::primitives::BlakeTwo256; use frame::traits::Hash; impl Pallet { - // Generates and returns DNA and Sex + // Generates and returns DNA pub fn gen_dna() -> [u8; 32] { // Create randomness payload. Multiple kitties can be generated in the same block, // retaining uniqueness. From ed98ee52de3664f2f4b58322bed3310881d33442 Mon Sep 17 00:00:00 2001 From: "Yung Beef 4.2" <89395745+Yung-Beef@users.noreply.github.com> Date: Tue, 29 Oct 2024 15:53:54 -0300 Subject: [PATCH 13/33] Update impls.rs --- steps/38/src/impls.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/steps/38/src/impls.rs b/steps/38/src/impls.rs index 34eae393..b56a0a8b 100644 --- a/steps/38/src/impls.rs +++ b/steps/38/src/impls.rs @@ -42,7 +42,7 @@ impl Pallet { - `kitty_id` which is `[u8; 32]`. - It returns a `DispatchResult` - The inner logic for now is: - - Call `Self::dispatch_event` on and emit `Event:::Transferred` with params. + - Call `Self::ddeposit_event` on and emit `Event:::Transferred` with params. - Return `Ok(())`. */ } From 2189bf551014e9484be9610fcc2224ddd2130de9 Mon Sep 17 00:00:00 2001 From: "Yung Beef 4.2" <89395745+Yung-Beef@users.noreply.github.com> Date: Tue, 29 Oct 2024 17:09:49 -0300 Subject: [PATCH 14/33] Update impls.rs --- steps/38/src/impls.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/steps/38/src/impls.rs b/steps/38/src/impls.rs index b56a0a8b..2ab0d08d 100644 --- a/steps/38/src/impls.rs +++ b/steps/38/src/impls.rs @@ -5,7 +5,7 @@ use frame::traits::Hash; // Learn about internal functions. impl Pallet { - // Generates and returns DNA and Sex + // Generates and returns DNA pub fn gen_dna() -> [u8; 32] { // Create randomness payload. Multiple kitties can be generated in the same block, // retaining uniqueness. From 13d6c68ac7988ee11be0ca2925e90234c2b692ad Mon Sep 17 00:00:00 2001 From: "Yung Beef 4.2" <89395745+Yung-Beef@users.noreply.github.com> Date: Tue, 29 Oct 2024 17:11:02 -0300 Subject: [PATCH 15/33] Update impls.rs --- steps/40/src/impls.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/steps/40/src/impls.rs b/steps/40/src/impls.rs index 749b40c3..e760af12 100644 --- a/steps/40/src/impls.rs +++ b/steps/40/src/impls.rs @@ -5,7 +5,7 @@ use frame::traits::Hash; // Learn about internal functions. impl Pallet { - // Generates and returns DNA and Sex + // Generates and returns DNA pub fn gen_dna() -> [u8; 32] { // Create randomness payload. Multiple kitties can be generated in the same block, // retaining uniqueness. From 165550cb9aa42e51e0e59bd3235ffc63c1ba92e6 Mon Sep 17 00:00:00 2001 From: "Yung Beef 4.2" <89395745+Yung-Beef@users.noreply.github.com> Date: Tue, 29 Oct 2024 17:34:20 -0300 Subject: [PATCH 16/33] Update README.md --- steps/42/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/steps/42/README.md b/steps/42/README.md index 90877e24..82a11584 100644 --- a/steps/42/README.md +++ b/steps/42/README.md @@ -101,7 +101,7 @@ T::NativeBalance::mint_into(alice, amount)?; T::NativeBalance::transfer(alice, bob, amount, Preserve)?; ``` -The key difference here is that we do NOT assume that these APIs must from from specifically `pallet_balances`. If you wanted to use another pallet in the `polkadot-sdk` ecosystem which provides these same functions, you can use it! Our pallet is NOT tightly coupled to which pallet provides access to the `NativeBalance`, it only requires that there is something implementing the `Inspect` and `Mutate` traits. +The key difference here is that we do NOT assume that these APIs must come from specifically `pallet_balances`. If you wanted to use another pallet in the `polkadot-sdk` ecosystem which provides these same functions, you can use it! Our pallet is NOT tightly coupled to which pallet provides access to the `NativeBalance`, it only requires that there is something implementing the `Inspect` and `Mutate` traits. The power of loose coupling may not be immediately obvious, but as you get deeper into developing in the Polkadot ecosystem, you will start to realize how powerful this approach can be. From d63f8ca547652aa363f741a06879bafa2b0f068c Mon Sep 17 00:00:00 2001 From: "Yung Beef 4.2" <89395745+Yung-Beef@users.noreply.github.com> Date: Tue, 29 Oct 2024 17:45:38 -0300 Subject: [PATCH 17/33] Update README.md --- steps/44/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/steps/44/README.md b/steps/44/README.md index 7f8adbac..a680fdc2 100644 --- a/steps/44/README.md +++ b/steps/44/README.md @@ -20,7 +20,7 @@ Let's look at how we would interact with this generic type, and solve many of th The `Balance` type is ultimately configured inside `pallet_balances`, and remember, we don't have direct access to that pallet because we used loose coupling. -The way we can access the `Balance` type is through the `Inspect` trait of the `NativeBalance` associated type. Accessing it kind of funny, which is why we commonly introduce a `BalanceOf` alias type like so: +The way we can access the `Balance` type is through the `Inspect` trait of the `NativeBalance` associated type. Accessing it is kind of funny, which is why we commonly introduce a `BalanceOf` alias type like so: ```rust // Allows easy access our Pallet's `Balance` type. Comes from `Fungible` interface. From 86fffacb694c87e8e7efbf2139f2e043d7ef4732 Mon Sep 17 00:00:00 2001 From: "Yung Beef 4.2" <89395745+Yung-Beef@users.noreply.github.com> Date: Tue, 29 Oct 2024 17:51:48 -0300 Subject: [PATCH 18/33] Update tests.rs --- steps/42/src/tests.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/steps/42/src/tests.rs b/steps/42/src/tests.rs index ffe1390d..20bff4fd 100644 --- a/steps/42/src/tests.rs +++ b/steps/42/src/tests.rs @@ -61,6 +61,7 @@ impl pallet_balances::Config for TestRuntime { // will also need to update this configuration to represent that. impl pallet_kitties::Config for TestRuntime { type RuntimeEvent = RuntimeEvent; + /* 🚧 TODO 🚧: Add type `NativeBalance` as the `Balances` pallet. */ } // We need to run most of our tests using this function: `new_test_ext().execute_with(|| { ... });` From 8927f724ddca697f490bbc8d7e6ff65a3ccfc30a Mon Sep 17 00:00:00 2001 From: "Yung Beef 4.2" <89395745+Yung-Beef@users.noreply.github.com> Date: Wed, 30 Oct 2024 11:23:32 -0300 Subject: [PATCH 19/33] Update README.md --- steps/46/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/steps/46/README.md b/steps/46/README.md index fa2d028c..5e0c171a 100644 --- a/steps/46/README.md +++ b/steps/46/README.md @@ -1,6 +1,6 @@ # Set Price Extrinsic -Now that we our Pallet set up to handle balances, let's actually use them. +Now that we have our Pallet set up to handle balances, let's actually use them. In this step, we will create an extrinsic which allows the owner of a kitty to set a price for the kitty. From 7cf80740ab56a66f170b5ad840c6f9abb5d66eac Mon Sep 17 00:00:00 2001 From: "Yung Beef 4.2" <89395745+Yung-Beef@users.noreply.github.com> Date: Wed, 30 Oct 2024 11:55:17 -0300 Subject: [PATCH 20/33] Update README.md --- steps/50/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/steps/50/README.md b/steps/50/README.md index 60cbe37f..909c412a 100644 --- a/steps/50/README.md +++ b/steps/50/README.md @@ -1,6 +1,6 @@ # Buy Kitty Extrinsic -Now that kitties can have a price, we want to enable them to be purchaseable. +Now that kitties can have a price, we want to enable them to be purchasable. For that, we will create the `buy_kitty` extrinsic. From dedfaa720d4b4c458c5c332da6c0e1895e9e6ab5 Mon Sep 17 00:00:00 2001 From: "Yung Beef 4.2" <89395745+Yung-Beef@users.noreply.github.com> Date: Wed, 30 Oct 2024 12:21:01 -0300 Subject: [PATCH 21/33] Update README.md --- steps/52/README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/steps/52/README.md b/steps/52/README.md index 9c91cc7f..40ba8e1a 100644 --- a/steps/52/README.md +++ b/steps/52/README.md @@ -63,6 +63,12 @@ That is all beyond the scope of this tutorial, but the high level idea is that w In this context, we don't want someone to kill their account to buy a kitty, so we want to use `Preservation::Preserve` for our `transfer`. +> NOTE: To access this enum, you will need import the trait to bring it in scope, so don't forget to include: +> +> ```rust +> use frame::traits::tokens::Preservation; +> ``` + So the final syntax should look like: ```rust From b2b1b28a008030bd607a10486e34dff62785c92e Mon Sep 17 00:00:00 2001 From: "Yung Beef 4.2" <89395745+Yung-Beef@users.noreply.github.com> Date: Wed, 30 Oct 2024 12:24:29 -0300 Subject: [PATCH 22/33] Update README.md --- steps/52/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/steps/52/README.md b/steps/52/README.md index 40ba8e1a..63acceb1 100644 --- a/steps/52/README.md +++ b/steps/52/README.md @@ -91,7 +91,7 @@ Both transfer functions need to succeed for the sale to complete successfully. If either one of them would fail, the whole purchase should fail. -Thankfully, both of our transfer functions return a result, and to handle things correctly here, we just ned to propagate up those errors. For that, we simply include `?` at the end of the function. +Thankfully, both of our transfer functions return a result, and to handle things correctly here, we just need to propagate up those errors. For that, we simply include `?` at the end of the function. If at any point our extrinsic or the logic inside the extrinsic returns an error, the whole extrinsic will fail and all changes to storage will be undone. This is exactly the same behavior you would expect from a smart contract, and keeps our state transition function functioning smoothly. From 11401bd0fd4a5a63445180463c264ec67fb4a6f2 Mon Sep 17 00:00:00 2001 From: "Yung Beef 4.2" <89395745+Yung-Beef@users.noreply.github.com> Date: Wed, 30 Oct 2024 12:24:57 -0300 Subject: [PATCH 23/33] Update impls.rs --- steps/52/src/impls.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/steps/52/src/impls.rs b/steps/52/src/impls.rs index e9dca34a..89e52100 100644 --- a/steps/52/src/impls.rs +++ b/steps/52/src/impls.rs @@ -2,6 +2,7 @@ use super::*; use frame::prelude::*; use frame::primitives::BlakeTwo256; /* 🚧 TODO 🚧: Import `frame::traits::tokens::Preservation`. */ +/* 🚧 TODO 🚧: Import `frame::traits::fungible::Mutate`. */ use frame::traits::Hash; // Learn about internal functions. From c0bdc12b20a78e72bb7fc63b11c8749468ffdd6f Mon Sep 17 00:00:00 2001 From: "Yung Beef 4.2" <89395745+Yung-Beef@users.noreply.github.com> Date: Wed, 30 Oct 2024 18:02:42 -0300 Subject: [PATCH 24/33] Update README.md --- steps/6/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/steps/6/README.md b/steps/6/README.md index f4854d4b..8c2d8564 100644 --- a/steps/6/README.md +++ b/steps/6/README.md @@ -31,6 +31,8 @@ If you are familiar with smart contracts or any kind of blockchain application, Those transactions are processed, and then dispatched to callable functions within the blockchain. +*Internal functions are generally implemented in a separate `impl.rs` file for ergonomic purposes, while the callable functions are located in `lib.rs`.* + ### Pallet Call Macro Pallet development allows you to create callable functions by introducing the `#[pallet::call]` macro on top of a normal function implementation code block. From 1bc0de2e8e0e8b921b09741b9810a15962c192b2 Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Thu, 31 Oct 2024 23:25:24 -0700 Subject: [PATCH 25/33] remove "and sex" --- steps/32/src/impls.rs | 2 +- steps/34/src/impls.rs | 2 +- steps/36/src/impls.rs | 2 +- steps/37/src/impls.rs | 2 +- steps/39/src/impls.rs | 2 +- steps/41/src/impls.rs | 2 +- steps/42/src/impls.rs | 2 +- steps/43/src/impls.rs | 2 +- steps/44/src/impls.rs | 2 +- steps/45/src/impls.rs | 2 +- steps/46/src/impls.rs | 2 +- steps/47/src/impls.rs | 2 +- steps/48/src/impls.rs | 2 +- steps/49/src/impls.rs | 2 +- steps/50/src/impls.rs | 2 +- steps/51/src/impls.rs | 2 +- steps/52/src/impls.rs | 2 +- steps/53/src/impls.rs | 2 +- steps/54/src/impls.rs | 2 +- 19 files changed, 19 insertions(+), 19 deletions(-) diff --git a/steps/32/src/impls.rs b/steps/32/src/impls.rs index 470eb783..ff69caec 100644 --- a/steps/32/src/impls.rs +++ b/steps/32/src/impls.rs @@ -4,7 +4,7 @@ use frame::primitives::BlakeTwo256; use frame::traits::Hash; impl Pallet { - // Generates and returns DNA and Sex + // Generates and returns DNA pub fn gen_dna() -> [u8; 32] { // Create randomness payload. Multiple kitties can be generated in the same block, // retaining uniqueness. diff --git a/steps/34/src/impls.rs b/steps/34/src/impls.rs index b680830e..e464223c 100644 --- a/steps/34/src/impls.rs +++ b/steps/34/src/impls.rs @@ -4,7 +4,7 @@ use frame::primitives::BlakeTwo256; use frame::traits::Hash; impl Pallet { - // Generates and returns DNA and Sex + // Generates and returns DNA pub fn gen_dna() -> [u8; 32] { // Create randomness payload. Multiple kitties can be generated in the same block, // retaining uniqueness. diff --git a/steps/36/src/impls.rs b/steps/36/src/impls.rs index e9dcca6b..793dec31 100644 --- a/steps/36/src/impls.rs +++ b/steps/36/src/impls.rs @@ -5,7 +5,7 @@ use frame::traits::Hash; // Learn about internal functions. impl Pallet { - // Generates and returns DNA and Sex + // Generates and returns DNA pub fn gen_dna() -> [u8; 32] { // Create randomness payload. Multiple kitties can be generated in the same block, // retaining uniqueness. diff --git a/steps/37/src/impls.rs b/steps/37/src/impls.rs index e9dcca6b..793dec31 100644 --- a/steps/37/src/impls.rs +++ b/steps/37/src/impls.rs @@ -5,7 +5,7 @@ use frame::traits::Hash; // Learn about internal functions. impl Pallet { - // Generates and returns DNA and Sex + // Generates and returns DNA pub fn gen_dna() -> [u8; 32] { // Create randomness payload. Multiple kitties can be generated in the same block, // retaining uniqueness. diff --git a/steps/39/src/impls.rs b/steps/39/src/impls.rs index 3428acb3..9d435f5b 100644 --- a/steps/39/src/impls.rs +++ b/steps/39/src/impls.rs @@ -5,7 +5,7 @@ use frame::traits::Hash; // Learn about internal functions. impl Pallet { - // Generates and returns DNA and Sex + // Generates and returns DNA pub fn gen_dna() -> [u8; 32] { // Create randomness payload. Multiple kitties can be generated in the same block, // retaining uniqueness. diff --git a/steps/41/src/impls.rs b/steps/41/src/impls.rs index a638a8c0..55742115 100644 --- a/steps/41/src/impls.rs +++ b/steps/41/src/impls.rs @@ -5,7 +5,7 @@ use frame::traits::Hash; // Learn about internal functions. impl Pallet { - // Generates and returns DNA and Sex + // Generates and returns DNA pub fn gen_dna() -> [u8; 32] { // Create randomness payload. Multiple kitties can be generated in the same block, // retaining uniqueness. diff --git a/steps/42/src/impls.rs b/steps/42/src/impls.rs index a638a8c0..55742115 100644 --- a/steps/42/src/impls.rs +++ b/steps/42/src/impls.rs @@ -5,7 +5,7 @@ use frame::traits::Hash; // Learn about internal functions. impl Pallet { - // Generates and returns DNA and Sex + // Generates and returns DNA pub fn gen_dna() -> [u8; 32] { // Create randomness payload. Multiple kitties can be generated in the same block, // retaining uniqueness. diff --git a/steps/43/src/impls.rs b/steps/43/src/impls.rs index a638a8c0..55742115 100644 --- a/steps/43/src/impls.rs +++ b/steps/43/src/impls.rs @@ -5,7 +5,7 @@ use frame::traits::Hash; // Learn about internal functions. impl Pallet { - // Generates and returns DNA and Sex + // Generates and returns DNA pub fn gen_dna() -> [u8; 32] { // Create randomness payload. Multiple kitties can be generated in the same block, // retaining uniqueness. diff --git a/steps/44/src/impls.rs b/steps/44/src/impls.rs index c569f2af..2c01fdca 100644 --- a/steps/44/src/impls.rs +++ b/steps/44/src/impls.rs @@ -5,7 +5,7 @@ use frame::traits::Hash; // Learn about internal functions. impl Pallet { - // Generates and returns DNA and Sex + // Generates and returns DNA pub fn gen_dna() -> [u8; 32] { // Create randomness payload. Multiple kitties can be generated in the same block, // retaining uniqueness. diff --git a/steps/45/src/impls.rs b/steps/45/src/impls.rs index bee571d1..16bdb731 100644 --- a/steps/45/src/impls.rs +++ b/steps/45/src/impls.rs @@ -5,7 +5,7 @@ use frame::traits::Hash; // Learn about internal functions. impl Pallet { - // Generates and returns DNA and Sex + // Generates and returns DNA pub fn gen_dna() -> [u8; 32] { // Create randomness payload. Multiple kitties can be generated in the same block, // retaining uniqueness. diff --git a/steps/46/src/impls.rs b/steps/46/src/impls.rs index e7fa6b60..f3f82812 100644 --- a/steps/46/src/impls.rs +++ b/steps/46/src/impls.rs @@ -5,7 +5,7 @@ use frame::traits::Hash; // Learn about internal functions. impl Pallet { - // Generates and returns DNA and Sex + // Generates and returns DNA pub fn gen_dna() -> [u8; 32] { // Create randomness payload. Multiple kitties can be generated in the same block, // retaining uniqueness. diff --git a/steps/47/src/impls.rs b/steps/47/src/impls.rs index 53fb204a..48af8471 100644 --- a/steps/47/src/impls.rs +++ b/steps/47/src/impls.rs @@ -5,7 +5,7 @@ use frame::traits::Hash; // Learn about internal functions. impl Pallet { - // Generates and returns DNA and Sex + // Generates and returns DNA pub fn gen_dna() -> [u8; 32] { // Create randomness payload. Multiple kitties can be generated in the same block, // retaining uniqueness. diff --git a/steps/48/src/impls.rs b/steps/48/src/impls.rs index c486f9ed..aa65cdd0 100644 --- a/steps/48/src/impls.rs +++ b/steps/48/src/impls.rs @@ -5,7 +5,7 @@ use frame::traits::Hash; // Learn about internal functions. impl Pallet { - // Generates and returns DNA and Sex + // Generates and returns DNA pub fn gen_dna() -> [u8; 32] { // Create randomness payload. Multiple kitties can be generated in the same block, // retaining uniqueness. diff --git a/steps/49/src/impls.rs b/steps/49/src/impls.rs index 79ec6585..af4e4602 100644 --- a/steps/49/src/impls.rs +++ b/steps/49/src/impls.rs @@ -5,7 +5,7 @@ use frame::traits::Hash; // Learn about internal functions. impl Pallet { - // Generates and returns DNA and Sex + // Generates and returns DNA pub fn gen_dna() -> [u8; 32] { // Create randomness payload. Multiple kitties can be generated in the same block, // retaining uniqueness. diff --git a/steps/50/src/impls.rs b/steps/50/src/impls.rs index 953fa5c2..04c92c57 100644 --- a/steps/50/src/impls.rs +++ b/steps/50/src/impls.rs @@ -5,7 +5,7 @@ use frame::traits::Hash; // Learn about internal functions. impl Pallet { - // Generates and returns DNA and Sex + // Generates and returns DNA pub fn gen_dna() -> [u8; 32] { // Create randomness payload. Multiple kitties can be generated in the same block, // retaining uniqueness. diff --git a/steps/51/src/impls.rs b/steps/51/src/impls.rs index 81f657e7..03cf1f18 100644 --- a/steps/51/src/impls.rs +++ b/steps/51/src/impls.rs @@ -5,7 +5,7 @@ use frame::traits::Hash; // Learn about internal functions. impl Pallet { - // Generates and returns DNA and Sex + // Generates and returns DNA pub fn gen_dna() -> [u8; 32] { // Create randomness payload. Multiple kitties can be generated in the same block, // retaining uniqueness. diff --git a/steps/52/src/impls.rs b/steps/52/src/impls.rs index 89e52100..c78ac6e6 100644 --- a/steps/52/src/impls.rs +++ b/steps/52/src/impls.rs @@ -7,7 +7,7 @@ use frame::traits::Hash; // Learn about internal functions. impl Pallet { - // Generates and returns DNA and Sex + // Generates and returns DNA pub fn gen_dna() -> [u8; 32] { // Create randomness payload. Multiple kitties can be generated in the same block, // retaining uniqueness. diff --git a/steps/53/src/impls.rs b/steps/53/src/impls.rs index 179c26e2..463894ed 100644 --- a/steps/53/src/impls.rs +++ b/steps/53/src/impls.rs @@ -6,7 +6,7 @@ use frame::traits::Hash; // Learn about internal functions. impl Pallet { - // Generates and returns DNA and Sex + // Generates and returns DNA pub fn gen_dna() -> [u8; 32] { // Create randomness payload. Multiple kitties can be generated in the same block, // retaining uniqueness. diff --git a/steps/54/src/impls.rs b/steps/54/src/impls.rs index 179c26e2..463894ed 100644 --- a/steps/54/src/impls.rs +++ b/steps/54/src/impls.rs @@ -6,7 +6,7 @@ use frame::traits::Hash; // Learn about internal functions. impl Pallet { - // Generates and returns DNA and Sex + // Generates and returns DNA pub fn gen_dna() -> [u8; 32] { // Create randomness payload. Multiple kitties can be generated in the same block, // retaining uniqueness. From 9e78b77cd13c5767de4c9327406cc704f10c6a9a Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Thu, 31 Oct 2024 23:31:39 -0700 Subject: [PATCH 26/33] Update steps/20/README.md --- steps/20/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/steps/20/README.md b/steps/20/README.md index 6a62e06a..46d9d441 100644 --- a/steps/20/README.md +++ b/steps/20/README.md @@ -19,7 +19,7 @@ Each `Key` can store a separate `Value`, which makes maps super useful. In this case `[u8; 32]` represents some unique identifier for each Kitty we will store, and `()` is simply a placeholder type for now. -Note that each storage instance needs its own `#[pallet::storage]` macro. +Note that each storage instance needs its own `#[pallet::storage]` attribute. ## Conceptual From c58e0d404f74bedaab4845c2558690736da5f892 Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Thu, 31 Oct 2024 23:31:59 -0700 Subject: [PATCH 27/33] Update steps/20/README.md --- steps/20/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/steps/20/README.md b/steps/20/README.md index 46d9d441..169722f0 100644 --- a/steps/20/README.md +++ b/steps/20/README.md @@ -19,7 +19,7 @@ Each `Key` can store a separate `Value`, which makes maps super useful. In this case `[u8; 32]` represents some unique identifier for each Kitty we will store, and `()` is simply a placeholder type for now. -Note that each storage instance needs its own `#[pallet::storage]` attribute. +Note that each storage item needs its own `#[pallet::storage]` attribute. ## Conceptual From 2460e6ad88997ee1b7cae4091dc4fc2b761331ff Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Thu, 31 Oct 2024 23:33:52 -0700 Subject: [PATCH 28/33] Update steps/22/src/lib.rs --- steps/22/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/steps/22/src/lib.rs b/steps/22/src/lib.rs index 780e6bc6..717c9009 100644 --- a/steps/22/src/lib.rs +++ b/steps/22/src/lib.rs @@ -40,8 +40,8 @@ pub mod pallet { pub fn create_kitty(origin: OriginFor) -> DispatchResult { let who = ensure_signed(origin)?; /* 🚧 TODO 🚧: - - Create a `dna` variable that this kitty will have, which has a value of `[0u8; 32]`. - - Pass `dna` to the `mint` function as a second parameter. + - Create a `dna` variable for this kitty, which we will set as `[0u8; 32]` for now. + - Pass `dna` to the `mint` function as the second parameter. */ Self::mint(who)?; Ok(()) From 25013156785bbbfa175c3d00cab770ca46fe33f1 Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Thu, 31 Oct 2024 23:35:25 -0700 Subject: [PATCH 29/33] Update steps/38/src/impls.rs --- steps/38/src/impls.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/steps/38/src/impls.rs b/steps/38/src/impls.rs index 2ab0d08d..6743fe42 100644 --- a/steps/38/src/impls.rs +++ b/steps/38/src/impls.rs @@ -42,7 +42,7 @@ impl Pallet { - `kitty_id` which is `[u8; 32]`. - It returns a `DispatchResult` - The inner logic for now is: - - Call `Self::ddeposit_event` on and emit `Event:::Transferred` with params. + - Call `Self::deposit_event` on and emit `Event:::Transferred` with params. - Return `Ok(())`. */ } From 84943e5a5044cdc7b55d5ce93fb901c68a6cf2d6 Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Thu, 31 Oct 2024 23:35:53 -0700 Subject: [PATCH 30/33] Update steps/38/src/impls.rs --- steps/38/src/impls.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/steps/38/src/impls.rs b/steps/38/src/impls.rs index 6743fe42..3dd15659 100644 --- a/steps/38/src/impls.rs +++ b/steps/38/src/impls.rs @@ -42,7 +42,7 @@ impl Pallet { - `kitty_id` which is `[u8; 32]`. - It returns a `DispatchResult` - The inner logic for now is: - - Call `Self::deposit_event` on and emit `Event:::Transferred` with params. + - Call `Self::deposit_event` and emit `Event:::Transferred` with params. - Return `Ok(())`. */ } From 0784def5c9bd48124e62de81bc91ebd582003698 Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Thu, 31 Oct 2024 23:40:16 -0700 Subject: [PATCH 31/33] Update steps/52/README.md --- steps/52/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/steps/52/README.md b/steps/52/README.md index 63acceb1..5ce0efd5 100644 --- a/steps/52/README.md +++ b/steps/52/README.md @@ -63,7 +63,7 @@ That is all beyond the scope of this tutorial, but the high level idea is that w In this context, we don't want someone to kill their account to buy a kitty, so we want to use `Preservation::Preserve` for our `transfer`. -> NOTE: To access this enum, you will need import the trait to bring it in scope, so don't forget to include: +> NOTE: Don't forget the TODO that imports this enum so you can use it: > > ```rust > use frame::traits::tokens::Preservation; From 47eaafb8c0476f0eca677763d262f21dcbd0f0e3 Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Thu, 31 Oct 2024 23:42:07 -0700 Subject: [PATCH 32/33] Update steps/52/src/impls.rs --- steps/52/src/impls.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/steps/52/src/impls.rs b/steps/52/src/impls.rs index c78ac6e6..c7a34b2c 100644 --- a/steps/52/src/impls.rs +++ b/steps/52/src/impls.rs @@ -2,7 +2,6 @@ use super::*; use frame::prelude::*; use frame::primitives::BlakeTwo256; /* 🚧 TODO 🚧: Import `frame::traits::tokens::Preservation`. */ -/* 🚧 TODO 🚧: Import `frame::traits::fungible::Mutate`. */ use frame::traits::Hash; // Learn about internal functions. From 748563f2fb0cc313578d590b1fbeec986318ce19 Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Thu, 31 Oct 2024 23:45:10 -0700 Subject: [PATCH 33/33] Update steps/6/README.md --- steps/6/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/steps/6/README.md b/steps/6/README.md index 8c2d8564..2b3ee410 100644 --- a/steps/6/README.md +++ b/steps/6/README.md @@ -31,7 +31,7 @@ If you are familiar with smart contracts or any kind of blockchain application, Those transactions are processed, and then dispatched to callable functions within the blockchain. -*Internal functions are generally implemented in a separate `impl.rs` file for ergonomic purposes, while the callable functions are located in `lib.rs`.* +For ergonomics, you will normally see callable functions defined in the `lib.rs`, but their logic implemented in a separate `impls.rs` file. This is really up to your preference, but since this is the common practice in the Polkadot SDK, the tutorial will use this pattern as well. ### Pallet Call Macro