Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pragma solidity ^0.4.18;
- pragma experimental ABIEncoderV2;
- contract RealEstateMarket {
- struct RealEstate {
- uint id;
- string image;
- string description;
- uint256 price;
- address owner;
- }
- RealEstate[] realEstates;
- RealEstate[] realEstatesForSold;
- mapping (address => uint) public balances;
- function addRealEstate(uint id, address _owner, string image, string description, uint price) {
- RealEstate memory realEstate = RealEstate(id, image, description, price, _owner);
- realEstatesForSold.push(realEstate);
- realEstates.push(realEstate);
- }
- function getRealEstatesLength() view public returns (uint) {
- return realEstates.length;
- }
- function getRealEstate(uint id) public returns (string, string, uint, address) {
- return (
- realEstates[id].image,
- realEstates[id].description,
- realEstates[id].price,
- realEstates[id].owner);
- }
- function getRealEstateForSold(uint id) public returns (string, string, uint, address) {
- return (
- realEstatesForSold[id].image,
- realEstatesForSold[id].description,
- realEstatesForSold[id].price,
- realEstates[id].owner);
- }
- function buyRealEstate(uint id) payable {
- if(msg.sender.balance < realEstatesForSold[id].price) return;
- if(msg.value < realEstatesForSold[id].price) return;
- realEstatesForSold[id].owner.transfer(msg.value);
- // emit Sent(msg.sender, receiver, amount);
- for(uint i = 0; i < realEstates.length; i++) {
- if(realEstates[i].id == realEstatesForSold[id].id) {
- realEstates[i].owner = msg.sender;
- break;
- }
- }
- realEstatesForSold[id] = realEstatesForSold[realEstatesForSold.length - 1];
- realEstatesForSold.length--;
- }
- }
Add Comment
Please, Sign In to add comment