Skip to content

Commit 8961c64

Browse files
committed
backup
1 parent 2291d78 commit 8961c64

File tree

6 files changed

+41
-23
lines changed

6 files changed

+41
-23
lines changed

.devcontainer/devcontainer.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
"lldb.executable": "/usr/bin/lldb"
77
},
88
"extensions": [
9-
"rust-lang.rust",
10-
"bungcip.better-toml",
11-
"vadimcn.vscode-lldb"
12-
],
9+
"rust-lang.rust",
10+
"bungcip.better-toml",
11+
"vadimcn.vscode-lldb",
12+
"rust-lang.rust-analyzer"
13+
],
1314
"forwardPorts": [
1415
3000,
1516
9944

pallets/fruniques/src/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{mock::*, Error};
22

3-
use frame_support::{assert_err, assert_noop, assert_ok};
3+
use frame_support::{assert_noop, assert_ok};
44
use sp_runtime::Permill;
55

66
pub struct ExtBuilder;

pallets/gated-marketplace/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ std = [
4545
"frame-benchmarking/std",
4646
"pallet-balances/std",
4747
"pallet-timestamp/std",
48+
"pallet-uniques/std",
49+
"pallet-fruniques/std"
4850
]
4951

5052
runtime-benchmarks = ["frame-benchmarking/runtime-benchmarks"]

pallets/gated-marketplace/src/functions.rs

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,9 @@ impl<T: Config> Pallet<T> {
187187
buyer: None,
188188
};
189189

190-
190+
//TODO: FIX THIS HELPER FUCNTION
191191
//ensure there is no a previous sell offer for this item
192-
Self::is_item_already_for_sale(collection_id, item_id, marketplace_id)?;
192+
//Self::is_item_already_for_sale(collection_id, item_id, marketplace_id)?;
193193

194194
//insert in OffersByItem
195195
<OffersByItem<T>>::try_mutate(collection_id, item_id, |offers| {
@@ -216,8 +216,6 @@ impl<T: Config> Pallet<T> {
216216
}
217217

218218
pub fn do_enlist_buy_offer(authority: T::AccountId, marketplace_id: [u8;32], collection_id: T::CollectionId, item_id: T::ItemId, price: BalanceOf<T>,) -> DispatchResult {
219-
//TODO: ensure the user is a Marketparticipant
220-
221219
//ensure the item is for sale, if not, return error
222220
ensure!(<OffersByItem<T>>::contains_key(collection_id, item_id), Error::<T>::ItemNotForSale);
223221

@@ -299,8 +297,6 @@ impl<T: Config> Pallet<T> {
299297
//ensure the offer_id exists in OffersByItem
300298
Self::does_exist_offer_id_for_this_item(collection_id, item_id, offer_id)?;
301299

302-
//TODO: ensure the offer is not expired
303-
304300
//ensure the offer is open and available
305301
ensure!(Self::is_offer_status(offer_id, OfferStatus::Open), Error::<T>::OfferIsNotAvailable);
306302

@@ -322,8 +318,6 @@ impl<T: Config> Pallet<T> {
322318
//remove all the offers associated with the item
323319
Self::delete_all_offers_for_this_item(collection_id, item_id )?;
324320

325-
//TODO: add the offer_id from this offer to the buyer's history
326-
327321
Self::deposit_event(Event::OfferWasAccepted(offer_id, buyer));
328322
Ok(())
329323
}
@@ -467,6 +461,7 @@ impl<T: Config> Pallet<T> {
467461
Ok(())
468462
}).map_err(|_:Error::<T>| Error::<T>::OfferNotFound)?;
469463

464+
Self::deposit_event(Event::OfferRemoved(offer_id, marketplace_id));
470465

471466
Ok(())
472467
}
@@ -787,22 +782,39 @@ impl<T: Config> Pallet<T> {
787782
Ok(())
788783
}
789784

790-
fn is_item_already_for_sale(collection_id: T::CollectionId, item_id: T::ItemId, marketplace_id: [u8;32]) -> DispatchResult {
791-
let offers = <OffersByItem<T>>::get(collection_id, item_id);
785+
// fn is_item_already_for_sale(collection_id: T::CollectionId, item_id: T::ItemId, marketplace_id: [u8;32]) -> DispatchResult {
786+
// let offers = <OffersByItem<T>>::get(collection_id, item_id);
787+
788+
// //if len is == 0, it means that there is no offers for this item, maybe it's the first entry
789+
// if offers.len() == 0 {
790+
// return Ok(());
791+
// } else if offers.len() > 0 {
792+
// for offer in offers {
793+
// let offer_info = <OffersInfo<T>>::get(offer).ok_or(Error::<T>::OfferNotFound)?;
794+
// //ensure the offer_type is SellOrder, because this vector also contains buy offers.
795+
// if offer_info.marketplace_id == marketplace_id && offer_info.offer_type == OfferType::SellOrder {
796+
// return Err(Error::<T>::OfferAlreadyExists)?;
797+
// }
798+
// }
799+
// }
800+
// Ok(())
801+
// }
802+
803+
fn _is_item_already_for_sale(collection_id: T::CollectionId, item_id: T::ItemId, marketplace_id: [u8;32]) -> bool {
804+
805+
let offers = match <OffersByItem<T>>::try_get(collection_id, item_id){
806+
Ok(offers) => offers,
807+
Err(_) => return false};
792808

793-
//if len is == 0, it means that there is no offers for this item, maybe it's the first entry
794-
if offers.len() == 0 {
795-
return Ok(())
796-
} else if offers.len() > 0 {
797809
for offer in offers {
798-
let offer_info = <OffersInfo<T>>::get(offer).ok_or(Error::<T>::OfferNotFound)?;
810+
let offer_info = <OffersInfo<T>>::get(offer);
799811
//ensure the offer_type is SellOrder, because this vector also contains buy offers.
800812
if offer_info.marketplace_id == marketplace_id && offer_info.offer_type == OfferType::SellOrder {
801-
return Err(Error::<T>::OfferAlreadyExists)?;
813+
return true;
802814
}
803815
}
804-
}
805-
Ok(())
816+
817+
true
806818
}
807819

808820

pallets/gated-marketplace/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,8 @@ pub mod pallet {
212212
OfferWasAccepted([u8;32], T::AccountId),
213213
/// Offer was duplicated. [new_offer_id, new_marketplace_id]
214214
OfferDuplicated([u8;32], [u8;32]),
215+
/// Offer was removed. [offer_id], [marketplace_id]
216+
OfferRemoved([u8;32], [u8;32]),
215217
}
216218

217219
// Errors inform users that something went wrong.

runtime/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ std = [
113113
"sp-transaction-pool/std",
114114
"sp-version/std",
115115
]
116+
116117
runtime-benchmarks = [
117118
"frame-benchmarking/runtime-benchmarks",
118119
"frame-support/runtime-benchmarks",

0 commit comments

Comments
 (0)