Skip to content

Commit

Permalink
add a construction sign to the TODO
Browse files Browse the repository at this point in the history
  • Loading branch information
shawntabrizi committed Aug 2, 2024
1 parent 80ce88b commit 6fcb5c9
Show file tree
Hide file tree
Showing 39 changed files with 52 additions and 52 deletions.
2 changes: 1 addition & 1 deletion steps/10/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use frame_support::pallet_prelude::*;

impl<T: Config> Pallet<T> {
pub fn mint(owner: T::AccountId) -> DispatchResult {
/* TODO:
/* 🚧 TODO 🚧:
- `get` the current count of kitties.
- `unwrap_or` set the count to `0`.
- increment the count by one.
Expand Down
2 changes: 1 addition & 1 deletion steps/12/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use frame_support::pallet_prelude::*;
impl<T: Config> Pallet<T> {
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. */
/* 🚧 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 });
Expand Down
2 changes: 1 addition & 1 deletion steps/12/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub mod pallet {

#[pallet::error]
pub enum Error<T> {
/* TODO:
/* 🚧 TODO 🚧:
- Introduce a new error `TooManyKitties`.
*/
}
Expand Down
4 changes: 2 additions & 2 deletions steps/14/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ use frame_support::pallet_prelude::*;

impl<T: Config> Pallet<T> {
pub fn mint(owner: T::AccountId) -> DispatchResult {
/* TODO: Remove the `unwrap_or` which is not needed when using `ValueQuery`. */
/* 🚧 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 🚧: 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
2 changes: 1 addition & 1 deletion steps/14/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub mod pallet {
}

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

#[pallet::event]
Expand Down
2 changes: 1 addition & 1 deletion steps/16/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub mod pallet {
#[pallet::storage]
pub(super) type CountForKitties<T: Config> = StorageValue<Value = u64, QueryKind = ValueQuery>;

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

Expand Down
4 changes: 2 additions & 2 deletions steps/17/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ use super::*;
use frame_support::pallet_prelude::*;

impl<T: Config> Pallet<T> {
/* TODO: Update this function signature to include `id` which is type `[u8; 16]`. */
/* 🚧 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::<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 `id`, insert `()`. */
CountForKitties::<T>::set(new_count);
Self::deposit_event(Event::<T>::Created { owner });
Ok(())
Expand Down
4 changes: 2 additions & 2 deletions steps/17/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +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; 16]` and has value `[0u8; 16]`. */
/* TODO: Pass `default_id` to the `mint` function as a second parameter. */
/* 🚧 TODO 🚧: Create `const default_id`, which type `[u8; 16]` and has value `[0u8; 16]`. */
/* 🚧 TODO 🚧: Pass `default_id` to the `mint` function as a second parameter. */
Self::mint(who)?;
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion steps/19/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use frame_support::pallet_prelude::*;

impl<T: Config> Pallet<T> {
pub fn mint(owner: T::AccountId, dna: [u8; 16]) -> DispatchResult {
/* TODO:
/* 🚧 TODO 🚧:
- `ensure!` that `Kitties` map does not `contains_key` for `dna`.
- If it does, return `Error::<T>::DuplicateKitty`.
*/
Expand Down
2 changes: 1 addition & 1 deletion steps/19/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub mod pallet {
#[pallet::error]
pub enum Error<T> {
TooManyKitties,
/* TODO: Create a new error `DuplicateKitty`. */
/* 🚧 TODO 🚧: Create a new error `DuplicateKitty`. */
}

#[pallet::call]
Expand Down
2 changes: 1 addition & 1 deletion steps/2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ mod impls;

pub use pallet::*;

/* TODO: Learn about macros used in the `polkadot-sdk`, making pallet development easier. */
/* 🚧 TODO 🚧: Learn about macros used in the `polkadot-sdk`, making pallet development easier. */
#[frame_support::pallet(dev_mode)]
pub mod pallet {
use super::*;
Expand Down
2 changes: 1 addition & 1 deletion steps/22/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub mod pallet {
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
}

/* TODO:
/* 🚧 TODO 🚧:
- Create a new `struct` called `Kitty`.
- Make `Kitty` generic over `T` where `T: Config`.
- Add two fields to `Kitty`:
Expand Down
4 changes: 2 additions & 2 deletions steps/24/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ use frame_support::pallet_prelude::*;

impl<T: Config> Pallet<T> {
pub fn mint(owner: T::AccountId, dna: [u8; 16]) -> DispatchResult {
/* TODO: Create a new variable `kitty` which is a `Kitty` struct with `dna` and `owner`. */
/* 🚧 TODO 🚧: Create a new variable `kitty` which is a `Kitty` struct with `dna` and `owner`. */

// Check if the kitty does not already exist in our storage map
ensure!(!Kitties::<T>::contains_key(dna), Error::<T>::DuplicateKitty);

let current_count: u64 = CountForKitties::<T>::get();
let new_count = current_count.checked_add(1).ok_or(Error::<T>::TooManyKitties)?;
/* TODO: Insert `kitty`into the map instead of `()`. */
/* 🚧 TODO 🚧: Insert `kitty`into the map instead of `()`. */
Kitties::<T>::insert(dna, ());
CountForKitties::<T>::set(new_count);
Self::deposit_event(Event::<T>::Created { owner });
Expand Down
4 changes: 2 additions & 2 deletions steps/24/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub mod pallet {
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
}

/* TODO:
/* 🚧 TODO 🚧:
- Add the derive macros needed for putting a struct in storage.
- Add `#[scale_info(skip_type_params(T))]` to ignore the generic `T`.
*/
Expand All @@ -32,7 +32,7 @@ pub mod pallet {
pub(super) type CountForKitties<T: Config> = StorageValue<Value = u64, QueryKind = ValueQuery>;

#[pallet::storage]
/* TODO: Update the `Value` to be type `Kitty<T>` instead of (). */
/* 🚧 TODO 🚧: Update the `Value` to be type `Kitty<T>` instead of (). */
pub(super) type Kitties<T: Config> = StorageMap<Key = [u8; 16], Value = ()>;

#[pallet::event]
Expand Down
2 changes: 1 addition & 1 deletion steps/26/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::*;
use frame_support::pallet_prelude::*;

impl<T: Config> Pallet<T> {
/* TODO: Create a function `gen_dna` which returns a `[u8; 16]`.
/* 🚧 TODO 🚧: Create a function `gen_dna` which returns a `[u8; 16]`.
- Create a `unique_payload` which contains data from `frame_system::Pallet::<T>`:
- `parent_hash`
- `block_number`
Expand Down
2 changes: 1 addition & 1 deletion steps/26/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub mod pallet {
impl<T: Config> Pallet<T> {
pub fn create_kitty(origin: OriginFor<T>) -> DispatchResult {
let who = ensure_signed(origin)?;
/* TODO: Use the `Self::gen_dna()` function to generate a unique Kitty. */
/* 🚧 TODO 🚧: Use the `Self::gen_dna()` function to generate a unique Kitty. */
let dna = [0u8; 16];
Self::mint(who, dna)?;
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion steps/28/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl<T: Config> Pallet<T> {
let current_count: u64 = CountForKitties::<T>::get();
let new_count = current_count.checked_add(1).ok_or(Error::<T>::TooManyKitties)?;

/* TODO: `append` the `dna` to the `KittiesOwned` storage for the `owner`. */
/* 🚧 TODO 🚧: `append` the `dna` to the `KittiesOwned` storage for the `owner`. */

Kitties::<T>::insert(dna, kitty);
CountForKitties::<T>::set(new_count);
Expand Down
2 changes: 1 addition & 1 deletion steps/28/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub mod pallet {
#[pallet::storage]
pub(super) type Kitties<T: Config> = StorageMap<Key = [u8; 16], Value = Kitty<T>>;

/* TODO: Create a new `StorageMap` called `KittiesOwned`.
/* 🚧 TODO 🚧: Create a new `StorageMap` called `KittiesOwned`.
- The `Key` of this map is `T::AccountId`.
- The `Value` of this map is `Vec<[u8; 16]>`.
- The `QueryKind` should be set to `ValueQuery`.
Expand Down
2 changes: 1 addition & 1 deletion steps/3/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub mod pallet {
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;

/* TODO: Learn about the Pallet struct. */
/* 🚧 TODO 🚧: Learn about the Pallet struct. */
#[pallet::pallet]
pub struct Pallet<T>(_);

Expand Down
2 changes: 1 addition & 1 deletion steps/30/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl<T: Config> Pallet<T> {
let current_count: u64 = CountForKitties::<T>::get();
let new_count = current_count.checked_add(1).ok_or(Error::<T>::TooManyKitties)?;

/* TODO: Update `append` to `try_append` and `map_err` to `Error::<T>::TooManyOwned`. */
/* 🚧 TODO 🚧: Update `append` to `try_append` and `map_err` to `Error::<T>::TooManyOwned`. */
KittiesOwned::<T>::append(&owner, dna);
Kitties::<T>::insert(dna, kitty);
CountForKitties::<T>::set(new_count);
Expand Down
4 changes: 2 additions & 2 deletions steps/30/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub mod pallet {
#[pallet::storage]
pub(super) type KittiesOwned<T: Config> = StorageMap<
Key = T::AccountId,
/* TODO: Turn this into a `BoundedVec` with a limit of `ConstU32<100>`. */
/* 🚧 TODO 🚧: Turn this into a `BoundedVec` with a limit of `ConstU32<100>`. */
Value = Vec<[u8; 16]>,
QueryKind = ValueQuery,
>;
Expand All @@ -51,7 +51,7 @@ pub mod pallet {
pub enum Error<T> {
TooManyKitties,
DuplicateKitty,
/* TODO: Add a new `Error` named `TooManyOwned` */
/* 🚧 TODO 🚧: Add a new `Error` named `TooManyOwned` */
}

#[pallet::call]
Expand Down
2 changes: 1 addition & 1 deletion steps/33/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl<T: Config> Pallet<T> {
Ok(())
}

/* TODO: Create an internal function called `do_transfer`:
/* 🚧 TODO 🚧: Create an internal function called `do_transfer`:
- It has inputs:
- `from` which is `T::AccountId`.
- `to` which is `T::AccountId`.
Expand Down
4 changes: 2 additions & 2 deletions steps/33/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub mod pallet {
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
Created { owner: T::AccountId },
/* TODO: Create a new event called `Transferred`:
/* 🚧 TODO 🚧: Create a new event called `Transferred`:
- Parameters are:
- `from` which is `T::AccountId`.
- `to` which is `T::AccountId`.
Expand All @@ -68,7 +68,7 @@ pub mod pallet {
Ok(())
}

/* TODO: Make a new extrinsic called `transfer`.
/* 🚧 TODO 🚧: Make a new extrinsic called `transfer`.
- Input parameters are:
- `origin` which is `OriginFor<T>`.
- `to` which is `T::AccountId`.
Expand Down
6 changes: 3 additions & 3 deletions steps/35/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ impl<T: Config> Pallet<T> {
}

pub fn do_transfer(from: T::AccountId, to: T::AccountId, kitty_id: [u8; 16]) -> DispatchResult {
/* TODO: Sanity check the transfer is allowed:
/* 🚧 TODO 🚧: Sanity check the transfer is allowed:
- First `ensure!` that `from` and `to` are not equal, else return `Error::<T>::TransferToSelf`.
- Get the `kitty` from `Kitties` using `kitty_id`, else return `Error::<T>::NoKitty`.
- Check the `kitty.owner` is equal to `from`, else return `NotOwner`.
*/

/* TODO: Update the owner of the kitty:
/* 🚧 TODO 🚧: Update the owner of the kitty:
- Update `kitty.owner` to `to`.
- Update the `KittiesOwned` of `from` and `to:
- Create a mutable `to_owned` by querying `KittiesOwned` for `to`.
Expand All @@ -52,7 +52,7 @@ impl<T: Config> Pallet<T> {
- If you cannot find the kitty in the vector, return `Error::<T>::NoKitty`.
*/

/* TODO: Update the final storage.
/* 🚧 TODO 🚧: Update the final storage.
- Insert into `Kitties` under `kitty_id` the modified `kitty` struct.
- Insert into `KittiesOwned` under `to` the modified `to_owned` vector.
- Insert into `KittiesOwned` under `from` the modified `from_owned` vector.
Expand Down
2 changes: 1 addition & 1 deletion steps/35/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub mod pallet {
TooManyKitties,
DuplicateKitty,
TooManyOwned,
/* TODO: Add new `Error` variants needed for `do_transfer`:
/* 🚧 TODO 🚧: Add new `Error` variants needed for `do_transfer`:
- `TransferToSelf`: for when the `from` and `to` of the transfer is the same.
- `NoKitty`: for when a transfer involves a kitty that does not exist.
- `NotOwner`: for when a transfer is initiated by someone who is not the current owner.
Expand Down
2 changes: 1 addition & 1 deletion steps/39/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl<T: Config> Pallet<T> {
Ok(())
}

/* TODO: Make an internal function called `do_set_price`:
/* 🚧 TODO 🚧: Make an internal function called `do_set_price`:
- Inputs to the function are:
- `caller` which is `T::AccountId`.
- `kitty_id` which is `[u8; 16]`.
Expand Down
4 changes: 2 additions & 2 deletions steps/39/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub mod pallet {
pub enum Event<T: Config> {
Created { owner: T::AccountId },
Transferred { from: T::AccountId, to: T::AccountId, kitty_id: [u8; 16] },
/* TODO: Create a new `Event` called `PriceSet` with fields:
/* 🚧 TODO 🚧: Create a new `Event` called `PriceSet` with fields:
- `owner` which is `T::AccountId`.
- `kitty_id` which is `[u8; 16]`.
- `new_price` which is `Option<BalanceOf<T>>`.
Expand Down Expand Up @@ -92,7 +92,7 @@ pub mod pallet {
Ok(())
}

/* TODO: Make an callable function called `set_price`:
/* 🚧 TODO 🚧: Make an callable function called `set_price`:
- Inputs to the function are:
- `origin` which is `OriginFor<T>`.
- `kitty_id` which is `[u8; 16]`.
Expand Down
2 changes: 1 addition & 1 deletion steps/4/src/impls.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::*;
use frame_support::pallet_prelude::*;

/* TODO: Learn about internal functions. */
/* 🚧 TODO 🚧: Learn about internal functions. */
impl<T: Config> Pallet<T> {
pub fn mint(owner: T::AccountId) -> DispatchResult {
Self::deposit_event(Event::<T>::Created { owner });
Expand Down
2 changes: 1 addition & 1 deletion steps/4/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub mod pallet {
#[pallet::error]
pub enum Error<T> {}

/* TODO: Learn about callable functions and dispatch. */
/* 🚧 TODO 🚧: Learn about callable functions and dispatch. */
#[pallet::call]
impl<T: Config> Pallet<T> {
pub fn create_kitty(origin: OriginFor<T>) -> DispatchResult {
Expand Down
2 changes: 1 addition & 1 deletion steps/41/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl<T: Config> Pallet<T> {
kitty_id: [u8; 16],
new_price: Option<BalanceOf<T>>,
) -> DispatchResult {
/* TODO: Create the logic for setting the Kitty price:
/* 🚧 TODO 🚧: Create the logic for setting the Kitty price:
- Create a mutable `kitty` by calling `get` on `Kitties` with `kitty_id`.
- Return an error if the kitty doesn't exist by returning `Error::<T>::NoKitty`.
- `ensure!` that the `kitty.owner` is equal to the `caller` else return `Error::<T>::NotOwner`.
Expand Down
2 changes: 1 addition & 1 deletion steps/43/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl<T: Config> Pallet<T> {
Ok(())
}

/* TODO: Create a new internal function `do_buy_kitty`:
/* 🚧 TODO 🚧: Create a new internal function `do_buy_kitty`:
- Inputs to the function are:
- `buyer` which is `T::AccountId`.
- `kitty_id` which is `[u8; 16]`.
Expand Down
4 changes: 2 additions & 2 deletions steps/43/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub mod pallet {
Created { owner: T::AccountId },
Transferred { from: T::AccountId, to: T::AccountId, kitty_id: [u8; 16] },
PriceSet { owner: T::AccountId, kitty_id: [u8; 16], new_price: Option<BalanceOf<T>> },
/* TODO: Create a new `Event` called `Sold` with the following parameters:
/* 🚧 TODO 🚧: Create a new `Event` called `Sold` with the following parameters:
- `buyer` which is `T::AccountId`.
- `kitty_id` which is `[u8; 16]`.
- `price` which is `BalanceOf<T>`.
Expand Down Expand Up @@ -103,7 +103,7 @@ pub mod pallet {
Ok(())
}

/* TODO: Create a new callable function `buy_kitty`:
/* 🚧 TODO 🚧: Create a new callable function `buy_kitty`:
- Inputs to the function are:
- `origin` which is `OriginFor<T>`.
- `kitty_id` which is `[u8; 16]`.
Expand Down
6 changes: 3 additions & 3 deletions steps/45/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ impl<T: Config> Pallet<T> {
kitty_id: [u8; 16],
price: BalanceOf<T>,
) -> DispatchResult {
/* TODO: Sanity check that the purchase is allowed:
/* 🚧 TODO 🚧: Sanity check that the purchase is allowed:
- Get `kitty` from `Kitties` using `kitty_id`, `ok_or` return `Error::<T>::NoKitty`.
- Get the `real_price` from `kitty.price`, `ok_or` return `Error::<T>::NotForSale`.
- `ensure!` that `price` is greater or equal to `real_price`, else `Error::<T>::MaxPriceTooLow`.
*/

/* TODO: Execute the transfers:
/* 🚧 TODO 🚧: Execute the transfers:
- Import `use frame_support::traits::tokens::Preservation;`, which is used for balance transfer.
- Use `T::NativeBalance` to `transfer` from the `buyer` to the `kitty.owner`.
- The amount transferred should be the `real_price`.
Expand All @@ -91,7 +91,7 @@ impl<T: Config> Pallet<T> {
- Remember to propagate up all results from these functions with `?`.
*/

/* TODO: Update the event to use the `real_price` in the `Event`. */
/* 🚧 TODO 🚧: Update the event to use the `real_price` in the `Event`. */
Self::deposit_event(Event::<T>::Sold { buyer, kitty_id, price });
Ok(())
}
Expand Down
Loading

0 comments on commit 6fcb5c9

Please sign in to comment.