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 Nov 1, 2024
1 parent 7370a7a commit b425085
Show file tree
Hide file tree
Showing 96 changed files with 255 additions and 176 deletions.
2 changes: 1 addition & 1 deletion src/0/source/changes.diff
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 00000000..c537f0b6
index 0000000..c537f0b
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,5 @@
Expand Down
12 changes: 6 additions & 6 deletions src/1/source/changes.diff
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
diff --git a/Cargo.lock b/Cargo.lock
new file mode 100644
index 00000000..31cbe7df
index 0000000..31cbe7d
--- /dev/null
+++ b/Cargo.lock
@@ -0,0 +1,3624 @@
Expand Down Expand Up @@ -3630,7 +3630,7 @@ index 00000000..31cbe7df
+]
diff --git a/Cargo.toml b/Cargo.toml
new file mode 100644
index 00000000..293d4f2a
index 0000000..293d4f2
--- /dev/null
+++ b/Cargo.toml
@@ -0,0 +1,26 @@
Expand Down Expand Up @@ -3662,7 +3662,7 @@ index 00000000..293d4f2a
+try-runtime = []
diff --git a/rustfmt.toml b/rustfmt.toml
new file mode 100644
index 00000000..cf9aa251
index 0000000..cf9aa25
--- /dev/null
+++ b/rustfmt.toml
@@ -0,0 +1,24 @@
Expand Down Expand Up @@ -3692,7 +3692,7 @@ index 00000000..cf9aa251
+wrap_comments = true
diff --git a/src/impls.rs b/src/impls.rs
new file mode 100644
index 00000000..03abf99e
index 0000000..03abf99
--- /dev/null
+++ b/src/impls.rs
@@ -0,0 +1,9 @@
Expand All @@ -3707,7 +3707,7 @@ index 00000000..03abf99e
+}
diff --git a/src/lib.rs b/src/lib.rs
new file mode 100644
index 00000000..ae8a09bc
index 0000000..ae8a09b
--- /dev/null
+++ b/src/lib.rs
@@ -0,0 +1,38 @@
Expand Down Expand Up @@ -3751,7 +3751,7 @@ index 00000000..ae8a09bc
+}
diff --git a/src/tests.rs b/src/tests.rs
new file mode 100644
index 00000000..375cd3f4
index 0000000..375cd3f
--- /dev/null
+++ b/src/tests.rs
@@ -0,0 +1,97 @@
Expand Down
2 changes: 1 addition & 1 deletion src/10/source/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
8 changes: 5 additions & 3 deletions src/11/solution/solution.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 7d88fffb..90242f63 100644
index 7d88fff..90242f6 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -18,11 +18,8 @@ pub mod pallet {
Expand All @@ -17,10 +17,10 @@ index 7d88fffb..90242f63 100644
#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
diff --git a/src/tests.rs b/src/tests.rs
index 8fa3dc60..d3e7ab78 100644
index 8fa3dc6..e271b01 100644
--- a/src/tests.rs
+++ b/src/tests.rs
@@ -117,3 +117,15 @@ fn create_kitty_emits_event() {
@@ -117,3 +117,17 @@ fn create_kitty_emits_event() {
System::assert_last_event(Event::<TestRuntime>::Created { owner: 1 }.into());
})
}
Expand All @@ -34,5 +34,7 @@ index 8fa3dc60..d3e7ab78 100644
+ CountForKitties::<TestRuntime>::set(Some(1337u32));
+ // You can `put` the value directly with a `u32`.
+ CountForKitties::<TestRuntime>::put(1337u32);
+ // Check that the value is now in storage.
+ assert_eq!(CountForKitties::<TestRuntime>::get(), Some(1337u32));
+ })
+}
2 changes: 2 additions & 0 deletions src/11/solution/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,5 +127,7 @@ fn count_for_kitties_created_correctly() {
CountForKitties::<TestRuntime>::set(Some(1337u32));
// You can `put` the value directly with a `u32`.
CountForKitties::<TestRuntime>::put(1337u32);
// Check that the value is now in storage.
assert_eq!(CountForKitties::<TestRuntime>::get(), Some(1337u32));
})
}
2 changes: 1 addition & 1 deletion src/11/template/template.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 ae8a09bc..7d88fffb 100644
index ae8a09b..7d88fff 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -18,6 +18,12 @@ pub mod pallet {
Expand Down
8 changes: 4 additions & 4 deletions src/12/solution/solution.diff
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/src/impls.rs b/src/impls.rs
index b396f986..97393307 100644
index b396f98..9739330 100644
--- a/src/impls.rs
+++ b/src/impls.rs
@@ -3,12 +3,9 @@ use frame::prelude::*;
Expand All @@ -19,11 +19,11 @@ index b396f986..97393307 100644
Ok(())
}
diff --git a/src/tests.rs b/src/tests.rs
index d3e7ab78..6318ca0b 100644
index e271b01..08f81b9 100644
--- a/src/tests.rs
+++ b/src/tests.rs
@@ -129,3 +129,15 @@ fn count_for_kitties_created_correctly() {
CountForKitties::<TestRuntime>::put(1337u32);
@@ -131,3 +131,15 @@ fn count_for_kitties_created_correctly() {
assert_eq!(CountForKitties::<TestRuntime>::get(), Some(1337u32));
})
}
+
Expand Down
2 changes: 2 additions & 0 deletions src/12/solution/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ fn count_for_kitties_created_correctly() {
CountForKitties::<TestRuntime>::set(Some(1337u32));
// You can `put` the value directly with a `u32`.
CountForKitties::<TestRuntime>::put(1337u32);
// Check that the value is now in storage.
assert_eq!(CountForKitties::<TestRuntime>::get(), Some(1337u32));
})
}

Expand Down
2 changes: 2 additions & 0 deletions src/12/template/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,5 +127,7 @@ fn count_for_kitties_created_correctly() {
CountForKitties::<TestRuntime>::set(Some(1337u32));
// You can `put` the value directly with a `u32`.
CountForKitties::<TestRuntime>::put(1337u32);
// Check that the value is now in storage.
assert_eq!(CountForKitties::<TestRuntime>::get(), Some(1337u32));
})
}
2 changes: 1 addition & 1 deletion src/12/template/template.diff
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/src/impls.rs b/src/impls.rs
index 03abf99e..b396f986 100644
index 03abf99..b396f98 100644
--- a/src/impls.rs
+++ b/src/impls.rs
@@ -3,6 +3,12 @@ use frame::prelude::*;
Expand Down
8 changes: 4 additions & 4 deletions src/13/solution/solution.diff
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/src/impls.rs b/src/impls.rs
index c550bc8d..7277e367 100644
index c550bc8..7277e36 100644
--- a/src/impls.rs
+++ b/src/impls.rs
@@ -4,8 +4,7 @@ use frame::prelude::*;
Expand All @@ -13,7 +13,7 @@ index c550bc8d..7277e367 100644
Self::deposit_event(Event::<T>::Created { owner });
Ok(())
diff --git a/src/lib.rs b/src/lib.rs
index 8edcc9b7..2c11f460 100644
index 8edcc9b..2c11f46 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -29,9 +29,7 @@ pub mod pallet {
Expand All @@ -28,10 +28,10 @@ index 8edcc9b7..2c11f460 100644

#[pallet::call]
diff --git a/src/tests.rs b/src/tests.rs
index 6318ca0b..5e74d29a 100644
index 08f81b9..089ada9 100644
--- a/src/tests.rs
+++ b/src/tests.rs
@@ -141,3 +141,16 @@ fn mint_increments_count_for_kitty() {
@@ -143,3 +143,16 @@ fn mint_increments_count_for_kitty() {
assert_eq!(CountForKitties::<TestRuntime>::get(), Some(1));
})
}
Expand Down
2 changes: 2 additions & 0 deletions src/13/solution/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ fn count_for_kitties_created_correctly() {
CountForKitties::<TestRuntime>::set(Some(1337u32));
// You can `put` the value directly with a `u32`.
CountForKitties::<TestRuntime>::put(1337u32);
// Check that the value is now in storage.
assert_eq!(CountForKitties::<TestRuntime>::get(), Some(1337u32));
})
}

