-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
31d96ed
commit c0f3e05
Showing
188 changed files
with
14,380 additions
and
1,904 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,25 @@ | ||
diff --git a/src/lib.rs b/src/lib.rs | ||
index 3b445c2..446ce3c 100644 | ||
index 924f26f..2ed0e74 100644 | ||
--- a/src/lib.rs | ||
+++ b/src/lib.rs | ||
@@ -22,8 +22,7 @@ pub mod pallet { | ||
@@ -33,9 +33,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>; | ||
#[pallet::error] | ||
pub enum Error<T> { | ||
- /* TODO: | ||
- - Introduce a new error `TooManyKitties`. | ||
- */ | ||
+ TooManyKitties, | ||
} | ||
|
||
// Learn about events. | ||
#[pallet::event] | ||
@@ -52,11 +51,9 @@ pub mod pallet { | ||
impl<T: Config> Pallet<T> { | ||
// Learn about callable functions and dispatch. | ||
@@ -54,8 +52,7 @@ pub mod 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::<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); | ||
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(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,3 @@ | ||
# Value Query | ||
# Safe Math | ||
|
||
- TODO: | ||
- Explain storage as an option | ||
- Explain `OptionQuery` and `ValueQuery` | ||
- Explain default value | ||
- Explain safe math, overflows, saturating, checked, and APIs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,25 @@ | ||
diff --git a/src/lib.rs b/src/lib.rs | ||
index 2ed0e74..3b445c2 100644 | ||
index 59a65fe..924f26f 100644 | ||
--- a/src/lib.rs | ||
+++ b/src/lib.rs | ||
@@ -22,6 +22,7 @@ pub mod pallet { | ||
@@ -32,7 +32,11 @@ 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>; | ||
#[pallet::error] | ||
- pub enum Error<T> {} | ||
+ pub enum Error<T> { | ||
+ /* TODO: | ||
+ - Introduce a new error `TooManyKitties`. | ||
+ */ | ||
+ } | ||
|
||
// Learn about events. | ||
@@ -51,8 +52,10 @@ pub mod pallet { | ||
impl<T: Config> Pallet<T> { | ||
// Learn about callable functions and dispatch. | ||
#[pallet::call] | ||
@@ -50,6 +54,7 @@ pub mod 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::<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`. */ | ||
+ /* TODO: Update this logic to use safe math. */ | ||
let new_count = current_count + 1; | ||
CountForKitties::<T>::set(Some(new_count)); | ||
Self::deposit_event(Event::<T>::Created { owner }); | ||
Ok(()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(()) |
Oops, something went wrong.