1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
#![cfg_attr(not(feature = "std"), no_std)]
pub use pallet::*;
pub use pallet_housing_fund as HousingFund;
pub use pallet_nft as Nft;
pub use pallet_onboarding as Onboarding;
pub use pallet_roles as Roles;
#[cfg(test)]
mod mock;
#[cfg(test)]
mod tests;
#[cfg(feature = "runtime-benchmarks")]
mod benchmarking;
pub mod weights;
pub use weights::WeightInfo;
#[frame_support::pallet]
pub mod pallet {
use super::*;
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
pub type AccountIdOf<T> = <T as frame_system::Config>::AccountId;
#[pallet::pallet]
#[pallet::generate_store(pub(super) trait Store)]
pub struct Pallet<T>(_);
#[pallet::config]
pub trait Config:
frame_system::Config
+ Roles::Config
+ Nft::Config
+ Onboarding::Config
+ HousingFund::Config
{
type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;
type WeightInfo: WeightInfo;
}
#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
NotaryValidatedAssetTransaction(AccountIdOf<T>, T::NftCollectionId, T::NftItemId),
NotaryRejectedAssetTransaction(AccountIdOf<T>, T::NftCollectionId, T::NftItemId),
SellerCancelledAssetTransaction(AccountIdOf<T>, T::NftCollectionId, T::NftItemId),
}
#[pallet::error]
pub enum Error<T> {
NotANotary,
NotASeller,
NotTheHouseOwner,
AssetDoesNotExist,
HouseHasNotFinalisedStatus,
HouseHasNotFinalisingStatus,
}
#[pallet::call]
impl<T: Config> Pallet<T> {
#[pallet::weight(10_000 + T::DbWeight::get().writes(1).ref_time())]
pub fn validate_transaction_asset(
origin: OriginFor<T>,
collection_id: T::NftCollectionId,
nft_item_id: T::NftItemId,
) -> DispatchResult {
let who = ensure_signed(origin.clone())?;
ensure!(Roles::Pallet::<T>::notaries(who.clone()).is_some(), Error::<T>::NotANotary);
let house_wrap = Onboarding::Houses::<T>::get(collection_id, nft_item_id);
ensure!(house_wrap.is_some(), Error::<T>::AssetDoesNotExist);
ensure!(
house_wrap.unwrap().status == Onboarding::AssetStatus::FINALISING,
Error::<T>::HouseHasNotFinalisingStatus
);
let collection = Self::get_possible_collection(collection_id);
Onboarding::Pallet::<T>::change_status(
origin,
collection,
nft_item_id,
Onboarding::AssetStatus::FINALISED,
)
.ok();
Self::deposit_event(Event::NotaryValidatedAssetTransaction(
who,
collection_id,
nft_item_id,
));
Ok(())
}
#[pallet::weight(10_000 + T::DbWeight::get().writes(1).ref_time())]
pub fn reject_transaction_asset(
origin: OriginFor<T>,
collection_id: T::NftCollectionId,
nft_item_id: T::NftItemId,
) -> DispatchResult {
let who = ensure_signed(origin.clone())?;
ensure!(Roles::Pallet::<T>::notaries(who.clone()).is_some(), Error::<T>::NotANotary);
let house_wrap = Onboarding::Houses::<T>::get(collection_id, nft_item_id);
ensure!(house_wrap.is_some(), Error::<T>::AssetDoesNotExist);
ensure!(
house_wrap.unwrap().status == Onboarding::AssetStatus::FINALISING,
Error::<T>::HouseHasNotFinalisingStatus
);
let collection = Self::get_possible_collection(collection_id);
Onboarding::Pallet::<T>::change_status(
origin,
collection,
nft_item_id,
Onboarding::AssetStatus::REJECTED,
)
.ok();
HousingFund::Pallet::<T>::cancel_house_bidding(collection_id, nft_item_id).ok();
Self::deposit_event(Event::NotaryRejectedAssetTransaction(
who,
collection_id,
nft_item_id,
));
Ok(())
}
#[pallet::weight(10_000 + T::DbWeight::get().writes(1).ref_time())]
pub fn cancel_transaction_asset(
origin: OriginFor<T>,
collection_id: T::NftCollectionId,
nft_item_id: T::NftItemId,
) -> DispatchResult {
let who = ensure_signed(origin.clone())?;
ensure!(Roles::Pallet::<T>::sellers(who.clone()).is_some(), Error::<T>::NotASeller);
let house_wrap = Onboarding::Houses::<T>::get(collection_id, nft_item_id);
ensure!(house_wrap.is_some(), Error::<T>::AssetDoesNotExist);
let owner: T::AccountId = Nft::Pallet::<T>::owner(collection_id, nft_item_id).unwrap();
ensure!(who == owner, Error::<T>::NotTheHouseOwner);
ensure!(
house_wrap.unwrap().status == Onboarding::AssetStatus::FINALISED,
Error::<T>::HouseHasNotFinalisedStatus
);
let collection = Self::get_possible_collection(collection_id);
Onboarding::Pallet::<T>::change_status(
origin,
collection,
nft_item_id,
Onboarding::AssetStatus::CANCELLED,
)
.ok();
HousingFund::Pallet::<T>::cancel_house_bidding(collection_id, nft_item_id).ok();
Self::deposit_event(Event::SellerCancelledAssetTransaction(
who,
collection_id,
nft_item_id,
));
Ok(())
}
}
}
use enum_iterator::all;
pub use frame_support::inherent::Vec;
impl<T: Config> Pallet<T> {
fn get_possible_collection(collection_id: T::NftCollectionId) -> Nft::PossibleCollections {
let collections = all::<Nft::PossibleCollections>().collect::<Vec<_>>();
let mut possible_collection = Nft::PossibleCollections::HOUSES;
for item in collections.iter() {
let value: T::NftCollectionId = item.value().into();
if value == collection_id {
possible_collection = *item;
break
}
}
possible_collection
}
}