-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProject.sol
563 lines (443 loc) · 12.5 KB
/
Project.sol
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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
// SPDX-License-Identifier:GPL-3.0
pragma solidity >=0.7.0 <=0.9.0;
pragma experimental ABIEncoderV2;
// Land Registration Contract
contract Project
{
/*
State variable of type address for owner of Contract
*/
address private owner;
/*
State variable of type uint for Lands count
*/
uint public landsCount;
/*
Constructor to make deployer of the contract Land Inspector
*/
constructor ()
{
owner = msg.sender;
}
/*
Event for registerOrUpdateLandInspector Function
*/
event inspectorRegister
(
string status,
address id,
string Name,
uint Age,
string Designation
);
/*
Event for registerOrUpdateSeller Function
*/
event sellerRegister
(
string status,
string Name,
uint Age,
string City,
uint CNIC,
string Email
);
/*
Event for registerOrUpdateLandBuyer Function
*/
event buyerRegister
( string status,
string Name,
uint Age,
string City,
uint CNIC,
string Email
);
/*
Event for registerLand Function
*/
event landRegister
(
string status,
uint landId,
address seller
);
/*
Event for BuyLand Function
*/
event buyingLand
(
string status,
uint landId,
uint price,
address seller,
address buyer
);
/*
Event for transferOwnership Function
*/
event ownershipTransfer
(
address oldOwner,
uint landId,
address newOwner
);
/*
Struct to store Seller data
*/
struct sellerStruct
{
string Name;
uint Age;
string City;
uint CNIC;
string Email;
bool isVerified;
uint flag;
}
/*
Struct to store Buyer data
*/
struct buyerStruct
{
string Name;
uint Age;
string City;
uint CNIC;
string Email;
bool isVerified;
uint flag;
}
/*
Struct to store Seller data
*/
struct landInspectorStruct
{
address id;
string Name;
uint Age;
string Designation;
}
/*
Struct to store Land data
*/
struct landStruct
{
uint LandId;
uint Area;
string City;
string State;
uint LandPrice;
string PropertyPID;
bool isVerified;
uint flag;
}
/*
Mappings
1. Mapping for seller to map seller address to its struct
2. Mapping for buyer to map buyer address to its struct
3. Mapping for Lands to map Land id to its struct
4. Mapping for Land Owner to map its owner's address to its struct
5. Mapping for Land Owner to map seller's address to its lad's id
*/
mapping(address => sellerStruct) private SellerMapping;
mapping(address => buyerStruct) private BuyerMapping;
mapping(uint => landStruct) public Lands;
mapping(uint => address) private landOwnerMapping;
mapping(address => uint) private ownerMapping;
/*
landInspectorStruct type variable
*/
landInspectorStruct private Inspector;
/*
Function to register or update Land Inspector, only Contract Deployer can call this function
*/
function registerOrUpdateLandInspector(string memory _name, uint _age, string memory _designation) public
{
require(msg.sender == owner, "You are not the owner");
Inspector = landInspectorStruct(owner, _name, _age, _designation);
emit inspectorRegister("Land Inspector data is successfully saved", msg.sender, _name, _age, _designation);
}
/*
Modifier to rstrict some functions use for Inspector only
*/
modifier onlyInspector()
{
require(msg.sender == Inspector.id, "You are not the Land Inspector");
_;
}
/*
Function to register or update Seller
A buyer and Inspector can not call this function
*/
function registerOrUpdateSeller
(
string memory _Name,
uint _Age,
string memory _City,
uint _CNIC,
string memory _Email
) public
{
require(msg.sender != Inspector.id, "Inspector can not be seller");
require(BuyerMapping[msg.sender].flag !=1, "This person is registered as Buyer");
SellerMapping[msg.sender] = sellerStruct(_Name, _Age, _City, _CNIC, _Email, false, 1);
emit sellerRegister("Seller data is successfully saved", _Name, _Age, _City, _CNIC, _Email);
}
/*
Function to set the verification status of seller
Only Inspector can call this function
*/
function verifySeller
(
address _address,
bool _status
) public onlyInspector
{
SellerMapping[_address].isVerified = _status;
}
/*
Function to register Land
Land should not be registered already
Caller of the function should not be registered as Buyer
Only a Seller can call this function
Seller should be verified
*/
function registerLand
(
uint _area,
string memory _city,
string memory _state,
uint _price,
string memory _Ppid
) public
{
require(Lands[ownerMapping[msg.sender]].flag != 1,"Land is already registered");
require(BuyerMapping[msg.sender].flag != 1, "This person is registered as Buyer");
require(SellerMapping[msg.sender].isVerified == true, "Seller is not verified");
landsCount ++;
Lands[landsCount] = landStruct(landsCount, _area, _city, _state, _price, _Ppid, false, 1);
landOwnerMapping[landsCount] = msg.sender;
ownerMapping[msg.sender] = landsCount;
emit landRegister("Land data successfully saved", landsCount, msg.sender);
}
/*
Function to set verification status of Land
Only Inspector can call this function
*/
function verifyLand
(
uint _landId,
bool _status
) public onlyInspector
{
Lands[_landId].isVerified = _status;
}
/*
Function to register or update Buyer
Caller of the function should not be registered as Seller
Inspector can not call his function
Anyone can call this function
*/
function registerOrUpdateBuyer
(
string memory _Name,
uint _Age,
string memory _City,
uint _CNIC,
string memory _Email
) public
{
require(msg.sender != Inspector.id, "Inspector can not be Buyer");
require(SellerMapping[msg.sender].flag !=1, "This person is registered as Seller");
BuyerMapping[msg.sender] = buyerStruct(_Name, _Age, _City, _CNIC, _Email, false, 1);
emit buyerRegister("Buyer data is successfully saved", _Name, _Age, _City, _CNIC, _Email);
}
/*
Function to set verification status of Buyer
Only Inspector can call this function
*/
function verifyBuyer
(
address _address,
bool _status
) public onlyInspector
{
BuyerMapping[_address].isVerified = _status;
}
/*
Function to transfer ownership of Land
Only land owner can call this function
*/
function TransferOwnership
(
uint _landId,
address _address
) public
{
require(keccak256(abi.encode(landOwnerMapping[_landId])) ==
keccak256(abi.encode(msg.sender)), "You are not the owner of this Land");
landOwnerMapping[_landId] = _address;
ownerMapping[msg.sender] = _landId;
emit ownershipTransfer(msg.sender, _landId, _address);
}
/*
Function to buy Land by its Land Id
Owner of Land can not buy it
Caller of function should be a verified Buyer
Owner of land should be a verified Seller
Land must be verified
Price sent by Buyer must be equal to Land Price
*/
function BuyLand
(
uint _landId
) public payable
{
require(landOwnerMapping[_landId] != msg.sender, "You can not Buy Land because you are the Owner");
require(BuyerMapping[msg.sender].isVerified == true, "Buyer is not verified");
require(SellerMapping[landOwnerMapping[_landId]].isVerified == true, "Seller is not verified");
require(Lands[_landId].isVerified == true, "Land is not verified");
if (msg.value > Lands[_landId].LandPrice*1000000000000000000)
{
payable(msg.sender).transfer(address(this).balance);
emit buyingLand("Land not bought, sent more Ethers than Land price",
_landId, Lands[_landId].LandPrice, landOwnerMapping[_landId], msg.sender);
}
else if (msg.value < Lands[_landId].LandPrice*1000000000000000000)
{
payable(msg.sender).transfer(address(this).balance);
emit buyingLand("Land not bought, sent less Ethers than Land price",
_landId, Lands[_landId].LandPrice, landOwnerMapping[_landId], msg.sender);
}
else
{
payable(landOwnerMapping[_landId]).transfer(msg.value);
landOwnerMapping[_landId] = msg.sender;
ownerMapping[msg.sender] = _landId;
emit buyingLand("Land bought successfully",
_landId, Lands[_landId].LandPrice, landOwnerMapping[_landId], msg.sender);
}
}
/*
Function to check Land Owner by Land Id
Anyone can call this function
*/
function LandOwner
(
uint _landId
) public view returns(address _address)
{
return landOwnerMapping[_landId];
}
/*
Function to check either Land is verified or not by Land Id
Anyone can call this function
*/
function LandIsVerified
(
uint _landId
) public view returns(bool)
{
return Lands[_landId].isVerified;
}
/*
Function to check either Seller is verified or not by its Address
Anyone can call this function
*/
function SellerIsVerified
(
address _address
) public view returns(bool)
{
return SellerMapping[_address].isVerified;
}
/*
Function to check either Buyer is verified or not by its Address
Anyone can call this function
*/
function BuyerIsverified
(
address _address
) public view returns(bool)
{
return BuyerMapping[_address].isVerified;
}
/*
Function to check who is the Land Inspector
Anyone can call this function
*/
function CheckLandInspector
(
) public view returns (landInspectorStruct memory)
{
return Inspector;
}
/*
Function to check what is the Land City by Land Id
Anyone can call this function
*/
function GetLandCity
(
uint _landId
) public view returns(string memory)
{
return Lands[_landId].City;
}
/*
Function to check what is the Land Price by Land Id
Anyone can call this function
*/
function GetLandPrice
(
uint _landId
) public view returns(uint)
{
return Lands[_landId].LandPrice;
}
/*
Function to check what is the area of Land by Land Id
Anyone can call this function
*/
function GetLandArea
(
uint _landId
) public view returns(uint)
{
return Lands[_landId].Area;
}
/*
Function to check is caller of function a Buyer
Anyone can call this function
*/
function isBuyer
(
) public view returns(bool)
{
if (BuyerMapping[msg.sender].flag == 1)
{
return true;
}
else
{
return false;
}
}
/*
Function to check is caller of function a Selller
Anyone can call this function
*/
function isSeller
(
) public view returns(bool)
{
if (SellerMapping[msg.sender].flag == 1)
{
return true;
}
else
{
return false;
}
}
}