-
+
-
+
```rust
-{{#include ./template/src/lib.rs}}
+{{#include ./template/src/impls.rs}}
```
@@ -34,12 +34,12 @@
-
+
-
+ Pallet {
- // Learn about `AccountId`.
- fn mint(owner: T::AccountId) -> DispatchResult {
-- /* TODO:
-- - `get` the current count of kitties.
-- - `unwrap_or` set the count to `0`.
-- - increment the count by one.
-- - `set` the new count of kitties.
-- */
-+ let current_count: u64 = CountForKitties::::get().unwrap_or(0);
-+ let new_count = current_count + 1;
-+ CountForKitties::::set(Some(new_count));
- Self::deposit_event(Event::::Created { owner });
- Ok(())
- }
+diff --git a/src/impls.rs b/src/impls.rs
+index 67fd2a0..ef53a56 100644
+--- a/src/impls.rs
++++ b/src/impls.rs
+@@ -4,12 +4,9 @@ use frame_support::pallet_prelude::*;
+ impl Pallet {
+ // Learn about `AccountId`.
+ pub fn mint(owner: T::AccountId) -> DispatchResult {
+- /* TODO:
+- - `get` the current count of kitties.
+- - `unwrap_or` set the count to `0`.
+- - increment the count by one.
+- - `set` the new count of kitties.
+- */
++ let current_count: u64 = CountForKitties::::get().unwrap_or(0);
++ let new_count = current_count + 1;
++ CountForKitties::::set(Some(new_count));
+ Self::deposit_event(Event::::Created { owner });
+ Ok(())
+ }
diff --git a/src/10/solution/src/impls.rs b/src/10/solution/src/impls.rs
new file mode 100644
index 00000000..ef53a56f
--- /dev/null
+++ b/src/10/solution/src/impls.rs
@@ -0,0 +1,13 @@
+use super::*;
+use frame_support::pallet_prelude::*;
+
+impl Pallet {
+ // Learn about `AccountId`.
+ pub fn mint(owner: T::AccountId) -> DispatchResult {
+ let current_count: u64 = CountForKitties::::get().unwrap_or(0);
+ let new_count = current_count + 1;
+ CountForKitties::::set(Some(new_count));
+ Self::deposit_event(Event::::Created { owner });
+ Ok(())
+ }
+}
diff --git a/src/10/solution/src/lib.rs b/src/10/solution/src/lib.rs
index 59a65fea..acea2e23 100644
--- a/src/10/solution/src/lib.rs
+++ b/src/10/solution/src/lib.rs
@@ -1,5 +1,7 @@
#![cfg_attr(not(feature = "std"), no_std)]
+mod impls;
+
pub use pallet::*;
// Learn about Macros used in the `polkadot-sdk`, making pallet development easier.
@@ -44,16 +46,4 @@ pub mod pallet {
Ok(())
}
}
-
- // Learn about internal functions.
- impl Pallet {
- // Learn about `AccountId`.
- fn mint(owner: T::AccountId) -> DispatchResult {
- let current_count: u64 = CountForKitties::::get().unwrap_or(0);
- let new_count = current_count + 1;
- CountForKitties::::set(Some(new_count));
- Self::deposit_event(Event::::Created { owner });
- Ok(())
- }
- }
}
diff --git a/src/10/template/src/impls.rs b/src/10/template/src/impls.rs
new file mode 100644
index 00000000..67fd2a06
--- /dev/null
+++ b/src/10/template/src/impls.rs
@@ -0,0 +1,16 @@
+use super::*;
+use frame_support::pallet_prelude::*;
+
+impl Pallet {
+ // Learn about `AccountId`.
+ pub fn mint(owner: T::AccountId) -> DispatchResult {
+ /* TODO:
+ - `get` the current count of kitties.
+ - `unwrap_or` set the count to `0`.
+ - increment the count by one.
+ - `set` the new count of kitties.
+ */
+ Self::deposit_event(Event::::Created { owner });
+ Ok(())
+ }
+}
diff --git a/src/10/template/src/lib.rs b/src/10/template/src/lib.rs
index 356e5476..acea2e23 100644
--- a/src/10/template/src/lib.rs
+++ b/src/10/template/src/lib.rs
@@ -1,5 +1,7 @@
#![cfg_attr(not(feature = "std"), no_std)]
+mod impls;
+
pub use pallet::*;
// Learn about Macros used in the `polkadot-sdk`, making pallet development easier.
@@ -44,19 +46,4 @@ pub mod pallet {
Ok(())
}
}
-
- // Learn about internal functions.
- impl Pallet {
- // Learn about `AccountId`.
- fn mint(owner: T::AccountId) -> DispatchResult {
- /* TODO:
- - `get` the current count of kitties.
- - `unwrap_or` set the count to `0`.
- - increment the count by one.
- - `set` the new count of kitties.
- */
- Self::deposit_event(Event::::Created { owner });
- Ok(())
- }
- }
}
diff --git a/src/10/template/template.diff b/src/10/template/template.diff
index 1c6418a2..70be1f0b 100644
--- a/src/10/template/template.diff
+++ b/src/10/template/template.diff
@@ -1,17 +1,17 @@
-diff --git a/src/lib.rs b/src/lib.rs
-index 67dd167..356e547 100644
---- a/src/lib.rs
-+++ b/src/lib.rs
-@@ -49,6 +49,12 @@ pub mod pallet {
- impl Pallet {
- // Learn about `AccountId`.
- fn mint(owner: T::AccountId) -> DispatchResult {
-+ /* TODO:
-+ - `get` the current count of kitties.
-+ - `unwrap_or` set the count to `0`.
-+ - increment the count by one.
-+ - `set` the new count of kitties.
-+ */
- Self::deposit_event(Event::::Created { owner });
- Ok(())
- }
+diff --git a/src/impls.rs b/src/impls.rs
+index 869c781..67fd2a0 100644
+--- a/src/impls.rs
++++ b/src/impls.rs
+@@ -4,6 +4,12 @@ use frame_support::pallet_prelude::*;
+ impl Pallet {
+ // Learn about `AccountId`.
+ pub fn mint(owner: T::AccountId) -> DispatchResult {
++ /* TODO:
++ - `get` the current count of kitties.
++ - `unwrap_or` set the count to `0`.
++ - increment the count by one.
++ - `set` the new count of kitties.
++ */
+ Self::deposit_event(Event::::Created { owner });
+ Ok(())
+ }
diff --git a/src/11/README.md b/src/11/README.md
index 061af0d2..cead1dba 100644
--- a/src/11/README.md
+++ b/src/11/README.md
@@ -17,9 +17,18 @@
```rust
-{{#include ./solution/src/lib.rs}}
+{{#include ./solution/src/impls.rs}}
```
diff --git a/src/10/solution/solution.diff b/src/10/solution/solution.diff
index 029788b9..63742707 100644
--- a/src/10/solution/solution.diff
+++ b/src/10/solution/solution.diff
@@ -1,20 +1,20 @@
-diff --git a/src/lib.rs b/src/lib.rs
-index 356e547..59a65fe 100644
---- a/src/lib.rs
-+++ b/src/lib.rs
-@@ -49,12 +49,9 @@ pub mod pallet {
- impl
-
+
+
-
+
+
+```rust
+{{#include ./template/src/impls.rs}}
+```
+
+
+
+
```rust
{{#include ./template/src/lib.rs}}
@@ -34,9 +43,18 @@
-
+
+
-
+
+
+```rust
+{{#include ./solution/src/impls.rs}}
+```
+
+
+
+
```rust
{{#include ./solution/src/lib.rs}}
diff --git a/src/11/solution/solution.diff b/src/11/solution/solution.diff
index a60cd898..c4b93397 100644
--- a/src/11/solution/solution.diff
+++ b/src/11/solution/solution.diff
@@ -1,8 +1,22 @@
+diff --git a/src/impls.rs b/src/impls.rs
+index ba4070f..9481d05 100644
+--- a/src/impls.rs
++++ b/src/impls.rs
+@@ -5,8 +5,7 @@ impl Pallet {
+ // Learn about `AccountId`.
+ pub fn mint(owner: T::AccountId) -> DispatchResult {
+ let current_count: u64 = CountForKitties::::get().unwrap_or(0);
+- /* TODO: Update this logic to use safe math. */
+- let new_count = current_count + 1;
++ let new_count = current_count.checked_add(1).ok_or(Error::::TooManyKitties)?;
+ CountForKitties::::set(Some(new_count));
+ Self::deposit_event(Event::::Created { owner });
+ Ok(())
diff --git a/src/lib.rs b/src/lib.rs
-index 924f26f..2ed0e74 100644
+index 110d15d..9ff62ff 100644
--- a/src/lib.rs
+++ b/src/lib.rs
-@@ -33,9 +33,7 @@ pub mod pallet {
+@@ -35,9 +35,7 @@ pub mod pallet {
#[pallet::error]
pub enum Error {
@@ -13,13 +27,3 @@ index 924f26f..2ed0e74 100644
}
// Learn about callable functions and dispatch.
-@@ -54,8 +52,7 @@ pub mod pallet {
- // Learn about `AccountId`.
- fn mint(owner: T::AccountId) -> DispatchResult {
- let current_count: u64 = CountForKitties::::get().unwrap_or(0);
-- /* TODO: Update this logic to use safe math. */
-- let new_count = current_count + 1;
-+ let new_count = current_count.checked_add(1).ok_or(Error::::TooManyKitties)?;
- CountForKitties::::set(Some(new_count));
- Self::deposit_event(Event::::Created { owner });
- Ok(())
diff --git a/src/11/solution/src/impls.rs b/src/11/solution/src/impls.rs
new file mode 100644
index 00000000..9481d053
--- /dev/null
+++ b/src/11/solution/src/impls.rs
@@ -0,0 +1,13 @@
+use super::*;
+use frame_support::pallet_prelude::*;
+
+impl Pallet {
+ // Learn about `AccountId`.
+ pub fn mint(owner: T::AccountId) -> DispatchResult {
+ let current_count: u64 = CountForKitties::::get().unwrap_or(0);
+ let new_count = current_count.checked_add(1).ok_or(Error::::TooManyKitties)?;
+ CountForKitties::::set(Some(new_count));
+ Self::deposit_event(Event::::Created { owner });
+ Ok(())
+ }
+}
diff --git a/src/11/solution/src/lib.rs b/src/11/solution/src/lib.rs
index 2ed0e748..9ff62ffe 100644
--- a/src/11/solution/src/lib.rs
+++ b/src/11/solution/src/lib.rs
@@ -1,5 +1,7 @@
#![cfg_attr(not(feature = "std"), no_std)]
+mod impls;
+
pub use pallet::*;
// Learn about Macros used in the `polkadot-sdk`, making pallet development easier.
@@ -46,16 +48,4 @@ pub mod pallet {
Ok(())
}
}
-
- // Learn about internal functions.
- impl Pallet {
- // Learn about `AccountId`.
- fn mint(owner: T::AccountId) -> DispatchResult {
- let current_count: u64 = CountForKitties::::get().unwrap_or(0);
- let new_count = current_count.checked_add(1).ok_or(Error::::TooManyKitties)?;
- CountForKitties::::set(Some(new_count));
- Self::deposit_event(Event::::Created { owner });
- Ok(())
- }
- }
}
diff --git a/src/11/template/src/impls.rs b/src/11/template/src/impls.rs
new file mode 100644
index 00000000..ba4070f5
--- /dev/null
+++ b/src/11/template/src/impls.rs
@@ -0,0 +1,14 @@
+use super::*;
+use frame_support::pallet_prelude::*;
+
+impl Pallet {
+ // Learn about `AccountId`.
+ pub fn mint(owner: T::AccountId) -> DispatchResult {
+ let current_count: u64 = CountForKitties::::get().unwrap_or(0);
+ /* TODO: Update this logic to use safe math. */
+ let new_count = current_count + 1;
+ CountForKitties::::set(Some(new_count));
+ Self::deposit_event(Event::::Created { owner });
+ Ok(())
+ }
+}
diff --git a/src/11/template/src/lib.rs b/src/11/template/src/lib.rs
index 924f26fe..110d15d2 100644
--- a/src/11/template/src/lib.rs
+++ b/src/11/template/src/lib.rs
@@ -1,5 +1,7 @@
#![cfg_attr(not(feature = "std"), no_std)]
+mod impls;
+
pub use pallet::*;
// Learn about Macros used in the `polkadot-sdk`, making pallet development easier.
@@ -48,17 +50,4 @@ pub mod pallet {
Ok(())
}
}
-
- // Learn about internal functions.
- impl Pallet {
- // Learn about `AccountId`.
- fn mint(owner: T::AccountId) -> DispatchResult {
- let current_count: u64 = CountForKitties::::get().unwrap_or(0);
- /* TODO: Update this logic to use safe math. */
- let new_count = current_count + 1;
- CountForKitties::::set(Some(new_count));
- Self::deposit_event(Event::::Created { owner });
- Ok(())
- }
- }
}
diff --git a/src/11/template/template.diff b/src/11/template/template.diff
index 065a5e1a..0dc78199 100644
--- a/src/11/template/template.diff
+++ b/src/11/template/template.diff
@@ -1,8 +1,20 @@
+diff --git a/src/impls.rs b/src/impls.rs
+index ef53a56..ba4070f 100644
+--- a/src/impls.rs
++++ b/src/impls.rs
+@@ -5,6 +5,7 @@ impl Pallet {
+ // Learn about `AccountId`.
+ pub fn mint(owner: T::AccountId) -> DispatchResult {
+ let current_count: u64 = CountForKitties::::get().unwrap_or(0);
++ /* TODO: Update this logic to use safe math. */
+ let new_count = current_count + 1;
+ CountForKitties::::set(Some(new_count));
+ Self::deposit_event(Event::::Created { owner });
diff --git a/src/lib.rs b/src/lib.rs
-index 59a65fe..924f26f 100644
+index acea2e2..110d15d 100644
--- a/src/lib.rs
+++ b/src/lib.rs
-@@ -32,7 +32,11 @@ pub mod pallet {
+@@ -34,7 +34,11 @@ pub mod pallet {
}
#[pallet::error]
@@ -15,11 +27,3 @@ index 59a65fe..924f26f 100644
// Learn about callable functions and dispatch.
#[pallet::call]
-@@ -50,6 +54,7 @@ pub mod pallet {
- // Learn about `AccountId`.
- fn mint(owner: T::AccountId) -> DispatchResult {
- let current_count: u64 = CountForKitties::::get().unwrap_or(0);
-+ /* TODO: Update this logic to use safe math. */
- let new_count = current_count + 1;
- CountForKitties::::set(Some(new_count));
- Self::deposit_event(Event::::Created { owner });
diff --git a/src/12/README.md b/src/12/README.md
index 061af0d2..cead1dba 100644
--- a/src/12/README.md
+++ b/src/12/README.md
@@ -17,9 +17,18 @@
-
+
+
-
+
+
+```rust
+{{#include ./template/src/impls.rs}}
+```
+
+
+
+
```rust
{{#include ./template/src/lib.rs}}
@@ -34,9 +43,18 @@
-
+
+
-
+
+
+```rust
+{{#include ./solution/src/impls.rs}}
+```
+
+
+
+
```rust
{{#include ./solution/src/lib.rs}}
diff --git a/src/12/solution/solution.diff b/src/12/solution/solution.diff
index 026c2ac7..caa81773 100644
--- a/src/12/solution/solution.diff
+++ b/src/12/solution/solution.diff
@@ -1,8 +1,26 @@
+diff --git a/src/impls.rs b/src/impls.rs
+index 99141c0..1af97cb 100644
+--- a/src/impls.rs
++++ b/src/impls.rs
+@@ -4,11 +4,9 @@ use frame_support::pallet_prelude::*;
+ impl Pallet {
+ // Learn about `AccountId`.
+ pub fn mint(owner: T::AccountId) -> DispatchResult {
+- /* TODO: Remove the `unwrap_or` which is not needed when using `ValueQuery`. */
+- let current_count: u64 = CountForKitties::::get().unwrap_or(0);
++ let current_count: u64 = CountForKitties::::get();
+ let new_count = current_count.checked_add(1).ok_or(Error::::TooManyKitties)?;
+- /* TODO: Remove the `Option` wrapper when setting the `new_count`. */
+- CountForKitties::::set(Some(new_count));
++ CountForKitties::::set(new_count);
+ Self::deposit_event(Event::::Created { owner });
+ Ok(())
+ }
diff --git a/src/lib.rs b/src/lib.rs
-index 3b445c2..446ce3c 100644
+index 5ef793a..824c5ac 100644
--- a/src/lib.rs
+++ b/src/lib.rs
-@@ -22,8 +22,7 @@ pub mod pallet {
+@@ -24,8 +24,7 @@ pub mod pallet {
/// Learn about storage value.
#[pallet::storage]
@@ -12,17 +30,3 @@ index 3b445c2..446ce3c 100644
// Learn about events.
#[pallet::event]
-@@ -52,11 +51,9 @@ pub mod pallet {
- impl Pallet {
- // Learn about `AccountId`.
- fn mint(owner: T::AccountId) -> DispatchResult {
-- /* TODO: Remove the `unwrap_or` which is not needed when using `ValueQuery`. */
-- let current_count: u64 = CountForKitties::::get().unwrap_or(0);
-+ let current_count: u64 = CountForKitties::::get();
- let new_count = current_count.checked_add(1).ok_or(Error::::TooManyKitties)?;
-- /* TODO: Remove the `Option` wrapper when setting the `new_count`. */
-- CountForKitties::::set(Some(new_count));
-+ CountForKitties::::set(new_count);
- Self::deposit_event(Event::::Created { owner });
- Ok(())
- }
diff --git a/src/12/solution/src/impls.rs b/src/12/solution/src/impls.rs
new file mode 100644
index 00000000..1af97cbb
--- /dev/null
+++ b/src/12/solution/src/impls.rs
@@ -0,0 +1,13 @@
+use super::*;
+use frame_support::pallet_prelude::*;
+
+impl Pallet {
+ // Learn about `AccountId`.
+ pub fn mint(owner: T::AccountId) -> DispatchResult {
+ let current_count: u64 = CountForKitties::::get();
+ let new_count = current_count.checked_add(1).ok_or(Error::::TooManyKitties)?;
+ CountForKitties::::set(new_count);
+ Self::deposit_event(Event::::Created { owner });
+ Ok(())
+ }
+}
diff --git a/src/12/solution/src/lib.rs b/src/12/solution/src/lib.rs
index 446ce3ca..824c5aca 100644
--- a/src/12/solution/src/lib.rs
+++ b/src/12/solution/src/lib.rs
@@ -1,5 +1,7 @@
#![cfg_attr(not(feature = "std"), no_std)]
+mod impls;
+
pub use pallet::*;
// Learn about Macros used in the `polkadot-sdk`, making pallet development easier.
@@ -46,16 +48,4 @@ pub mod pallet {
Ok(())
}
}
-
- // Learn about internal functions.
- impl Pallet {
- // Learn about `AccountId`.
- fn mint(owner: T::AccountId) -> DispatchResult {
- let current_count: u64 = CountForKitties::::get();
- let new_count = current_count.checked_add(1).ok_or(Error::::TooManyKitties)?;
- CountForKitties::::set(new_count);
- Self::deposit_event(Event::::Created { owner });
- Ok(())
- }
- }
}
diff --git a/src/12/template/src/impls.rs b/src/12/template/src/impls.rs
new file mode 100644
index 00000000..99141c05
--- /dev/null
+++ b/src/12/template/src/impls.rs
@@ -0,0 +1,15 @@
+use super::*;
+use frame_support::pallet_prelude::*;
+
+impl Pallet {
+ // Learn about `AccountId`.
+ pub fn mint(owner: T::AccountId) -> DispatchResult {
+ /* TODO: Remove the `unwrap_or` which is not needed when using `ValueQuery`. */
+ let current_count: u64 = CountForKitties::::get().unwrap_or(0);
+ let new_count = current_count.checked_add(1).ok_or(Error::::TooManyKitties)?;
+ /* TODO: Remove the `Option` wrapper when setting the `new_count`. */
+ CountForKitties::::set(Some(new_count));
+ Self::deposit_event(Event::::Created { owner });
+ Ok(())
+ }
+}
diff --git a/src/12/template/src/lib.rs b/src/12/template/src/lib.rs
index 3b445c24..5ef793a3 100644
--- a/src/12/template/src/lib.rs
+++ b/src/12/template/src/lib.rs
@@ -1,5 +1,7 @@
#![cfg_attr(not(feature = "std"), no_std)]
+mod impls;
+
pub use pallet::*;
// Learn about Macros used in the `polkadot-sdk`, making pallet development easier.
@@ -47,18 +49,4 @@ pub mod pallet {
Ok(())
}
}
-
- // Learn about internal functions.
- impl Pallet {
- // Learn about `AccountId`.
- fn mint(owner: T::AccountId) -> DispatchResult {
- /* TODO: Remove the `unwrap_or` which is not needed when using `ValueQuery`. */
- let current_count: u64 = CountForKitties::::get().unwrap_or(0);
- let new_count = current_count.checked_add(1).ok_or(Error::::TooManyKitties)?;
- /* TODO: Remove the `Option` wrapper when setting the `new_count`. */
- CountForKitties::::set(Some(new_count));
- Self::deposit_event(Event::::Created { owner });
- Ok(())
- }
- }
}
diff --git a/src/12/template/template.diff b/src/12/template/template.diff
index eff48282..a39feda3 100644
--- a/src/12/template/template.diff
+++ b/src/12/template/template.diff
@@ -1,8 +1,23 @@
+diff --git a/src/impls.rs b/src/impls.rs
+index 9481d05..99141c0 100644
+--- a/src/impls.rs
++++ b/src/impls.rs
+@@ -4,8 +4,10 @@ use frame_support::pallet_prelude::*;
+ impl Pallet {
+ // Learn about `AccountId`.
+ pub fn mint(owner: T::AccountId) -> DispatchResult {
++ /* TODO: Remove the `unwrap_or` which is not needed when using `ValueQuery`. */
+ let current_count: u64 = CountForKitties::::get().unwrap_or(0);
+ let new_count = current_count.checked_add(1).ok_or(Error::::TooManyKitties)?;
++ /* TODO: Remove the `Option` wrapper when setting the `new_count`. */
+ CountForKitties::::set(Some(new_count));
+ Self::deposit_event(Event::::Created { owner });
+ Ok(())
diff --git a/src/lib.rs b/src/lib.rs
-index 2ed0e74..3b445c2 100644
+index 9ff62ff..5ef793a 100644
--- a/src/lib.rs
+++ b/src/lib.rs
-@@ -22,6 +22,7 @@ pub mod pallet {
+@@ -24,6 +24,7 @@ pub mod pallet {
/// Learn about storage value.
#[pallet::storage]
@@ -10,14 +25,3 @@ index 2ed0e74..3b445c2 100644
pub(super) type CountForKitties = StorageValue;
// Learn about events.
-@@ -51,8 +52,10 @@ pub mod pallet {
- impl Pallet {
- // Learn about `AccountId`.
- fn mint(owner: T::AccountId) -> DispatchResult {
-+ /* TODO: Remove the `unwrap_or` which is not needed when using `ValueQuery`. */
- let current_count: u64 = CountForKitties::::get().unwrap_or(0);
- let new_count = current_count.checked_add(1).ok_or(Error::::TooManyKitties)?;
-+ /* TODO: Remove the `Option` wrapper when setting the `new_count`. */
- CountForKitties::::set(Some(new_count));
- Self::deposit_event(Event::::Created { owner });
- Ok(())
diff --git a/src/13/source/changes.diff b/src/13/source/changes.diff
index 809a16c3..7b2265c8 100644
--- a/src/13/source/changes.diff
+++ b/src/13/source/changes.diff
@@ -1,8 +1,8 @@
diff --git a/src/lib.rs b/src/lib.rs
-index 446ce3c..c320583 100644
+index 824c5ac..38fafb0 100644
--- a/src/lib.rs
+++ b/src/lib.rs
-@@ -24,6 +24,10 @@ pub mod pallet {
+@@ -26,6 +26,10 @@ pub mod pallet {
#[pallet::storage]
pub(super) type CountForKitties = StorageValue;
diff --git a/src/13/source/src/impls.rs b/src/13/source/src/impls.rs
new file mode 100644
index 00000000..1af97cbb
--- /dev/null
+++ b/src/13/source/src/impls.rs
@@ -0,0 +1,13 @@
+use super::*;
+use frame_support::pallet_prelude::*;
+
+impl Pallet {
+ // Learn about `AccountId`.
+ pub fn mint(owner: T::AccountId) -> DispatchResult {
+ let current_count: u64 = CountForKitties::::get();
+ let new_count = current_count.checked_add(1).ok_or(Error::::TooManyKitties)?;
+ CountForKitties::::set(new_count);
+ Self::deposit_event(Event::::Created { owner });
+ Ok(())
+ }
+}
diff --git a/src/13/source/src/lib.rs b/src/13/source/src/lib.rs
index c3205834..38fafb0c 100644
--- a/src/13/source/src/lib.rs
+++ b/src/13/source/src/lib.rs
@@ -1,5 +1,7 @@
#![cfg_attr(not(feature = "std"), no_std)]
+mod impls;
+
pub use pallet::*;
// Learn about Macros used in the `polkadot-sdk`, making pallet development easier.
@@ -50,16 +52,4 @@ pub mod pallet {
Ok(())
}
}
-
- // Learn about internal functions.
- impl Pallet {
- // Learn about `AccountId`.
- fn mint(owner: T::AccountId) -> DispatchResult {
- let current_count: u64 = CountForKitties::::get();
- let new_count = current_count.checked_add(1).ok_or(Error::::TooManyKitties)?;
- CountForKitties::::set(new_count);
- Self::deposit_event(Event::::Created { owner });
- Ok(())
- }
- }
}
diff --git a/src/14/README.md b/src/14/README.md
index 061af0d2..cead1dba 100644
--- a/src/14/README.md
+++ b/src/14/README.md
@@ -17,9 +17,18 @@
-
+
+
-
+
+
+```rust
+{{#include ./template/src/impls.rs}}
+```
+
+
+
+
```rust
{{#include ./template/src/lib.rs}}
@@ -34,9 +43,18 @@
-
+
+
-
+
+
+```rust
+{{#include ./solution/src/impls.rs}}
+```
+
+
+
+
```rust
{{#include ./solution/src/lib.rs}}
diff --git a/src/14/solution/solution.diff b/src/14/solution/solution.diff
index d3d5ae5f..891afde3 100644
--- a/src/14/solution/solution.diff
+++ b/src/14/solution/solution.diff
@@ -1,8 +1,26 @@
+diff --git a/src/impls.rs b/src/impls.rs
+index e4449c9..c8320f8 100644
+--- a/src/impls.rs
++++ b/src/impls.rs
+@@ -3,11 +3,10 @@ use frame_support::pallet_prelude::*;
+
+ impl Pallet {
+ // Learn about `AccountId`.
+- /* TODO: Update this function signature to include `id` which is type `[u8; 16]`. */
+- pub fn mint(owner: T::AccountId) -> DispatchResult {
++ pub fn mint(owner: T::AccountId, dna: [u8; 16]) -> DispatchResult {
+ let current_count: u64 = CountForKitties::::get();
+ let new_count = current_count.checked_add(1).ok_or(Error::::TooManyKitties)?;
+- /* TODO: In the `Kitties` map, under the key `id`, insert `()`. */
++ Kitties::::insert(dna, ());
+ CountForKitties::::set(new_count);
+ Self::deposit_event(Event::::Created { owner });
+ Ok(())
diff --git a/src/lib.rs b/src/lib.rs
-index e1d2dd7..6a46bd4 100644
+index 978c774..331ff28 100644
--- a/src/lib.rs
+++ b/src/lib.rs
-@@ -46,9 +46,8 @@ pub mod pallet {
+@@ -48,9 +48,8 @@ pub mod pallet {
pub fn create_kitty(origin: OriginFor) -> DispatchResult {
// Learn about `origin`.
let who = ensure_signed(origin)?;
@@ -14,17 +32,3 @@ index e1d2dd7..6a46bd4 100644
Ok(())
}
}
-@@ -56,11 +55,10 @@ pub mod pallet {
- // Learn about internal functions.
- impl Pallet {
- // Learn about `AccountId`.
-- /* TODO: Update this function signature to include `id` which is type `[u8; 16]`. */
-- fn mint(owner: T::AccountId) -> DispatchResult {
-+ fn mint(owner: T::AccountId, dna: [u8; 16]) -> DispatchResult {
- let current_count: u64 = CountForKitties::::get();
- let new_count = current_count.checked_add(1).ok_or(Error::::TooManyKitties)?;
-- /* TODO: In the `Kitties` map, under the key `id`, insert `()`. */
-+ Kitties::::insert(dna, ());
- CountForKitties::::set(new_count);
- Self::deposit_event(Event::::Created { owner });
- Ok(())
diff --git a/src/14/solution/src/impls.rs b/src/14/solution/src/impls.rs
new file mode 100644
index 00000000..c8320f87
--- /dev/null
+++ b/src/14/solution/src/impls.rs
@@ -0,0 +1,14 @@
+use super::*;
+use frame_support::pallet_prelude::*;
+
+impl Pallet {
+ // Learn about `AccountId`.
+ pub fn mint(owner: T::AccountId, dna: [u8; 16]) -> DispatchResult {
+ let current_count: u64 = CountForKitties::::get();
+ let new_count = current_count.checked_add(1).ok_or(Error::::TooManyKitties)?;
+ Kitties::::insert(dna, ());
+ CountForKitties::::set(new_count);
+ Self::deposit_event(Event::::Created { owner });
+ Ok(())
+ }
+}
diff --git a/src/14/solution/src/lib.rs b/src/14/solution/src/lib.rs
index 6a46bd42..331ff28f 100644
--- a/src/14/solution/src/lib.rs
+++ b/src/14/solution/src/lib.rs
@@ -1,5 +1,7 @@
#![cfg_attr(not(feature = "std"), no_std)]
+mod impls;
+
pub use pallet::*;
// Learn about Macros used in the `polkadot-sdk`, making pallet development easier.
@@ -51,17 +53,4 @@ pub mod pallet {
Ok(())
}
}
-
- // Learn about internal functions.
- impl Pallet {
- // Learn about `AccountId`.
- fn mint(owner: T::AccountId, dna: [u8; 16]) -> DispatchResult {
- let current_count: u64 = CountForKitties::::get();
- let new_count = current_count.checked_add(1).ok_or(Error::::TooManyKitties)?;
- Kitties::::insert(dna, ());
- CountForKitties::::set(new_count);
- Self::deposit_event(Event::::Created { owner });
- Ok(())
- }
- }
}
diff --git a/src/14/template/src/impls.rs b/src/14/template/src/impls.rs
new file mode 100644
index 00000000..e4449c96
--- /dev/null
+++ b/src/14/template/src/impls.rs
@@ -0,0 +1,15 @@
+use super::*;
+use frame_support::pallet_prelude::*;
+
+impl Pallet {
+ // Learn about `AccountId`.
+ /* TODO: Update this function signature to include `id` which is type `[u8; 16]`. */
+ pub fn mint(owner: T::AccountId) -> DispatchResult {
+ let current_count: u64 = CountForKitties::::get();
+ let new_count = current_count.checked_add(1).ok_or(Error::::TooManyKitties)?;
+ /* TODO: In the `Kitties` map, under the key `id`, insert `()`. */
+ CountForKitties::::set(new_count);
+ Self::deposit_event(Event::::Created { owner });
+ Ok(())
+ }
+}
diff --git a/src/14/template/src/lib.rs b/src/14/template/src/lib.rs
index e1d2dd7f..978c774f 100644
--- a/src/14/template/src/lib.rs
+++ b/src/14/template/src/lib.rs
@@ -1,5 +1,7 @@
#![cfg_attr(not(feature = "std"), no_std)]
+mod impls;
+
pub use pallet::*;
// Learn about Macros used in the `polkadot-sdk`, making pallet development easier.
@@ -52,18 +54,4 @@ pub mod pallet {
Ok(())
}
}
-
- // Learn about internal functions.
- impl Pallet {
- // Learn about `AccountId`.
- /* TODO: Update this function signature to include `id` which is type `[u8; 16]`. */
- fn mint(owner: T::AccountId) -> DispatchResult {
- let current_count: u64 = CountForKitties::::get();
- let new_count = current_count.checked_add(1).ok_or(Error::::TooManyKitties)?;
- /* TODO: In the `Kitties` map, under the key `id`, insert `()`. */
- CountForKitties::::set(new_count);
- Self::deposit_event(Event::::Created { owner });
- Ok(())
- }
- }
}
diff --git a/src/14/template/template.diff b/src/14/template/template.diff
index 3d6247f4..f56e6a5e 100644
--- a/src/14/template/template.diff
+++ b/src/14/template/template.diff
@@ -1,8 +1,24 @@
+diff --git a/src/impls.rs b/src/impls.rs
+index 1af97cb..e4449c9 100644
+--- a/src/impls.rs
++++ b/src/impls.rs
+@@ -3,9 +3,11 @@ use frame_support::pallet_prelude::*;
+
+ impl Pallet {
+ // Learn about `AccountId`.
++ /* TODO: Update this function signature to include `id` which is type `[u8; 16]`. */
+ pub fn mint(owner: T::AccountId) -> DispatchResult {
+ let current_count: u64 = CountForKitties::::get();
+ let new_count = current_count.checked_add(1).ok_or(Error::::TooManyKitties)?;
++ /* TODO: In the `Kitties` map, under the key `id`, insert `()`. */
+ CountForKitties::::set(new_count);
+ Self::deposit_event(Event::::Created { owner });
+ Ok(())
diff --git a/src/lib.rs b/src/lib.rs
-index c320583..e1d2dd7 100644
+index 38fafb0..978c774 100644
--- a/src/lib.rs
+++ b/src/lib.rs
-@@ -46,6 +46,8 @@ pub mod pallet {
+@@ -48,6 +48,8 @@ pub mod pallet {
pub fn create_kitty(origin: OriginFor) -> DispatchResult {
// Learn about `origin`.
let who = ensure_signed(origin)?;
@@ -11,15 +27,3 @@ index c320583..e1d2dd7 100644
Self::mint(who)?;
Ok(())
}
-@@ -54,9 +56,11 @@ pub mod pallet {
- // Learn about internal functions.
- impl Pallet {
- // Learn about `AccountId`.
-+ /* TODO: Update this function signature to include `id` which is type `[u8; 16]`. */
- fn mint(owner: T::AccountId) -> DispatchResult {
- let current_count: u64 = CountForKitties::::get();
- let new_count = current_count.checked_add(1).ok_or(Error::::TooManyKitties)?;
-+ /* TODO: In the `Kitties` map, under the key `id`, insert `()`. */
- CountForKitties::::set(new_count);
- Self::deposit_event(Event::::Created { owner });
- Ok(())
diff --git a/src/15/README.md b/src/15/README.md
index 061af0d2..cead1dba 100644
--- a/src/15/README.md
+++ b/src/15/README.md
@@ -17,9 +17,18 @@
-
+
+
-
+
+
+```rust
+{{#include ./template/src/impls.rs}}
+```
+
+
+
+
```rust
{{#include ./template/src/lib.rs}}
@@ -34,9 +43,18 @@
-
+
+
-
+
+
+```rust
+{{#include ./solution/src/impls.rs}}
+```
+
+
+
+
```rust
{{#include ./solution/src/lib.rs}}
diff --git a/src/15/solution/solution.diff b/src/15/solution/solution.diff
index af0cde73..ceed39b4 100644
--- a/src/15/solution/solution.diff
+++ b/src/15/solution/solution.diff
@@ -1,8 +1,26 @@
+diff --git a/src/impls.rs b/src/impls.rs
+index c984894..650fdfb 100644
+--- a/src/impls.rs
++++ b/src/impls.rs
+@@ -4,10 +4,9 @@ use frame_support::pallet_prelude::*;
+ impl Pallet {
+ // Learn about `AccountId`.
+ pub fn mint(owner: T::AccountId, dna: [u8; 16]) -> DispatchResult {
+- /* TODO:
+- - `ensure!` that `Kitties` map does not `contains_key` for `dna`.
+- - If it does, return `Error::::DuplicateKitty`.
+- */
++ // Check if the kitty does not already exist in our storage map
++ ensure!(!Kitties::::contains_key(dna), Error::::DuplicateKitty);
++
+ let current_count: u64 = CountForKitties::::get();
+ let new_count = current_count.checked_add(1).ok_or(Error::::TooManyKitties)?;
+ Kitties::::insert(dna, ());
diff --git a/src/lib.rs b/src/lib.rs
-index 957c715..2b62b30 100644
+index f2120f9..a5bb629 100644
--- a/src/lib.rs
+++ b/src/lib.rs
-@@ -38,7 +38,7 @@ pub mod pallet {
+@@ -40,7 +40,7 @@ pub mod pallet {
#[pallet::error]
pub enum Error {
TooManyKitties,
@@ -11,17 +29,3 @@ index 957c715..2b62b30 100644
}
// Learn about callable functions and dispatch.
-@@ -57,10 +57,9 @@ pub mod pallet {
- impl Pallet {
- // Learn about `AccountId`.
- fn mint(owner: T::AccountId, dna: [u8; 16]) -> DispatchResult {
-- /* TODO:
-- - `ensure!` that `Kitties` map does not `contains_key` for `dna`.
-- - If it does, return `Error::::DuplicateKitty`.
-- */
-+ // Check if the kitty does not already exist in our storage map
-+ ensure!(!Kitties::::contains_key(dna), Error::::DuplicateKitty);
-+
- let current_count: u64 = CountForKitties::::get();
- let new_count = current_count.checked_add(1).ok_or(Error::::TooManyKitties)?;
- Kitties::::insert(dna, ());
diff --git a/src/15/solution/src/impls.rs b/src/15/solution/src/impls.rs
new file mode 100644
index 00000000..650fdfbe
--- /dev/null
+++ b/src/15/solution/src/impls.rs
@@ -0,0 +1,17 @@
+use super::*;
+use frame_support::pallet_prelude::*;
+
+impl Pallet {
+ // Learn about `AccountId`.
+ pub fn mint(owner: T::AccountId, dna: [u8; 16]) -> DispatchResult {
+ // Check if the kitty does not already exist in our storage map
+ ensure!(!Kitties::