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
255
256
257
258
259
260
261
pub use super::*;
pub use frame_support::{
assert_ok,
dispatch::{DispatchResult, EncodeLike},
inherent::Vec,
pallet_prelude::*,
sp_runtime::traits::{AccountIdConversion, Hash, Saturating, StaticLookup, Zero},
storage::child,
traits::{
Currency, ExistenceRequirement, Get, LockableCurrency, ReservableCurrency, WithdrawReasons,
},
PalletId,
};
pub use frame_system::{ensure_signed, pallet_prelude::*, RawOrigin};
pub use scale_info::{prelude::vec, TypeInfo};
pub use serde::{Deserialize, Serialize};
pub type BalanceOf<T> =
<<T as pallet::Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
pub type AccountIdOf<T> = <T as frame_system::Config>::AccountId;
pub type BlockNumberOf<T> = <T as frame_system::Config>::BlockNumber;
pub type Idle<T> = (Vec<HouseSeller<T>>, Vec<Servicer<T>>);
#[derive(Clone, Encode, Decode, Default, PartialEq, Eq, TypeInfo, Copy)]
#[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize))]
pub enum Accounts {
INVESTOR,
#[default]
SELLER,
TENANT,
SERVICER,
NOTARY,
REPRESENTATIVE,
}
#[derive(Clone, Encode, Decode, Default, PartialEq, Eq, TypeInfo)]
#[scale_info(skip_type_params(T))]
#[cfg_attr(feature = "std", derive(Debug))]
pub struct Investor<T: Config> {
pub account_id: T::AccountId,
pub age: BlockNumberOf<T>,
pub share: BalanceOf<T>,
pub selections: u32,
}
impl<T: Config> Investor<T>
where
types::Investor<T>: EncodeLike<types::Investor<T>>,
{
pub fn new(acc: OriginFor<T>) -> DispatchResult {
let caller = ensure_signed(acc)?;
let now = <frame_system::Pallet<T>>::block_number();
let inv =
Investor { account_id: caller.clone(), age: now, share: Zero::zero(), selections: 0 };
InvestorLog::<T>::insert(caller, &inv);
Ok(())
}
}
#[derive(Clone, Encode, Decode, Default, PartialEq, Eq, TypeInfo)]
#[scale_info(skip_type_params(T))]
#[cfg_attr(feature = "std", derive(Debug))]
pub struct HouseSeller<T: Config> {
pub account_id: T::AccountId,
pub age: BlockNumberOf<T>,
pub activated: bool,
pub verifier: T::AccountId,
}
impl<T: Config> HouseSeller<T>
where
types::HouseSeller<T>: EncodeLike<types::HouseSeller<T>>,
{
pub fn new(acc: OriginFor<T>) -> DispatchResult {
let caller = ensure_signed(acc)?;
let admin = SUDO::Pallet::<T>::key().unwrap();
let now = <frame_system::Pallet<T>>::block_number();
ensure!(!HouseSellerLog::<T>::contains_key(&caller), Error::<T>::NoneValue);
let hw =
HouseSeller { account_id: caller.clone(), age: now, activated: false, verifier: admin };
SellerApprovalList::<T>::mutate(|list| {
list.push(hw);
});
RequestedRoles::<T>::insert(caller, Accounts::SELLER);
Ok(())
}
}
#[derive(Clone, Encode, Decode, Default, PartialEq, Eq, TypeInfo)]
#[scale_info(skip_type_params(T))]
#[cfg_attr(feature = "std", derive(Debug))]
pub struct Tenant<T: Config> {
pub account_id: T::AccountId,
pub rent: BalanceOf<T>,
pub age: BlockNumberOf<T>,
pub asset_account: Option<T::AccountId>,
pub contract_start: BlockNumberOf<T>,
pub remaining_rent: BalanceOf<T>,
pub remaining_payments: u8,
pub registered: bool,
}
impl<T: Config> Tenant<T> {
pub fn new(acc: OriginFor<T>) -> DispatchResult {
let caller = ensure_signed(acc)?;
let now = <frame_system::Pallet<T>>::block_number();
let tenant = Tenant {
account_id: caller.clone(),
rent: Zero::zero(),
age: now,
asset_account: None,
contract_start: now,
remaining_rent: Zero::zero(),
remaining_payments: 0,
registered: false,
};
TenantLog::<T>::insert(caller, &tenant);
Ok(())
}
}
#[derive(Clone, Encode, Decode, Default, PartialEq, Eq, TypeInfo)]
#[scale_info(skip_type_params(T))]
#[cfg_attr(feature = "std", derive(Debug))]
pub struct Servicer<T: Config> {
pub account_id: T::AccountId,
pub age: BlockNumberOf<T>,
pub activated: bool,
pub verifier: T::AccountId,
}
impl<T: Config> Servicer<T> {
pub fn new(acc: OriginFor<T>) -> DispatchResult {
let caller = ensure_signed(acc)?;
let admin = SUDO::Pallet::<T>::key().unwrap();
let now = <frame_system::Pallet<T>>::block_number();
let sv =
Servicer { account_id: caller.clone(), age: now, activated: false, verifier: admin };
ServicerApprovalList::<T>::mutate(|list| {
list.push(sv);
});
RequestedRoles::<T>::insert(caller, Accounts::SERVICER);
Ok(())
}
}
#[derive(Clone, Encode, Decode, Default, PartialEq, Eq, TypeInfo)]
#[scale_info(skip_type_params(T))]
#[cfg_attr(feature = "std", derive(Debug))]
pub struct Representative<T: Config> {
pub account_id: T::AccountId,
pub age: BlockNumberOf<T>,
pub activated: bool,
pub assets_accounts: Vec<T::AccountId>,
pub index: u32,
}
impl<T: Config> Representative<T>
where
types::Representative<T>: EncodeLike<types::Representative<T>>,
{
pub fn new(acc: OriginFor<T>) -> DispatchResult {
let caller = ensure_signed(acc)?;
let now = <frame_system::Pallet<T>>::block_number();
if !RepresentativeLog::<T>::contains_key(&caller) {
let rep = Representative::<T> {
account_id: caller.clone(),
age: now,
activated: false,
assets_accounts: Vec::new(),
index: Default::default(),
};
RepApprovalList::<T>::insert(caller, rep);
} else {
let rep = RepresentativeLog::<T>::get(&caller).unwrap();
RepApprovalList::<T>::insert(caller, rep);
}
Ok(())
}
}
#[derive(Clone, Encode, Decode, Default, PartialEq, Eq, TypeInfo)]
#[scale_info(skip_type_params(T))]
#[cfg_attr(feature = "std", derive(Debug))]
pub struct Notary<T: Config> {
pub account_id: T::AccountId,
pub age: BlockNumberOf<T>,
pub activated: bool,
pub verifier: T::AccountId,
}
impl<T: Config> Notary<T>
where
types::Notary<T>: EncodeLike<types::Notary<T>>,
{
pub fn new(acc: OriginFor<T>) -> DispatchResult {
let caller = ensure_signed(acc)?;
let now = <frame_system::Pallet<T>>::block_number();
ensure!(!NotaryLog::<T>::contains_key(&caller), Error::<T>::NoneValue);
let admin = SUDO::Pallet::<T>::key().unwrap();
let notary =
Notary { account_id: caller.clone(), age: now, activated: false, verifier: admin };
NotaryApprovalList::<T>::mutate(|list| {
list.push(notary);
});
RequestedRoles::<T>::insert(caller, Accounts::NOTARY);
Ok(())
}
}