diff --git a/exercises/ex04-marketplace/loosely-coupled-marketplace/src/lib.rs b/exercises/ex04-marketplace/loosely-coupled-marketplace/src/lib.rs index 29fde5a..09aa3cb 100644 --- a/exercises/ex04-marketplace/loosely-coupled-marketplace/src/lib.rs +++ b/exercises/ex04-marketplace/loosely-coupled-marketplace/src/lib.rs @@ -85,9 +85,7 @@ pub mod pallet { let origin = ensure_signed(origin)?; ensure!(amount > 0, Error::::ZeroAmount); - let owned: u128 = todo!( - "get the amount of this specific NFT owned by the seller, through the Resource type and its Sellable trait" - ); + let owned = T::Resource::amount_owned(nft_id, origin.clone()); ensure!(owned >= amount, Error::::NotEnoughOwned); ResourcesForSale::::insert(nft_id, origin.clone(), SaleData { price, amount }); @@ -107,9 +105,7 @@ pub mod pallet { let buyer = ensure_signed(origin)?; let sale_data = ResourcesForSale::::get(nft_id, seller.clone()); - let owned = todo!( - "get the amount of this specific NFT owned by the seller, through the Resource type and its Sellable trait" - ); + let owned = T::Resource::amount_owned(nft_id, seller.clone()); ensure!(amount <= sale_data.amount, Error::::NotEnoughInSale); ensure!(sale_data.amount <= owned, Error::::NotEnoughOwned); @@ -119,9 +115,9 @@ pub mod pallet { .checked_mul(&amount.checked_into().ok_or(Error::::Overflow)?) .ok_or(Error::::Overflow)?; - todo!("transfer the amount of currency owed from the buyer to the seller"); + T::Currency::transfer(&buyer, &seller, total_to_pay, KeepAlive)?; - todo!("transfer amount of nft_id from the seller to the buyer"); + T::Resource::transfer(nft_id, seller.clone(), buyer.clone(), amount); if amount == sale_data.amount { ResourcesForSale::::remove(nft_id, seller.clone()); diff --git a/exercises/ex04-marketplace/marketplace-nfts/src/lib.rs b/exercises/ex04-marketplace/marketplace-nfts/src/lib.rs index a8d9e78..0e843ea 100644 --- a/exercises/ex04-marketplace/marketplace-nfts/src/lib.rs +++ b/exercises/ex04-marketplace/marketplace-nfts/src/lib.rs @@ -208,10 +208,10 @@ impl Pallet { impl Sellable for Pallet { fn amount_owned(nft_id: T::NFTId, account: T::AccountId) -> u128 { - todo!("return the amount of nft_id owned by account") + Self::account(nft_id, account) } fn transfer(nft_id: T::NFTId, from: T::AccountId, to: T::AccountId, amount: u128) -> u128 { - todo!("do the transfer") + Self::unchecked_transfer(nft_id, from, to, amount) } } diff --git a/exercises/ex04-marketplace/tightly-coupled-marketplace/src/lib.rs b/exercises/ex04-marketplace/tightly-coupled-marketplace/src/lib.rs index e9766d5..74b913f 100644 --- a/exercises/ex04-marketplace/tightly-coupled-marketplace/src/lib.rs +++ b/exercises/ex04-marketplace/tightly-coupled-marketplace/src/lib.rs @@ -23,8 +23,9 @@ pub mod pallet { use frame_system::{ensure_signed, pallet_prelude::*}; #[pallet::config] - pub trait Config: frame_system::Config + scale_info::TypeInfo { - todo!("add a dependency on pallet_marketplace_nft on the previous line"); + pub trait Config: + frame_system::Config + scale_info::TypeInfo + pallet_marketplace_nfts::Config + { type Event: From> + IsType<::Event>; type Currency: Currency; } @@ -75,7 +76,7 @@ pub mod pallet { let origin = ensure_signed(origin)?; ensure!(amount > 0, Error::::ZeroAmount); - let owned = todo!("get the amount owned from the pallet_nft account storage"); + let owned = pallet_marketplace_nfts::Pallet::::account(nft_id, origin.clone()); ensure!(owned >= amount, Error::::NotEnoughOwned); NFTsForSale::::insert(nft_id, origin.clone(), SaleData { price, amount }); @@ -95,7 +96,7 @@ pub mod pallet { let buyer = ensure_signed(origin)?; let sale_data = NFTsForSale::::get(nft_id, seller.clone()); - let owned = todo!("get the amount owned from the pallet_nft account storage"); + let owned = pallet_marketplace_nfts::Pallet::::account(nft_id, seller.clone()); ensure!(amount <= sale_data.amount, Error::::NotEnoughInSale); ensure!(sale_data.amount <= owned, Error::::NotEnoughOwned); @@ -107,7 +108,12 @@ pub mod pallet { ::Currency::transfer(&buyer, &seller, total_to_pay, KeepAlive)?; - todo!("call the pallet_marketplace_nft transfer function"); + pallet_marketplace_nfts::Pallet::::unchecked_transfer( + nft_id, + seller.clone(), + buyer.clone(), + amount, + ); if amount == sale_data.amount { NFTsForSale::::remove(nft_id, seller.clone());