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 Jul 31, 2024
1 parent 6ef8191 commit e273ed1
Show file tree
Hide file tree
Showing 154 changed files with 2,821 additions and 2,320 deletions.
9 changes: 9 additions & 0 deletions src/1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<div class="tab">
<button class="subtab tablinks file-source file-added active" onclick="switchSubTab(event, 'Cargo.toml')" data-id="Cargo.toml">Cargo.toml</button>
<button class="subtab tablinks file-source file-added" onclick="switchSubTab(event, 'rustfmt.toml')" data-id="rustfmt.toml">rustfmt.toml</button>
<button class="subtab tablinks file-source file-added" onclick="switchSubTab(event, 'src/impls.rs')" data-id="src/impls.rs">src/impls.rs</button>
<button class="subtab tablinks file-source file-added" onclick="switchSubTab(event, 'src/lib.rs')" data-id="src/lib.rs">src/lib.rs</button>
</div>
<div id="source/Cargo.toml" class="subtab tabcontent active" data-id="Cargo.toml">
Expand All @@ -35,6 +36,14 @@

</div>

<div id="source/src/impls.rs" class="subtab tabcontent" data-id="src/impls.rs">

```rust
{{#include ./source/src/impls.rs}}
```

</div>

<div id="source/src/lib.rs" class="subtab tabcontent" data-id="src/lib.rs">

