Blockchain Business Example "Smart Property Contract"
This contract is for tangible and intangible property such as Cars, Houses or Patents.
Can be used to record and verify property rights.
First,
Second,
Can be used to record and verify property rights.
First,
payable
is a modifier that can be added to a function. It's impossible to have payable()
as a function name as it is a reserved keyword. You may use payable
only in addition to existing functions Second,
Payable
allows a function to receive ether while being called as stated in docs.It's manadatory from solidity 0.4.x. If you try to send ether using callpragma solidity ^0.4.18;
contract LandAresh {
address public owner;
uint public defaultCost;
uint public mainLandCost;
mapping(uint => mapping(uint => address))public properties;
mapping(uint => mapping(uint => address))public landContent;
mapping(uint => mapping(uint => bool))public status;
mapping(uint => mapping(uint => uint))public prices;
function LandAresh() public {
owner = msg.sender;
}
//x and y represent the position of the land in a GRID
function setLandPrice(uint x,uint y,uint price) public
{
if(status[x][y])
{
if(msg.sender==properties[x][y])
{
prices[x][y]=price;
}
}
else
{
if(msg.sender==owner)
{
prices[x][y]=price;
}
}
}
function setMainLandCost(uint price) public
{
if(msg.sender==owner) mainLandCost=price;
}
function setDefaultCost(uint price) public
{
if(msg.sender==owner) defaultCost=price;
}
function getLocation(uint x,uint y)public constant returns(uint,address,bool)
{
return(prices[x][y],properties[x][y],status[x][y]);
}
function buyMainLand() public payable
{
//If bigger than zero, means lang is available
if(mainLandCost>0)
{
if(msg.value>=mainLandCost)
{
owner=msg.sender;
mainLandCost=0;
}
}
}
function buyLand(uint x,uint y)public payable
{
if(status[x][y])
{
//land has owner
if(prices[x][y]>0) //if price is not zero then its for sale
{
if(msg.value>=prices[x][y]) //sell at higher price
{
properties[x][y]=msg.sender; //sold, assigned owner
}
}
}
else
{
//land has no owner
if(prices[x][y]>0)
{
if(msg.value>=prices[x][y])
{
properties[x][y]=msg.sender;
status[x][y]=true;
}
}
if(prices[x][y]==0)
{
if(msg.value>=defaultCost)
{
properties[x][y]=msg.sender;
}
}
}
}
function setLand(uint x,uint y,address entity) public
{
if(status[x][y])
{
//if status is true, land contains property
if(properties[x][y]==msg.sender)
{
landContent[x][y]=entity;
}
else
{
revert();
}
}
else
{
//land has no property
if(owner==msg.sender)
{
landContent[x][y]=entity;
}
else
{
revert();
}
}
}
}
Comments
Post a Comment