pragma solidity ^0.4.24; contract PropertyAuction{ address public owner; uint public price; string public addr; uint public area; uint public propID; bool public openBid; address public chosenBuyer; uint public chosenPrice; bool chosen; bool approved; struct Bidder{ address bidderAddr; uint proposedPrice; } Bidder[] public bidders; mapping(address => Bidder) b; constructor(string _addr, uint _area, uint _propID) public { owner = msg.sender; addr = _addr; area = _area; propID = _propID; price = 0; openBid = false; chosenBuyer = address(0x0); } event offerReceived(address sender); event buyerChosen(address bC); event moneySent(uint amount); modifier restricted(){ require(msg.sender == owner); _; } function setPrice(uint _price) public restricted{ price = _price; openBid = true; chosen = false; approved = false; } function sendBid(uint _proposedPrice) public{ require(openBid ==true); Bidder memory bb = Bidder(msg.sender, _proposedPrice); bidders.push(bb); b[msg.sender] = bb; emit offerReceived(msg.sender); } function closeBid() public restricted{ openBid = false; } function chooseBuyer() public restricted returns(address maxbuyer, uint maxPrice){ require( openBid == false); uint i; uint maxP; address maxbid; for(i=0;i<bidders.length-1;i++){ maxP =max(bidders[i].proposedPrice, bidders[i+1].proposedPrice); maxbid = bidders[i].bidderAddr; } chosen = true; chosenBuyer = maxbid; chosenPrice = maxP; return (maxbid, maxP); } function approveBuyer() public restricted{ require(chosen == true); approved = true; emit buyerChosen(chosenBuyer); } function disapproveBuyer() public restricted{ approved = false; chosenBuyer = address(0x0); openBid = true; } function sendMoney() public payable{ require(msg.sender == chosenBuyer && msg.value == chosenPrice && approved ==true); emit moneySent(msg.value); } function getBalance() public view returns(uint){ return address(this).balance; } function getMoney() public payable restricted{ require(approved ==true); owner.transfer(chosenPrice); } function max(uint a, uint c) private pure returns (uint) { return a > c ? a : c; } }
0.4.24