@@ -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
0 commit comments