Advertisement
Guest User

Untitled

a guest
Dec 14th, 2019
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. pragma solidity ^0.4.24;
  2.  
  3. import "./Timer.sol";
  4.  
  5. /// This contract represents the most simple crowdfunding campaign.
  6. /// This contract does not protect investors from not receiving goods
  7. /// they were promised from the crowdfunding owner. This kind of contract
  8. /// might be suitable for campaigns that do not promise anything to the
  9. /// investors except that they will start working on the project.
  10. /// (e.g. almost all blockchain spinoffs.)
  11. contract Crowdfunding {
  12.  
  13. address private owner;
  14.  
  15. Timer private timer;
  16.  
  17. uint256 public goal;
  18.  
  19. uint256 public endTimestamp;
  20.  
  21. mapping (address => uint256) public investments;
  22.  
  23. uint256 public sumOfValues = 0;
  24.  
  25. constructor(
  26. address _owner,
  27. Timer _timer,
  28. uint256 _goal,
  29. uint256 _endTimestamp
  30. ) public {
  31. owner = _owner == 0 ? msg.sender : _owner;
  32. timer = _timer;
  33. goal = _goal;
  34. endTimestamp = _endTimestamp;
  35. }
  36.  
  37. function invest() public payable {
  38. assert(timer.getTime() < endTimestamp);
  39. investments[msg.sender] += msg.value;
  40. sumOfValues += msg.value;
  41.  
  42. }
  43.  
  44. function claimFunds() public {
  45. assert(timer.getTime() >= endTimestamp);
  46. assert(msg.sender == owner);
  47. assert(sumOfValues >= goal);
  48. owner.transfer(sumOfValues);
  49.  
  50. }
  51.  
  52. function refund() public {
  53. assert(sumOfValues < goal);
  54. assert(timer.getTime() >= endTimestamp);
  55. msg.sender.transfer(investments[msg.sender]);
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement