Guest User

Untitled

a guest
May 24th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. pragma solidity ^0.4.18;
  2. pragma experimental ABIEncoderV2;
  3.  
  4. contract RealEstateMarket {
  5. struct RealEstate {
  6. uint id;
  7. string image;
  8. string description;
  9. uint256 price;
  10. address owner;
  11. }
  12. RealEstate[] realEstates;
  13. RealEstate[] realEstatesForSold;
  14.  
  15. mapping (address => uint) public balances;
  16.  
  17. function addRealEstate(uint id, address _owner, string image, string description, uint price) {
  18. RealEstate memory realEstate = RealEstate(id, image, description, price, _owner);
  19.  
  20. realEstatesForSold.push(realEstate);
  21. realEstates.push(realEstate);
  22. }
  23.  
  24. function getRealEstatesLength() view public returns (uint) {
  25. return realEstates.length;
  26.  
  27. }
  28.  
  29. function getRealEstate(uint id) public returns (string, string, uint, address) {
  30. return (
  31. realEstates[id].image,
  32. realEstates[id].description,
  33. realEstates[id].price,
  34. realEstates[id].owner);
  35. }
  36.  
  37. function getRealEstateForSold(uint id) public returns (string, string, uint, address) {
  38. return (
  39. realEstatesForSold[id].image,
  40. realEstatesForSold[id].description,
  41. realEstatesForSold[id].price,
  42. realEstates[id].owner);
  43. }
  44.  
  45. function buyRealEstate(uint id) payable {
  46. if(msg.sender.balance < realEstatesForSold[id].price) return;
  47. if(msg.value < realEstatesForSold[id].price) return;
  48.  
  49. realEstatesForSold[id].owner.transfer(msg.value);
  50. // emit Sent(msg.sender, receiver, amount);
  51.  
  52. for(uint i = 0; i < realEstates.length; i++) {
  53. if(realEstates[i].id == realEstatesForSold[id].id) {
  54. realEstates[i].owner = msg.sender;
  55. break;
  56. }
  57. }
  58.  
  59. realEstatesForSold[id] = realEstatesForSold[realEstatesForSold.length - 1];
  60. realEstatesForSold.length--;
  61. }
  62. }
Add Comment
Please, Sign In to add comment