Advertisement
Guest User

Untitled

a guest
Nov 7th, 2018
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. pragma solidity ^0.4.24;
  2.  
  3. contract Auction {
  4. address public owner;
  5. address public highestBidder; // The highest bidder's address
  6. uint public highestBid; // The amount of the highest bid
  7. mapping(address => uint) public userBalances; // mapping for the amount to return
  8.  
  9. constructor() public
  10. {
  11. // contractor
  12. // 1. Initialize highest bid and the bidder's address
  13. owner = msg.sender;
  14. highestBidder = 0;
  15. highestBid = 0;
  16. }
  17.  
  18. function bid() payable public
  19. {
  20. // Funtion to process bid
  21. // 1. Check if the bid is greater than the current highest bid
  22. // 2. Update status variable and the amount to return
  23. if(highestBid < msg.value) {
  24. highestBidder = msg.sender;
  25. highestBid = msg.value;
  26. userBalances[msg.sender] = msg.value;
  27. }
  28. }
  29.  
  30. function withdraw() public {
  31. // Function to withdraw the amount of bid to return
  32. // 1. Check if the amount to return is greater than zero
  33. // 2. Update status variablle and return bid
  34. if(userBalances[msg.sender] > 0) {
  35. msg.sender.transfer(userBalances[msg.sender]);
  36. userBalances[msg.sender] = 0;
  37. }
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement