Guest User

Untitled

a guest
Nov 21st, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.51 KB | None | 0 0
  1. pragma solidity ^0.4.18;
  2.  
  3. contract PChannel {
  4.  
  5. string public name = 'Payment channel';
  6.  
  7. string public symbol = 'ETH';
  8.  
  9. /**
  10. * Contract owner
  11. */
  12. address public owner = msg.sender;
  13.  
  14. /**
  15. * Fee for refund, send and forward
  16. */
  17. uint256 public fee = 1 szabo;
  18.  
  19. /**
  20. */
  21. uint256 public trFee = 0;
  22.  
  23. /**
  24. * User balances
  25. */
  26. mapping(address => uint256) private balances;
  27.  
  28. /**
  29. * Decimals for balances
  30. */
  31. uint8 public constant decimals = 18;
  32.  
  33. uint256 public totalSupply = 0;
  34.  
  35. /**
  36. * event for token purchase logging
  37. * @param purchaser who paid for the weis
  38. * @param beneficiary who got the weis
  39. * @param value weis paid for purchase
  40. * @param amount amount of wei purchased
  41. */
  42. event TokenPurchase (
  43. address indexed purchaser,
  44. address indexed beneficiary,
  45. uint256 value,
  46. uint256 amount
  47. );
  48.  
  49. function balanceOf(address addr) public constant returns (uint256) {
  50. return balances[addr];
  51. }
  52.  
  53. /**
  54. * Store wei in contract
  55. */
  56. function () public payable {
  57. require(msg.value > 0);
  58.  
  59. totalSupply += msg.value;
  60. balances[msg.sender] += msg.value;
  61.  
  62. TokenPurchase(msg.sender, msg.sender, msg.value, msg.value);
  63. }
  64.  
  65. /**
  66. * Send wei for user allocated in contract
  67. * @param to who got weis
  68. */
  69. function send(address to) public payable {
  70. require(to!=address(0));
  71. require(msg.value > fee);
  72.  
  73. uint256 amount = msg.value - fee;
  74. totalSupply += msg.value;
  75. balances[to] += amount;
  76. balances[owner] += fee;
  77.  
  78. TokenPurchase(msg.sender, to, msg.value, amount);
  79. }
  80.  
  81. /**
  82. * Forward payment to 'to' from sender
  83. */
  84. function forward(address to) public payable {
  85. require(to!=address(0));
  86. require(msg.value > fee);
  87.  
  88. uint256 amount = msg.value - fee;
  89. totalSupply += fee;
  90. balances[owner] += fee;
  91.  
  92. TokenPurchase(address(this), to, msg.value, amount);
  93.  
  94. to.transfer(amount);
  95. }
  96.  
  97. /**
  98. * Transfer wei from sender to 'to'
  99. */
  100. function transfer(address to, uint256 value) public {
  101. require(to!=address(0));
  102. require(balances[msg.sender]>=value+trFee);
  103.  
  104. uint256 amount = value - trFee;
  105. balances[msg.sender] -= amount;
  106. balances[to] += amount;
  107. balances[owner] += trFee;
  108.  
  109. TokenPurchase(msg.sender, to, value, value);
  110. }
  111.  
  112. /**
  113. * Refund 'value' wei to sender
  114. */
  115. function refund(uint256 value) public {
  116. require(balances[msg.sender]>value+fee);
  117.  
  118. uint256 amount = value - fee;
  119. balances[msg.sender] -= value;
  120. balances[owner] += fee;
  121. totalSupply -= amount;
  122.  
  123. TokenPurchase(address(this), msg.sender, value, amount);
  124.  
  125. msg.sender.transfer(amount);
  126. }
  127.  
  128. /**
  129. * Allocate fee for transfer
  130. */
  131. function setTrFee(uint256 _fee) public {
  132. require(msg.sender == owner);
  133. trFee = _fee;
  134. }
  135.  
  136. /**
  137. * Allocate new fee
  138. */
  139. function setFee(uint256 _fee) public {
  140. require(msg.sender == owner);
  141. fee = _fee;
  142. }
  143.  
  144. /**
  145. * Allocate new owner
  146. */
  147. function transferOwnership(address newOwner) public {
  148. require(msg.sender==owner && newOwner != address(0));
  149.  
  150. balances[newOwner] = balances[owner];
  151. balances[owner] = 0;
  152.  
  153. owner = newOwner;
  154. }
  155.  
  156. }
Add Comment
Please, Sign In to add comment