Expand Down
2 changes: 1 addition & 1 deletion src/13/template/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions src/13/template/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ fn count_for_kitties_created_correctly() {
CountForKitties::<TestRuntime>::set(Some(1337u32));
// You can `put` the value directly with a `u32`.
CountForKitties::<TestRuntime>::put(1337u32);
// Check that the value is now in storage.
assert_eq!(CountForKitties::<TestRuntime>::get(), Some(1337u32));
})
}

Expand Down
4 changes: 2 additions & 2 deletions src/13/template/template.diff
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/src/impls.rs b/src/impls.rs
index 97393307..c550bc8d 100644
index 9739330..c550bc8 100644
--- a/src/impls.rs
+++ b/src/impls.rs
@@ -4,6 +4,7 @@ use frame::prelude::*;
Expand All @@ -11,7 +11,7 @@ index 97393307..c550bc8d 100644
CountForKitties::<T>::set(Some(new_count));
Self::deposit_event(Event::<T>::Created { owner });
diff --git a/src/lib.rs b/src/lib.rs
index 90242f63..8edcc9b7 100644
index 90242f6..8edcc9b 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -28,7 +28,11 @@ pub mod pallet {
Expand Down
15 changes: 9 additions & 6 deletions src/14/solution/solution.diff
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/src/impls.rs b/src/impls.rs
index b9b5548a..d283fd6b 100644
index b9b5548..d283fd6 100644
--- a/src/impls.rs
+++ b/src/impls.rs
@@ -3,11 +3,9 @@ use frame::prelude::*;
Expand All @@ -17,7 +17,7 @@ index b9b5548a..d283fd6b 100644
Ok(())
}
diff --git a/src/lib.rs b/src/lib.rs
index eeb9724b..57baa0d1 100644
index eeb9724..57baa0d 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -19,8 +19,7 @@ pub mod pallet {
Expand All @@ -31,10 +31,10 @@ index eeb9724b..57baa0d1 100644
#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
diff --git a/src/tests.rs b/src/tests.rs
index 5e74d29a..43af4064 100644
index 089ada9..43af406 100644
--- a/src/tests.rs
+++ b/src/tests.rs
@@ -121,10 +121,10 @@ fn create_kitty_emits_event() {
@@ -121,26 +121,24 @@ fn create_kitty_emits_event() {
#[test]
fn count_for_kitties_created_correctly() {
new_test_ext().execute_with(|| {
Expand All @@ -48,8 +48,11 @@ index 5e74d29a..43af4064 100644
+ CountForKitties::<TestRuntime>::set(1337u32);
// You can `put` the value directly with a `u32`.
CountForKitties::<TestRuntime>::put(1337u32);
- // Check that the value is now in storage.
- assert_eq!(CountForKitties::<TestRuntime>::get(), Some(1337u32));
})
@@ -133,12 +133,12 @@ fn count_for_kitties_created_correctly() {
}

#[test]
fn mint_increments_count_for_kitty() {
new_test_ext().execute_with(|| {
Expand All @@ -66,7 +69,7 @@ index 5e74d29a..43af4064 100644
})
}

@@ -146,7 +146,7 @@ fn mint_increments_count_for_kitty() {
@@ -148,7 +146,7 @@ fn mint_increments_count_for_kitty() {
fn mint_errors_when_overflow() {
new_test_ext().execute_with(|| {
// Set the count to the largest value possible.
Expand Down
2 changes: 2 additions & 0 deletions src/14/template/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ fn count_for_kitties_created_correctly() {
CountForKitties::<TestRuntime>::set(Some(1337u32));
// You can `put` the value directly with a `u32`.
CountForKitties::<TestRuntime>::put(1337u32);
// Check that the value is now in storage.
assert_eq!(CountForKitties::<TestRuntime>::get(), Some(1337u32));
})
}

Expand Down
4 changes: 2 additions & 2 deletions src/14/template/template.diff
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/src/impls.rs b/src/impls.rs
index 7277e367..b9b5548a 100644
index 7277e36..b9b5548 100644
--- a/src/impls.rs
+++ b/src/impls.rs
@@ -3,8 +3,10 @@ use frame::prelude::*;
Expand All @@ -14,7 +14,7 @@ index 7277e367..b9b5548a 100644
Self::deposit_event(Event::<T>::Created { owner });
Ok(())
diff --git a/src/lib.rs b/src/lib.rs
index 2c11f460..eeb9724b 100644
index 2c11f46..eeb9724 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -19,6 +19,7 @@ pub mod pallet {
Expand Down
4 changes: 2 additions & 2 deletions src/15/solution/solution.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 bb395631..42fb376b 100644
index bb39563..42fb376 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -21,12 +21,8 @@ pub mod pallet {
Expand All @@ -18,7 +18,7 @@ index bb395631..42fb376b 100644
#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
diff --git a/src/tests.rs b/src/tests.rs
index 43af4064..a564bb30 100644
index 43af406..a564bb3 100644
--- a/src/tests.rs
+++ b/src/tests.rs
@@ -154,3 +154,13 @@ fn mint_errors_when_overflow() {
Expand Down
2 changes: 2 additions & 0 deletions src/15/template/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 item needs its own `#[pallet::storage]` attribute.

## Conceptual

The key difference between a `StorageValue` and a `StorageMap` is:
Expand Down
2 changes: 1 addition & 1 deletion src/15/template/template.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 57baa0d1..bb395631 100644
index 57baa0d..bb39563 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -21,6 +21,13 @@ pub mod pallet {
Expand Down
14 changes: 7 additions & 7 deletions src/16/solution/solution.diff
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
diff --git a/src/impls.rs b/src/impls.rs
index 89c7306a..363f5e49 100644
index 4443702..363f5e4 100644
--- a/src/impls.rs
+++ b/src/impls.rs
@@ -2,11 +2,10 @@ use super::*;
use frame::prelude::*;

impl<T: Config> Pallet<T> {
- /* 🚧 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 {
+ pub fn mint(owner: T::AccountId, dna: [u8; 32]) -> DispatchResult {
let current_count: u32 = 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 `()`. */
- /* 🚧 TODO 🚧: In the `Kitties` map, under the key `dna`, insert `()`. */
+ Kitties::<T>::insert(dna, ());
CountForKitties::<T>::set(new_count);
Self::deposit_event(Event::<T>::Created { owner });
Ok(())
diff --git a/src/lib.rs b/src/lib.rs
index 2a83b473..15fb5043 100644
index 717c900..15fb504 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -39,11 +39,8 @@ pub mod pallet {
impl<T: Config> Pallet<T> {
pub fn create_kitty(origin: OriginFor<T>) -> 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 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)?;
+ let dna = [0u8; 32];
Expand All @@ -35,7 +35,7 @@ index 2a83b473..15fb5043 100644
}
}
diff --git a/src/tests.rs b/src/tests.rs
index a564bb30..1da91ca7 100644
index a564bb3..1da91ca 100644
--- a/src/tests.rs
+++ b/src/tests.rs
@@ -164,3 +164,11 @@ fn kitties_map_created_correctly() {
Expand Down
Loading

0 comments on commit b425085

Please sign in to comment.