@@ -15,19 +15,31 @@ mod types;
1515
1616#[ frame_support:: pallet]
1717pub mod pallet {
18- use frame_support:: { pallet_prelude:: { * , OptionQuery } , transactional} ;
18+ use frame_support:: pallet_prelude:: * ;
19+ use frame_support:: transactional;
1920 use frame_system:: pallet_prelude:: * ;
20- use frame_support:: traits:: Currency ;
21- //use sp_runtime::sp_std::vec::Vec;
21+ use sp_runtime:: traits:: Scale ;
22+ use frame_support:: traits:: { Currency , Time } ;
23+
2224 use crate :: types:: * ;
23- //use frame_support::traits::tokens::Balance;
2425 use pallet_rbac:: types:: RoleBasedAccessControl ;
2526
27+ pub type BalanceOf < T > = <<T as pallet_uniques:: Config >:: Currency as Currency < <T as frame_system:: Config >:: AccountId > >:: Balance ;
28+
2629 #[ pallet:: config]
27- pub trait Config : frame_system:: Config + pallet_fruniques:: Config + pallet_uniques:: Config + pallet_timestamp:: Config {
30+ pub trait Config : frame_system:: Config + pallet_fruniques:: Config {
31+
2832 type Event : From < Event < Self > > + IsType < <Self as frame_system:: Config >:: Event > ;
29- type LocalCurrency : Currency < Self :: AccountId > ;
30- //type Balance: Balance + MaybeSerializeDeserialize + Debug + MaxEncodedLen;
33+
34+ type Moment : Parameter
35+ + Default
36+ + Scale < Self :: BlockNumber , Output = Self :: Moment >
37+ + Copy
38+ + MaxEncodedLen
39+ + scale_info:: StaticTypeInfo
40+ + Into < u64 > ;
41+
42+ type Timestamp : Time < Moment = Self :: Moment > ;
3143
3244 type RemoveOrigin : EnsureOrigin < Self :: Origin > ;
3345 #[ pallet:: constant]
@@ -88,7 +100,7 @@ pub mod pallet {
88100 _ ,
89101 Blake2_128Concat ,
90102 T :: AccountId , // K1: account_id
91- Blake2_128Concat ,
103+ Identity ,
92104 [ u8 ; 32 ] , // k2: marketplace_id
93105 [ u8 ; 32 ] , //application_id
94106 OptionQuery
@@ -113,7 +125,7 @@ pub mod pallet {
113125 _ ,
114126 Blake2_128Concat ,
115127 T :: AccountId , //custodians
116- Blake2_128Concat ,
128+ Identity ,
117129 [ u8 ; 32 ] , //marketplace_id
118130 BoundedVec < T :: AccountId , T :: MaxApplicationsPerCustodian > , //applicants
119131 ValueQuery
@@ -135,7 +147,7 @@ pub mod pallet {
135147 #[ pallet:: getter( fn offers_by_account) ]
136148 pub ( super ) type OffersByAccount < T : Config > = StorageMap <
137149 _ ,
138- Identity ,
150+ Blake2_128Concat ,
139151 T :: AccountId , // account_id
140152 BoundedVec < [ u8 ; 32 ] , T :: MaxOffersPerMarket > , // offer_id's
141153 ValueQuery ,
@@ -187,6 +199,8 @@ pub mod pallet {
187199 OfferWasAccepted ( [ u8 ; 32 ] , T :: AccountId ) ,
188200 /// Offer was duplicated. [new_offer_id, new_marketplace_id]
189201 OfferDuplicated ( [ u8 ; 32 ] , [ u8 ; 32 ] ) ,
202+ /// Offer was removed. [offer_id], [marketplace_id]
203+ OfferRemoved ( [ u8 ; 32 ] , [ u8 ; 32 ] ) ,
190204 }
191205
192206 // Errors inform users that something went wrong.
@@ -321,7 +335,7 @@ pub mod pallet {
321335 origin : OriginFor < T > ,
322336 marketplace_id : [ u8 ; 32 ] ,
323337 // Getting encoding errors from polkadotjs if an object vector have optional fields
324- fields : BoundedVec < ( BoundedVec < u8 , ConstU32 < 100 > > , BoundedVec < u8 , ConstU32 < 100 > > ) , T :: MaxFiles > ,
338+ fields : Fields < T > ,
325339 custodian_fields : Option < ( T :: AccountId , BoundedVec < BoundedVec < u8 , ConstU32 < 100 > > , T :: MaxFiles > ) >
326340 ) -> DispatchResult {
327341 let who = ensure_signed ( origin) ?;
@@ -359,7 +373,7 @@ pub mod pallet {
359373 origin : OriginFor < T > ,
360374 marketplace_id : [ u8 ; 32 ] ,
361375 // Getting encoding errors from polkadotjs if an object vector have optional fields
362- fields : BoundedVec < ( BoundedVec < u8 , ConstU32 < 100 > > , BoundedVec < u8 , ConstU32 < 100 > > ) , T :: MaxFiles > ,
376+ fields : Fields < T > ,
363377 custodian_fields : Option < ( T :: AccountId , BoundedVec < BoundedVec < u8 , ConstU32 < 100 > > , T :: MaxFiles > ) >
364378 ) -> DispatchResult {
365379 let who = ensure_signed ( origin) ?;
@@ -520,58 +534,33 @@ pub mod pallet {
520534
521535 /// Accepts a sell order.
522536 ///
523- /// This extrinsic accepts a sell order in the selected marketplace.
537+ /// This extrisicn is called by the user who wants to buy the item.
538+ /// Aaccepts a sell order in the selected marketplace.
524539 ///
525540 /// ### Parameters:
526541 /// - `origin`: The user who performs the action.
542+ /// - 'offer_id`: The id of the sell order to be accepted.
527543 /// - `marketplace_id`: The id of the marketplace where we want to accept the sell order.
528- /// - `collection_id`: The id of the collection.
529- /// - `item_id`: The id of the item inside the collection.
530544 ///
531545 /// ### Considerations:
532546 /// - You don't need to be the owner of the item to accept the sell order.
533547 /// - Once the sell order is accepted, the ownership of the item is transferred to the buyer.
534548 /// - If you don't have the enough balance to accept the sell order, it will throw an error.
535549 #[ transactional]
536550 #[ pallet:: weight( 10_000 + T :: DbWeight :: get( ) . writes( 1 ) ) ]
537- pub fn take_sell_offer ( origin : OriginFor < T > , offer_id : [ u8 ; 32 ] , marketplace_id : [ u8 ; 32 ] , collection_id : T :: CollectionId , item_id : T :: ItemId , ) -> DispatchResult {
551+ pub fn take_sell_offer ( origin : OriginFor < T > , offer_id : [ u8 ; 32 ] ) -> DispatchResult {
538552 let who = ensure_signed ( origin. clone ( ) ) ?;
539553
540- Self :: do_take_sell_offer ( who, offer_id, marketplace_id , collection_id , item_id )
554+ Self :: do_take_sell_offer ( who, offer_id)
541555 }
542-
543- /// Allows a user to duplicate a sell order.
544- ///
545- /// This extrinsic allows a user to duplicate a sell order in any marketplace.
546- ///
547- /// ### Parameters:
548- /// - `origin`: The user who performs the action.
549- /// - `marketplace_id`: The id of the marketplace where we want to duplicate the sell order.
550- /// - `collection_id`: The id of the collection.
551- /// - `item_id`: The id of the item inside the collection.
552- ///
553- /// ### Considerations:
554- /// - You can only duplicate a sell order if you are the owner of the item.
555- /// - The expiration date of the sell order is the same as the original sell order.
556- /// - You can update the price of the sell order.
557- #[ transactional]
558- #[ pallet:: weight( 10_000 + T :: DbWeight :: get( ) . writes( 1 ) ) ]
559- pub fn duplicate_offer ( origin : OriginFor < T > , offer_id : [ u8 ; 32 ] , marketplace_id : [ u8 ; 32 ] , collection_id : T :: CollectionId , item_id : T :: ItemId , modified_price : BalanceOf < T > ) -> DispatchResult {
560- let who = ensure_signed ( origin. clone ( ) ) ?;
561-
562- Self :: do_duplicate_offer ( who, offer_id, marketplace_id, collection_id, item_id, modified_price)
563- }
564-
565-
556+
566557 /// Delete an offer.
567558 ///
568559 /// This extrinsic deletes an offer in the selected marketplace.
569560 ///
570561 /// ### Parameters:
571562 /// - `origin`: The user who performs the action.
572- /// - `marketplace_id`: The id of the marketplace where we want to delete the offer.
573- /// - `collection_id`: The id of the collection.
574- /// - `item_id`: The id of the item inside the collection.
563+ /// - `offer_id`: The id of the offer to be deleted.
575564 ///
576565 /// ### Considerations:
577566 /// - You can delete sell orders or buy orders.
@@ -581,12 +570,12 @@ pub mod pallet {
581570 /// delete them one by one.
582571 #[ transactional]
583572 #[ pallet:: weight( 10_000 + T :: DbWeight :: get( ) . writes( 1 ) ) ]
584- pub fn remove_offer ( origin : OriginFor < T > , offer_id : [ u8 ; 32 ] , marketplace_id : [ u8 ; 32 ] , collection_id : T :: CollectionId , item_id : T :: ItemId , ) -> DispatchResult {
573+ pub fn remove_offer ( origin : OriginFor < T > , offer_id : [ u8 ; 32 ] ) -> DispatchResult {
585574 //Currently, we can only remove one offer at a time.
586575 //TODO: Add support for removing multiple offers at a time.
587576 let who = ensure_signed ( origin. clone ( ) ) ?;
588577
589- Self :: do_remove_offer ( who, offer_id, marketplace_id , collection_id , item_id )
578+ Self :: do_remove_offer ( who, offer_id)
590579 }
591580
592581 /// Enlist a buy order.
@@ -615,13 +604,13 @@ pub mod pallet {
615604
616605 /// Accepts a buy order.
617606 ///
618- /// This extrinsic accepts a buy order in the selected marketplace.
607+ /// This extrinsic is called by the owner of the item who accepts the buy offer created by a marketparticipant.
608+ /// Accepts a buy order in the selected marketplace.
619609 ///
620610 /// ### Parameters:
621611 /// - `origin`: The user who performs the action.
612+ /// - `offer_id`: The id of the buy order to be accepted.
622613 /// - `marketplace_id`: The id of the marketplace where we accept the buy order.
623- /// - `collection_id`: The id of the collection.
624- /// - `item_id`: The id of the item inside the collection.
625614 ///
626615 /// ### Considerations:
627616 /// - You need to be the owner of the item to accept a buy order.
@@ -631,10 +620,10 @@ pub mod pallet {
631620 /// - Once the buy order is accepted, the ownership of the item is transferred to the buyer.
632621 #[ transactional]
633622 #[ pallet:: weight( 10_000 + T :: DbWeight :: get( ) . writes( 1 ) ) ]
634- pub fn take_buy_offer ( origin : OriginFor < T > , offer_id : [ u8 ; 32 ] , marketplace_id : [ u8 ; 32 ] , collection_id : T :: CollectionId , item_id : T :: ItemId , ) -> DispatchResult {
623+ pub fn take_buy_offer ( origin : OriginFor < T > , offer_id : [ u8 ; 32 ] ) -> DispatchResult {
635624 let who = ensure_signed ( origin. clone ( ) ) ?;
636625
637- Self :: do_take_buy_offer ( who, offer_id, marketplace_id , collection_id , item_id )
626+ Self :: do_take_buy_offer ( who, offer_id)
638627 }
639628
640629
0 commit comments