SHARE
TWEET

Untitled

a guest Jun 27th, 2019 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. contract DominantAssuranceContract {
  2.     address owner;
  3.     uint256 deadline;
  4.     uint256 goal;
  5.     uint8 percentagePayoff;
  6.     mapping(address => uint256) public balanceOf;
  7.     uint256 totalPledges;
  8.  
  9.     constructor(uint256 numberOfDays, uint256 _goal, uint8 _percentagePayoff) public payable {
  10.         owner = msg.sender;
  11.         deadline = now + (numberOfDays * 1 days);
  12.         goal = _goal;
  13.         percentagePayoff = _percentagePayoff;
  14.         balanceOf[msg.sender] = msg.value;
  15.     }
  16.  
  17.     function pledge(uint256 amount) public payable {
  18.         require(now < deadline, "The campaign is over.");
  19.         require(msg.value == amount, "The amount is incorrect.");
  20.         require(msg.sender != owner, "The owner cannot pledge.");
  21.  
  22.         uint256 payoff = amount * percentagePayoff / 100;
  23.         if (payoff > balanceOf[owner]) {
  24.             payoff = balanceOf[owner];
  25.         }
  26.         balanceOf[owner] -= payoff;
  27.         balanceOf[msg.sender] += amount+payoff;
  28.         totalPledges += amount;
  29.     }
  30.  
  31.     function claimFunds() public {
  32.         require(now >= deadline, "The campaign is not over.");
  33.         require(totalPledges >= goal, "The funding goal was not met.");
  34.         require(msg.sender == owner, "Only the owner may claim funds.");
  35.  
  36.         msg.sender.transfer(address(this).balance);
  37.     }
  38.  
  39.     function getRefund() public {
  40.         require(now >= deadline, "The campaign is still active.");
  41.         require(totalPledges < goal, "Funding goal was met.");
  42.  
  43.         uint256 amount = balanceOf[msg.sender];
  44.         balanceOf[msg.sender] = 0;
  45.         msg.sender.transfer(amount);
  46.     }
  47. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top