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 22, 2024
1 parent 17d04bd commit 9b60c47
Show file tree
Hide file tree
Showing 173 changed files with 51,508 additions and 434 deletions.
8 changes: 8 additions & 0 deletions src/0/source/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
# Kitties Tutorial

Welcome to the new Substrate Collectables Workshop.

TODO: Content.
- Blockchain
- Runtime
- Pallet
- NFTs
9 changes: 5 additions & 4 deletions src/0/source/changes.diff
Original file line number Diff line number Diff line change
Expand Up @@ -4082,10 +4082,10 @@ index 0000000..2e09572
+try-runtime = []
diff --git a/src/lib.rs b/src/lib.rs
new file mode 100644
index 0000000..80f2418
index 0000000..8b9507e
--- /dev/null
+++ b/src/lib.rs
@@ -0,0 +1,42 @@
@@ -0,0 +1,43 @@
+#![cfg_attr(not(feature = "std"), no_std)]
+
+pub use pallet::*;
Expand Down Expand Up @@ -4117,14 +4117,15 @@ index 0000000..80f2418
+ impl<T: Config> Pallet<T> {
+ pub fn create_kitty(origin: OriginFor<T>) -> DispatchResult {
+ let who = ensure_signed(origin)?;
+ Self::mint(who);
+ Self::mint(who)?;
+ Ok(())
+ }
+ }
+
+ impl<T: Config> Pallet<T> {
+ fn mint(owner: T::AccountId) {
+ fn mint(owner: T::AccountId) -> DispatchResult {
+ Self::deposit_event(Event::<T>::Created { owner });
+ Ok(())
+ }
+ }
+}
5 changes: 3 additions & 2 deletions src/0/source/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@ pub mod pallet {
impl<T: Config> Pallet<T> {
pub fn create_kitty(origin: OriginFor<T>) -> DispatchResult {
let who = ensure_signed(origin)?;
Self::mint(who);
Self::mint(who)?;
Ok(())
}
}

impl<T: Config> Pallet<T> {
fn mint(owner: T::AccountId) {
fn mint(owner: T::AccountId) -> DispatchResult {
Self::deposit_event(Event::<T>::Created { owner });
Ok(())
}
}
}
4 changes: 3 additions & 1 deletion src/1/source/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# Kitties Tutorial
# FRAME Macros

- TODO: Teach the basics of FRAME macros.
2 changes: 1 addition & 1 deletion src/1/source/changes.diff
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/src/lib.rs b/src/lib.rs
index 80f2418..09a9d86 100644
index 8b9507e..44cc2ec 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -2,6 +2,7 @@
Expand Down
5 changes: 3 additions & 2 deletions src/1/source/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ pub mod pallet {
impl<T: Config> Pallet<T> {
pub fn create_kitty(origin: OriginFor<T>) -> DispatchResult {
let who = ensure_signed(origin)?;
Self::mint(who);
Self::mint(who)?;
Ok(())
}
}

impl<T: Config> Pallet<T> {
fn mint(owner: T::AccountId) {
fn mint(owner: T::AccountId) -> DispatchResult {
Self::deposit_event(Event::<T>::Created { owner });
Ok(())
}
}
}
45 changes: 36 additions & 9 deletions src/10/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,44 @@
<div class="content-row">
<div class="content-col">

{{#include ./source/README.md}}
{{#include ./template/README.md}}

</div>

<div class="content-col">

<div class="tab">
<button class="maintab tablinks active" onclick="switchMainTab(event, 'Source')">Source</button>
<button class="maintab tablinks active" onclick="switchMainTab(event, 'Template')">Template</button>
<button class="maintab tablinks" onclick="switchMainTab(event, 'Solution')">Solution</button>
<button class="maintab tablinks" onclick="switchMainTab(event, 'Diff')">Diff</button>
</div>

<div id="Source" class="maintab tabcontent active">
<div id="Template" class="maintab tabcontent active">

<div class="tab">
<button class="subtab tablinks file-source 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/lib.rs')" data-id="src/lib.rs">src/lib.rs</button>
</div>
<div id="source/src/lib.rs" class="subtab tabcontent active" data-id="src/lib.rs">
<div id="template/src/lib.rs" class="subtab tabcontent active" data-id="src/lib.rs">

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

</div>



</div>

<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>
</div>
<div id="solution/src/lib.rs" class="subtab tabcontent active" data-id="src/lib.rs">

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

</div>
Expand All @@ -33,12 +52,20 @@


<div class="tab">
<button class="difftab tablinks active" onclick="switchDiff(event, 'changes.diff')" data-id="changes.diff">changes.diff</button>
<button class="difftab tablinks active" onclick="switchDiff(event, 'template.diff')" data-id="template.diff">template.diff</button>
<button class="difftab tablinks" onclick="switchDiff(event, 'solution.diff')" data-id="solution.diff">solution.diff</button>
</div>
<div id="template.diff" class="difftab tabcontent active" data-id="template.diff">

```diff
{{#include ./template/template.diff}}
```

</div>
<div id="changes.diff" class="difftab tabcontent active" data-id="changes.diff">
<div id="solution.diff" class="difftab tabcontent" data-id="solution.diff">

```diff
{{#include ./source/changes.diff}}
{{#include ./solution/solution.diff}}
```

</div>
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions src/10/solution/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Solution

Here you will find the solution for the previous step.
28 changes: 28 additions & 0 deletions src/10/solution/solution.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
diff --git a/src/lib.rs b/src/lib.rs
index 3b445c2..446ce3c 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -22,8 +22,7 @@ pub mod pallet {

/// Learn about storage value.
#[pallet::storage]
- /* TODO: Update this storage to use a `QueryKind` of `ValueQuery`. */
- pub(super) type CountForKitties<T: Config> = StorageValue<Value = u64>;
+ pub(super) type CountForKitties<T: Config> = StorageValue<Value = u64, QueryKind = ValueQuery>;

// Learn about events.
#[pallet::event]
@@ -52,11 +51,9 @@ pub mod pallet {
impl<T: Config> Pallet<T> {
// 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::<T>::get().unwrap_or(0);
+ let current_count: u64 = CountForKitties::<T>::get();
let new_count = current_count.checked_add(1).ok_or(Error::<T>::TooManyKitties)?;
- /* TODO: Remove the `Option` wrapper when setting the `new_count`. */
- CountForKitties::<T>::set(Some(new_count));
+ CountForKitties::<T>::set(new_count);
Self::deposit_event(Event::<T>::Created { owner });
Ok(())
}
14 changes: 3 additions & 11 deletions src/11/template/src/lib.rs → src/10/solution/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@ pub mod pallet {

/// Learn about storage value.
#[pallet::storage]
pub(super) type CountForKitties<T: Config> = StorageValue<Value = u64>;

/// Learn about storage maps.
#[pallet::storage]
pub(super) type Kitties<T: Config> = StorageMap<Key = [u8; 16], Value = ()>;
pub(super) type CountForKitties<T: Config> = StorageValue<Value = u64, QueryKind = ValueQuery>;

// Learn about events.
#[pallet::event]
Expand All @@ -46,8 +42,6 @@ pub mod pallet {
pub fn create_kitty(origin: OriginFor<T>) -> DispatchResult {
// Learn about `origin`.
let who = ensure_signed(origin)?;
/* TODO: Create `const default_id`, which type `[u8; 16]` and has value `[0u8; 16]`. */
/* TODO: Pass `default_id` to the `mint` function. */
Self::mint(who)?;
Ok(())
}
Expand All @@ -56,12 +50,10 @@ pub mod pallet {
// Learn about internal functions.
impl<T: Config> Pallet<T> {
// 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 = CountForKitties::<T>::get().unwrap_or(0);
let current_count: u64 = CountForKitties::<T>::get();
let new_count = current_count.checked_add(1).ok_or(Error::<T>::TooManyKitties)?;
/* TODO: In the `Kitties` map, under the key `id`, insert `()`. */
CountForKitties::<T>::set(Some(new_count));
CountForKitties::<T>::set(new_count);
Self::deposit_event(Event::<T>::Created { owner });
Ok(())
}
Expand Down
1 change: 0 additions & 1 deletion src/10/source/README.md

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions src/10/template/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Value Query

- TODO:
- Explain storage as an option
- Explain `OptionQuery` and `ValueQuery`
- Explain default value
15 changes: 6 additions & 9 deletions src/11/solution/src/lib.rs → src/10/template/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,9 @@ pub mod pallet {

/// Learn about storage value.
#[pallet::storage]
/* TODO: Update this storage to use a `QueryKind` of `ValueQuery`. */
pub(super) type CountForKitties<T: Config> = StorageValue<Value = u64>;

/// Learn about storage maps.
#[pallet::storage]
pub(super) type Kitties<T: Config> = StorageMap<Key = [u8; 16], Value = ()>;

// Learn about events.
#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
Expand All @@ -46,19 +43,19 @@ pub mod pallet {
pub fn create_kitty(origin: OriginFor<T>) -> DispatchResult {
// Learn about `origin`.
let who = ensure_signed(origin)?;
let dna = [0u8; 16];
Self::mint(who, dna)?;
Self::mint(who)?;
Ok(())
}
}

// Learn about internal functions.
impl<T: Config> Pallet<T> {
// Learn about `AccountId`.
fn mint(owner: T::AccountId, dna: [u8; 16]) -> DispatchResult {
let current_count = CountForKitties::<T>::get().unwrap_or(0);
fn mint(owner: T::AccountId) -> DispatchResult {
/* TODO: Remove the `unwrap_or` which is not needed when using `ValueQuery`. */
let current_count: u64 = CountForKitties::<T>::get().unwrap_or(0);
let new_count = current_count.checked_add(1).ok_or(Error::<T>::TooManyKitties)?;
Kitties::<T>::insert(dna, ());
/* TODO: Remove the `Option` wrapper when setting the `new_count`. */
CountForKitties::<T>::set(Some(new_count));
Self::deposit_event(Event::<T>::Created { owner });
Ok(())
Expand Down
23 changes: 23 additions & 0 deletions src/10/template/template.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
diff --git a/src/lib.rs b/src/lib.rs
index 2ed0e74..3b445c2 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -22,6 +22,7 @@ pub mod pallet {

/// Learn about storage value.
#[pallet::storage]
+ /* TODO: Update this storage to use a `QueryKind` of `ValueQuery`. */
pub(super) type CountForKitties<T: Config> = StorageValue<Value = u64>;

// Learn about events.
@@ -51,8 +52,10 @@ pub mod pallet {
impl<T: Config> Pallet<T> {
// 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::<T>::get().unwrap_or(0);
let new_count = current_count.checked_add(1).ok_or(Error::<T>::TooManyKitties)?;
+ /* TODO: Remove the `Option` wrapper when setting the `new_count`. */
CountForKitties::<T>::set(Some(new_count));
Self::deposit_event(Event::<T>::Created { owner });
Ok(())
45 changes: 9 additions & 36 deletions src/11/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,25 @@
<div class="content-row">
<div class="content-col">

{{#include ./template/README.md}}
{{#include ./source/README.md}}

</div>

<div class="content-col">

<div class="tab">
<button class="maintab tablinks active" onclick="switchMainTab(event, 'Template')">Template</button>
<button class="maintab tablinks" onclick="switchMainTab(event, 'Solution')">Solution</button>
<button class="maintab tablinks active" onclick="switchMainTab(event, 'Source')">Source</button>
<button class="maintab tablinks" onclick="switchMainTab(event, 'Diff')">Diff</button>
</div>

<div id="Template" class="maintab tabcontent active">
<div id="Source" 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-source file-modified active" 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="source/src/lib.rs" class="subtab tabcontent active" data-id="src/lib.rs">

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

</div>



</div>

<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>
</div>
<div id="solution/src/lib.rs" class="subtab tabcontent active" data-id="src/lib.rs">

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

</div>
Expand All @@ -52,20 +33,12 @@


<div class="tab">
<button class="difftab tablinks active" onclick="switchDiff(event, 'template.diff')" data-id="template.diff">template.diff</button>
<button class="difftab tablinks" onclick="switchDiff(event, 'solution.diff')" data-id="solution.diff">solution.diff</button>
</div>
<div id="template.diff" class="difftab tabcontent active" data-id="template.diff">

```diff
{{#include ./template/template.diff}}
```

<button class="difftab tablinks active" onclick="switchDiff(event, 'changes.diff')" data-id="changes.diff">changes.diff</button>
</div>
<div id="solution.diff" class="difftab tabcontent" data-id="solution.diff">
<div id="changes.diff" class="difftab tabcontent active" data-id="changes.diff">

```diff
{{#include ./solution/solution.diff}}
{{#include ./source/changes.diff}}
```

</div>
Expand Down
1 change: 0 additions & 1 deletion src/11/solution/README.md

This file was deleted.

Loading

0 comments on commit 9b60c47

Please sign in to comment.