```rust
Expand Down
28 changes: 19 additions & 9 deletions src/1/source/changes.diff
Original file line number Diff line number Diff line change
Expand Up @@ -4069,14 +4069,31 @@ index 0000000..c342153
+# Format comments
+comment_width = 100
+wrap_comments = true
diff --git a/src/impls.rs b/src/impls.rs
new file mode 100644
index 0000000..d49f793
--- /dev/null
+++ b/src/impls.rs
@@ -0,0 +1,9 @@
+use super::*;
+use frame_support::pallet_prelude::*;
+
+impl<T: Config> Pallet<T> {
+ pub fn mint(owner: T::AccountId) -> DispatchResult {
+ Self::deposit_event(Event::<T>::Created { owner });
+ Ok(())
+ }
+}
diff --git a/src/lib.rs b/src/lib.rs
new file mode 100644
index 0000000..8b9507e
index 0000000..f846f0b
--- /dev/null
+++ b/src/lib.rs
@@ -0,0 +1,43 @@
@@ -0,0 +1,38 @@
+#![cfg_attr(not(feature = "std"), no_std)]
+
+mod impls;
+
+pub use pallet::*;
+
+#[frame_support::pallet(dev_mode)]
Expand Down Expand Up @@ -4110,11 +4127,4 @@ index 0000000..8b9507e
+ Ok(())
+ }
+ }
+
+ impl<T: Config> Pallet<T> {
+ fn mint(owner: T::AccountId) -> DispatchResult {
+ Self::deposit_event(Event::<T>::Created { owner });
+ Ok(())
+ }
+ }
+}
9 changes: 9 additions & 0 deletions src/1/source/src/impls.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use super::*;
use frame_support::pallet_prelude::*;

impl<T: Config> Pallet<T> {
pub fn mint(owner: T::AccountId) -> DispatchResult {
Self::deposit_event(Event::<T>::Created { owner });
Ok(())
}
}
9 changes: 2 additions & 7 deletions src/1/source/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#![cfg_attr(not(feature = "std"), no_std)]

mod impls;

pub use pallet::*;

#[frame_support::pallet(dev_mode)]
Expand Down Expand Up @@ -33,11 +35,4 @@ pub mod pallet {
Ok(())
}
}

impl<T: Config> Pallet<T> {
fn mint(owner: T::AccountId) -> DispatchResult {
Self::deposit_event(Event::<T>::Created { owner });
Ok(())
}
}
}
12 changes: 6 additions & 6 deletions src/10/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
<div id="Template" class="maintab tabcontent active">

<div class="tab">
<button class="subtab tablinks file-template file-modified active" onclick="switchSubTab(event, 'src/lib.rs')" data-id="src/lib.rs">src/lib.rs</button>
<button class="subtab tablinks file-template file-modified active" onclick="switchSubTab(event, 'src/impls.rs')" data-id="src/impls.rs">src/impls.rs</button>
</div>
<div id="template/src/lib.rs" class="subtab tabcontent active" data-id="src/lib.rs">
<div id="template/src/impls.rs" class="subtab tabcontent active" data-id="src/impls.rs">

```rust
{{#include ./template/src/lib.rs}}
{{#include ./template/src/impls.rs}}
```

</div>
Expand All @@ -34,12 +34,12 @@
<div id="Solution" class="maintab tabcontent">

<div class="tab">
<button class="subtab tablinks file-solution file-modified active" onclick="switchSubTab(event, 'src/lib.rs')" data-id="src/lib.rs">src/lib.rs</button>
<button class="subtab tablinks file-solution file-modified active" onclick="switchSubTab(event, 'src/impls.rs')" data-id="src/impls.rs">src/impls.rs</button>
</div>
<div id="solution/src/lib.rs" class="subtab tabcontent active" data-id="src/lib.rs">
<div id="solution/src/impls.rs" class="subtab tabcontent active" data-id="src/impls.rs">

```rust
{{#include ./solution/src/lib.rs}}
{{#include ./solution/src/impls.rs}}
```

</div>
Expand Down
40 changes: 20 additions & 20 deletions src/10/solution/solution.diff
Original file line number Diff line number Diff line change
@@ -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<T: Config> Pallet<T> {
// 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::<T>::get().unwrap_or(0);
+ let new_count = current_count + 1;
+ CountForKitties::<T>::set(Some(new_count));
Self::deposit_event(Event::<T>::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<T: Config> Pallet<T> {
// 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::<T>::get().unwrap_or(0);
+ let new_count = current_count + 1;
+ CountForKitties::<T>::set(Some(new_count));
Self::deposit_event(Event::<T>::Created { owner });
Ok(())
}
13 changes: 13 additions & 0 deletions src/10/solution/src/impls.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use super::*;
use frame_support::pallet_prelude::*;

impl<T: Config> Pallet<T> {
// Learn about `AccountId`.
pub fn mint(owner: T::AccountId) -> DispatchResult {
let current_count: u64 = CountForKitties::<T>::get().unwrap_or(0);
let new_count = current_count + 1;
CountForKitties::<T>::set(Some(new_count));
Self::deposit_event(Event::<T>::Created { owner });
Ok(())
}
}
14 changes: 2 additions & 12 deletions src/10/solution/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -44,16 +46,4 @@ pub mod pallet {
Ok(())
}
}

// Learn about internal functions.
impl<T: Config> Pallet<T> {
// Learn about `AccountId`.
fn mint(owner: T::AccountId) -> DispatchResult {
let current_count: u64 = CountForKitties::<T>::get().unwrap_or(0);
let new_count = current_count + 1;
CountForKitties::<T>::set(Some(new_count));
Self::deposit_event(Event::<T>::Created { owner });
Ok(())
}
}
}
16 changes: 16 additions & 0 deletions src/10/template/src/impls.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use super::*;
use frame_support::pallet_prelude::*;

impl<T: Config> Pallet<T> {
// 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::<T>::Created { owner });
Ok(())
}
}
17 changes: 2 additions & 15 deletions src/10/template/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -44,19 +46,4 @@ pub mod pallet {
Ok(())
}
}

// Learn about internal functions.
impl<T: Config> Pallet<T> {
// 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::<T>::Created { owner });
Ok(())
}
}
}
34 changes: 17 additions & 17 deletions src/10/template/template.diff
Original file line number Diff line number Diff line change
@@ -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<T: Config> Pallet<T> {
// 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::<T>::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<T: Config> Pallet<T> {
// 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::<T>::Created { owner });
Ok(())
}
26 changes: 22 additions & 4 deletions src/11/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,18 @@
<div id="Template" class="maintab tabcontent active">

<div class="tab">
<button class="subtab tablinks file-template file-modified active" onclick="switchSubTab(event, 'src/lib.rs')" data-id="src/lib.rs">src/lib.rs</button>
<button class="subtab tablinks file-template file-modified active" onclick="switchSubTab(event, 'src/impls.rs')" data-id="src/impls.rs">src/impls.rs</button>
<button class="subtab tablinks file-template file-modified" onclick="switchSubTab(event, 'src/lib.rs')" data-id="src/lib.rs">src/lib.rs</button>
</div>
<div id="template/src/lib.rs" class="subtab tabcontent active" data-id="src/lib.rs">
<div id="template/src/impls.rs" class="subtab tabcontent active" data-id="src/impls.rs">

```rust
{{#include ./template/src/impls.rs}}
```

</div>

<div id="template/src/lib.rs" class="subtab tabcontent" data-id="src/lib.rs">

```rust
{{#include ./template/src/lib.rs}}
Expand All @@ -34,9 +43,18 @@
<div id="Solution" class="maintab tabcontent">

<div class="tab">
<button class="subtab tablinks file-solution file-modified active" onclick="switchSubTab(event, 'src/lib.rs')" data-id="src/lib.rs">src/lib.rs</button>
<button class="subtab tablinks file-solution file-modified active" onclick="switchSubTab(event, 'src/impls.rs')" data-id="src/impls.rs">src/impls.rs</button>
<button class="subtab tablinks file-solution file-modified" onclick="switchSubTab(event, 'src/lib.rs')" data-id="src/lib.rs">src/lib.rs</button>
</div>
<div id="solution/src/lib.rs" class="subtab tabcontent active" data-id="src/lib.rs">
<div id="solution/src/impls.rs" class="subtab tabcontent active" data-id="src/impls.rs">

```rust
{{#include ./solution/src/impls.rs}}
```

</div>

<div id="solution/src/lib.rs" class="subtab tabcontent" data-id="src/lib.rs">

```rust
{{#include ./solution/src/lib.rs}}
Expand Down
28 changes: 16 additions & 12 deletions src/11/solution/solution.diff
Original file line number Diff line number Diff line change
@@ -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<T: Config> Pallet<T> {
// Learn about `AccountId`.
pub fn mint(owner: T::AccountId) -> DispatchResult {
let current_count: u64 = CountForKitties::<T>::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::<T>::TooManyKitties)?;
CountForKitties::<T>::set(Some(new_count));
Self::deposit_event(Event::<T>::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<T> {
Expand All @@ -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::<T>::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::<T>::TooManyKitties)?;
CountForKitties::<T>::set(Some(new_count));
Self::deposit_event(Event::<T>::Created { owner });
Ok(())
13 changes: 13 additions & 0 deletions src/11/solution/src/impls.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use super::*;
use frame_support::pallet_prelude::*;

impl<T: Config> Pallet<T> {
// Learn about `AccountId`.
pub fn mint(owner: T::AccountId) -> DispatchResult {
let current_count: u64 = CountForKitties::<T>::get().unwrap_or(0);
let new_count = current_count.checked_add(1).ok_or(Error::<T>::TooManyKitties)?;
CountForKitties::<T>::set(Some(new_count));
Self::deposit_event(Event::<T>::Created { owner });
Ok(())
}
}
Loading

0 comments on commit e273ed1

Please sign in to comment.