@@ -16,18 +16,16 @@ use types::*;
16
16
pub type BalanceOf < T > =
17
17
<<T as Config >:: Currency as Currency < <T as frame_system:: Config >:: AccountId > >:: Balance ;
18
18
19
- // TODO: Once you added the dependecy to pallet_marketplace_nft use T::NFTId instead
20
- pub type NFTId = u32 ;
21
-
22
19
#[ frame_support:: pallet]
23
20
pub mod pallet {
24
21
use super :: * ;
25
22
use frame_support:: pallet_prelude:: * ;
26
23
use frame_system:: { ensure_signed, pallet_prelude:: * } ;
27
24
28
25
#[ pallet:: config]
29
- // TODO: add a dependency on pallet_marketplace_nft on the previous line
30
- pub trait Config : frame_system:: Config + scale_info:: TypeInfo {
26
+ pub trait Config :
27
+ frame_system:: Config + scale_info:: TypeInfo + pallet_marketplace_nfts:: Config
28
+ {
31
29
type Event : From < Event < Self > > + IsType < <Self as frame_system:: Config >:: Event > ;
32
30
type Currency : Currency < Self :: AccountId > ;
33
31
}
@@ -40,9 +38,9 @@ pub mod pallet {
40
38
#[ pallet:: generate_deposit( pub ( super ) fn deposit_event) ]
41
39
pub enum Event < T : Config > {
42
40
/// NFT has been listed for sale (nft_id, seller, price, amount)
43
- ListedForSale ( NFTId , T :: AccountId , BalanceOf < T > , u128 ) ,
41
+ ListedForSale ( T :: NFTId , T :: AccountId , BalanceOf < T > , u128 ) ,
44
42
// NFT has been sold (nft_id, seller, buyer, amount)
45
- Sold ( NFTId , T :: AccountId , T :: AccountId , u128 ) ,
43
+ Sold ( T :: NFTId , T :: AccountId , T :: AccountId , u128 ) ,
46
44
}
47
45
48
46
#[ pallet:: error]
@@ -59,7 +57,7 @@ pub mod pallet {
59
57
pub type NFTsForSale < T : Config > = StorageDoubleMap <
60
58
_ ,
61
59
Blake2_128Concat ,
62
- NFTId ,
60
+ T :: NFTId ,
63
61
Blake2_128Concat ,
64
62
T :: AccountId ,
65
63
SaleData < T > ,
@@ -71,15 +69,14 @@ pub mod pallet {
71
69
#[ pallet:: weight( 0 ) ]
72
70
pub fn set_sale (
73
71
origin : OriginFor < T > ,
74
- nft_id : NFTId ,
72
+ nft_id : T :: NFTId ,
75
73
price : BalanceOf < T > ,
76
74
amount : u128 ,
77
75
) -> DispatchResult {
78
76
let origin = ensure_signed ( origin) ?;
79
77
80
78
ensure ! ( amount > 0 , Error :: <T >:: ZeroAmount ) ;
81
- // TODO: get the amount owned from the pallet_nft account storage, instead of 0
82
- let owned = 0 ;
79
+ let owned = pallet_marketplace_nfts:: Pallet :: < T > :: account ( nft_id, origin. clone ( ) ) ;
83
80
ensure ! ( owned >= amount, Error :: <T >:: NotEnoughOwned ) ;
84
81
85
82
NFTsForSale :: < T > :: insert ( nft_id, origin. clone ( ) , SaleData { price, amount } ) ;
@@ -92,14 +89,14 @@ pub mod pallet {
92
89
#[ pallet:: weight( 0 ) ]
93
90
pub fn buy (
94
91
origin : OriginFor < T > ,
95
- nft_id : NFTId ,
92
+ nft_id : T :: NFTId ,
96
93
seller : T :: AccountId ,
97
94
amount : u128 ,
98
95
) -> DispatchResult {
99
96
let buyer = ensure_signed ( origin) ?;
100
97
101
98
let sale_data = NFTsForSale :: < T > :: get ( nft_id, seller. clone ( ) ) ;
102
- let owned = todo ! ( "get the amount owned from the pallet_nft account storage" ) ;
99
+ let owned = pallet_marketplace_nfts :: Pallet :: < T > :: account ( nft_id , seller . clone ( ) ) ;
103
100
104
101
ensure ! ( amount <= sale_data. amount, Error :: <T >:: NotEnoughInSale ) ;
105
102
ensure ! ( sale_data. amount <= owned, Error :: <T >:: NotEnoughOwned ) ;
@@ -111,7 +108,12 @@ pub mod pallet {
111
108
112
109
<T as pallet:: Config >:: Currency :: transfer ( & buyer, & seller, total_to_pay, KeepAlive ) ?;
113
110
114
- todo ! ( "call the pallet_marketplace_nft transfer function" ) ;
111
+ pallet_marketplace_nfts:: Pallet :: < T > :: unchecked_transfer (
112
+ nft_id,
113
+ seller. clone ( ) ,
114
+ buyer. clone ( ) ,
115
+ amount,
116
+ ) ;
115
117
116
118
if amount == sale_data. amount {
117
119
NFTsForSale :: < T > :: remove ( nft_id, seller. clone ( ) ) ;
0 commit comments