-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLandContract.sol
68 lines (57 loc) · 2.19 KB
/
LandContract.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
pragma solidity ^0.5.11;
//global variables here
contract LandContractBatch7
{
//This is the contract for adding Property
//State variables here
//Fixed size variable - memory is fixed already
uint public totalLandsCounter = 0; //only number, integer
// bool status; //hold either 0 or 1 value
// //Variable size - memory isnt fixed
// string name;
// uint ids[]; //[2,4,7,8]
// ids[0] => 2
// ids[1] => 4
// ids[2] => 7
// ids[0] => 2
//user defined variable - struct, enum
//struct is to create table, land is table name, and columns names and var type below it
struct Land
{
address ethaddress;
uint cost;
uint landId;
}
// Land public myLand = Land (0x5B38Da6a701c568545dCfcB03FcB875f56beddC4, 50, 1);
// Land public myLand2 = Land (0x5B38Da6a701c568545dCfcB03FcB875f56beddC4, 100, 2);
// Land public myLand3 = Land (0x5B38Da6a701c568545dCfcB03FcB875f56beddC4, 50, 3);
//mapping (unit => string) public stumapping;
mapping (address => Land[]) public ownedLands;
//ownedLands [0x5B38Da6a701c568545dCfcB03FcB875f56beddC4][0] => (0x5B38Da6a701c568545dCfcB03FcB875f56beddC4, 50, 1)
//ownedLands [0x5B38Da6a701c568545dCfcB03FcB875f56beddC4][1] => (0x5B38Da6a701c568545dCfcB03FcB875f56beddC4, 50, 1)
//to get total land in contract
function getNumberofLands() view public returns (uint)
{
return totalLandsCounter;
}
//Access control - only this address can invoke the add property function. Use IF function
modifier isOwner
{
require(msg.sender == 0x5B38Da6a701c568545dCfcB03FcB875f56beddC4);
_;
}
//Add an event & write logs
event Add(address _owner, uint _landId);
//Add a new property - create incremental row, add data in row, push row to map
function addProperty(address _ethAddress, uint _cost) public isOwner
{
totalLandsCounter = totalLandsCounter + 1;
Land memory myLand = Land({
ethaddress: _ethAddress,
cost: _cost,
landId: totalLandsCounter
});
ownedLands[_ethAddress].push(myLand);
emit Add(msg.sender, totalLandsCounter);
}
}