Advertisement
Guest User

Untitled

a guest
Sep 28th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 KB | None | 0 0
  1.  
  2. contract owned {
  3. address public owner;
  4.  
  5. function owned() {
  6. owner = msg.sender;
  7. }
  8.  
  9. modifier onlyOwner {
  10. if (msg.sender != owner) throw;
  11. _
  12. }
  13.  
  14. function transferOwnership(address newOwner) onlyOwner {
  15. owner = newOwner;
  16. }
  17. }
  18.  
  19. contract token { function transfer(address receiver, uint amount){ } }
  20.  
  21.  
  22. contract Sell is owned {
  23.  
  24. /*contract variable */
  25. address public beneficiary;
  26. uint public fundingGoal;
  27. uint public amountRaised;
  28. // uint public deadline;
  29. uint public price;
  30. token public tokenReward;
  31. mapping(address => uint256) public balanceOf;
  32. bool fundingGoalReached = false;
  33. event GoalReached(address beneficiary, uint amountRaised);
  34. event FundTransfer(address backer, uint amount, bool isContribution);
  35. event Collected(address beneficiary, uint amountRaised);
  36. bool crowdsaleClosed = false;
  37. //uint amountToPay;
  38. //uint amountAll;
  39.  
  40. uint256 public sellPrice;
  41. /* Initialization */
  42. function Sell(
  43.  
  44. address ifSuccessfulSendTo,
  45. // uint fundingGoalInEthers,
  46. // uint durationInMinutes,
  47. uint etherCostOfEachToken,
  48. token addressOfTokenUsedAsReward
  49. ) {
  50. beneficiary = ifSuccessfulSendTo;
  51. // fundingGoal = fundingGoalInEthers * 1 ether;
  52. // deadline = now + durationInMinutes * 1 minutes;
  53. price = etherCostOfEachToken * 1 ether;
  54. tokenReward = token(addressOfTokenUsedAsReward);
  55. }
  56.  
  57.  
  58.  
  59. /* The function without name is the default function that is called whenever anyone sends funds to a contract */
  60. function () {
  61. if (crowdsaleClosed) throw;
  62. uint amount = msg.value;
  63. balanceOf[msg.sender] = amount;
  64. amountRaised += amount;
  65. tokenReward.transfer(msg.sender, amount / price);
  66. FundTransfer(msg.sender, amount, true);
  67. }
  68.  
  69. function safeWithdrawal() {
  70.  
  71.  
  72. if (beneficiary == msg.sender) {
  73. // amountToPay=amountRaised;
  74. if (beneficiary.send(amountRaised)) {
  75.  
  76. FundTransfer(beneficiary, amountRaised, false);
  77. // amountAll=amountAll+amountToPay
  78. // amountToPay=0;
  79. Collected(beneficiary,amountRaised);
  80. amountRaised=0;
  81. } else {
  82. //If we fail to send the funds to beneficiary, unlock funders balance
  83. // fundingGoalReached = false;
  84. }
  85. }
  86. }
  87.  
  88.  
  89.  
  90. function closeCrowdsale(){
  91. if (beneficiary==msg.sender) {
  92.  
  93. crowdsaleClosed=true;
  94.  
  95. }
  96. }
  97.  
  98. function setPrice(uint256 newSellPrice){
  99. sellPrice=newSellPrice;
  100. }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement