@@ -219,6 +219,9 @@ impl<T: Config> Pallet<T> {
219219 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 {
220220 //TODO: ensure the user is a Marketparticipant
221221
222+ //ensure the item is for sale, if not, return error
223+ ensure ! ( <OffersByItem <T >>:: contains_key( collection_id, item_id) , Error :: <T >:: ItemNotForSale ) ;
224+
222225 //ensure the marketplace exists
223226 ensure ! ( <Marketplaces <T >>:: contains_key( marketplace_id) , Error :: <T >:: MarketplaceNotFound ) ;
224227
@@ -284,6 +287,7 @@ impl<T: Config> Pallet<T> {
284287 }
285288
286289 pub fn do_take_sell_offer ( buyer : T :: AccountId , offer_id : [ u8 ; 32 ] , marketplace_id : [ u8 ; 32 ] , collection_id : T :: CollectionId , item_id : T :: ItemId , ) -> DispatchResult {
290+ //This extrisicn is called by the user who wants to buy the item
287291 //ensure the collection & owner exists
288292 let owner_item = pallet_uniques:: Pallet :: < T > :: owner ( collection_id, item_id) . ok_or ( Error :: < T > :: OwnerNotFound ) ?;
289293
@@ -325,10 +329,14 @@ impl<T: Config> Pallet<T> {
325329 Ok ( ( ) )
326330 }
327331
328- pub fn do_take_buy_offer ( offer_id : [ u8 ; 32 ] , marketplace_id : [ u8 ; 32 ] , collection_id : T :: CollectionId , item_id : T :: ItemId , ) -> DispatchResult {
332+ pub fn do_take_buy_offer ( authority : T :: AccountId , offer_id : [ u8 ; 32 ] , marketplace_id : [ u8 ; 32 ] , collection_id : T :: CollectionId , item_id : T :: ItemId , ) -> DispatchResult {
333+ //This extrinsic is called by the owner of the item who accepts the buy offer from the interested user.
329334 //ensure the collection & owner exists
330335 let owner_item = pallet_uniques:: Pallet :: < T > :: owner ( collection_id, item_id) . ok_or ( Error :: < T > :: OwnerNotFound ) ?;
331336
337+ //ensure only owner of the item can call the extrinic
338+ ensure ! ( owner_item == authority. clone( ) , Error :: <T >:: NotOwner ) ;
339+
332340 // Get the account_id of the offer creator (the buyer)
333341 let buy_offer_creator = Self :: get_offer_creator ( offer_id) . map_err ( |_| Error :: < T > :: OfferNotFound ) ?;
334342
@@ -697,7 +705,8 @@ impl<T: Config> Pallet<T> {
697705 }
698706 Ok ( ( ) )
699707 }
700-
708+
709+ //TODO: merge the timestamp function to convert from moment to milliseconds.
701710 fn convert_moment_to_u64_in_milliseconds ( date : T :: Moment ) -> Result < u64 , DispatchError > {
702711 let date_as_u64_millis;
703712 if let Some ( _date_as_u64) = TryInto :: < u64 > :: try_into ( date) . ok ( ) {
@@ -811,12 +820,11 @@ impl<T: Config> Pallet<T> {
811820 }
812821 }
813822 }
814-
815823 Ok ( ( ) )
816824 }
817825
818826
819- fn delete_all_sell_orders_for_this_item ( collection_id : T :: CollectionId , item_id : T :: ItemId ) -> DispatchResult {
827+ fn _delete_all_sell_orders_for_this_item ( collection_id : T :: CollectionId , item_id : T :: ItemId ) -> DispatchResult {
820828 //ensure the item has offers associated with it.
821829 ensure ! ( <OffersByItem <T >>:: contains_key( collection_id, item_id) , Error :: <T >:: OfferNotFound ) ;
822830
0 commit comments