Advertisement
Guest User

Untitled

a guest
Nov 19th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.94 KB | None | 0 0
  1. pragma solidity ^0.4.0;
  2.  
  3. contract SuperContract {
  4.  
  5. address admin;
  6.  
  7. enum State { Undefined, New, Accepted, Paid, Suspended, Locked, Finished }
  8.  
  9. struct Loan {
  10. bytes32 name;
  11. address borrower;
  12. uint amount; //Выданная сумма - 10000
  13. uint current; //Выплачено - 9000
  14. uint quantityOfPeriods; //Кол-во периодов - 10
  15. uint currentIteration;
  16. uint period; //Период
  17. uint time; //
  18. uint start; //Дата начала
  19. uint finish;
  20. State status;
  21. }
  22.  
  23. Loan loan;
  24.  
  25.  
  26. event CreditNew(address borrower, uint amount, uint time);
  27. event AcceptedLoan(address borrower);
  28. event ActivatedLoan(address borrower, bytes key);
  29. event Pay(address from, uint amount);
  30. event ChangeStatus(address who, State status);
  31. event Withdrawal(address _who, uint refund);
  32.  
  33. modifier onlyAdmin() {
  34. require (msg.sender == admin);
  35. _;
  36. }
  37.  
  38.  
  39. modifier onlyBank() {
  40. require(msg.sender == admin);
  41. _;
  42. }
  43.  
  44. modifier onlyBorrower() {
  45. require(msg.sender == loan.borrower);
  46. _;
  47. }
  48.  
  49. modifier checkAmount() {
  50. require(msg.value > loan.amount);
  51. _;
  52. }
  53.  
  54. function SuperContract(address borrower, uint amount, uint time, uint quantityOfPeriods) {
  55. admin = msg.sender;
  56. CreditNew(borrower, amount, time);
  57.  
  58. loan.borrower = borrower;
  59. loan.amount = amount;
  60. loan.time = time;
  61. loan.quantityOfPeriods = quantityOfPeriods;
  62. loan.currentIteration = 0;
  63. loan.status = State.New;
  64. }
  65.  
  66. function acceptLoan() onlyBorrower {
  67.  
  68. require(loan.status == State.New);
  69.  
  70. AcceptedLoan(msg.sender);
  71. //ChangeStatus(msg.sender, State.Accepted);
  72.  
  73. loan.status = State.Accepted;
  74. }
  75.  
  76. function activateLoan(address borrower, bytes key) onlyBank {
  77. require(loan.status == State.Accepted);
  78.  
  79. ActivatedLoan(borrower, key);
  80. //ChangeStatus(borrower, State.Paid);
  81.  
  82. loan.status = State.Paid;
  83. loan.start = now;
  84. }
  85.  
  86. function pay() checkAmount onlyBorrower payable {
  87. Pay(msg.sender, msg.value);
  88. uint _value = loan.current;
  89. //Need to add SafeMath
  90.  
  91. //Если вышел из минуса
  92. if (false) {
  93. ChangeStatus(msg.sender, State.Paid);
  94. loan.status = State.Paid;
  95. }
  96.  
  97. loan.current = _value + msg.value;
  98.  
  99. if (loan.current >= loan.amount) {
  100. ChangeStatus(msg.sender, State.Finished);
  101. loan.status = State.Finished;
  102. }
  103.  
  104. loan.currentIteration++;
  105. }
  106.  
  107. function check(address _who) constant returns (State status) {
  108. State currentStatus = loan.status;
  109. //Нужно прописать проверки
  110. if (false) {
  111. ChangeStatus(_who, State.Suspended);
  112. loan.status = State.Suspended;
  113. }
  114.  
  115. if (false) {
  116. ChangeStatus(_who, State.Locked);
  117. loan.status = State.Locked;
  118. }
  119.  
  120.  
  121. return loan.status;
  122. }
  123. function blockAccount(address _who) {}
  124.  
  125. function getCurrent() constant returns (uint currentAmount) {
  126. return loan.current;
  127. }
  128.  
  129. function doSuspend() {
  130.  
  131. ChangeStatus(loan.borrower, State.Suspended);
  132. loan.status = State.Suspended;
  133. }
  134.  
  135. function doLock() {
  136. ChangeStatus(loan.borrower, State.Locked);
  137. loan.status = State.Locked;
  138. }
  139.  
  140. function withdraw(address _who) onlyBorrower {
  141. require(loan.status == State.Finished);
  142. require(loan.current > loan.amount);
  143.  
  144. //Need to add SafeMath
  145. uint refund = loan.current - loan.amount;
  146.  
  147. Withdrawal(_who, refund);
  148. loan.current = loan.amount;
  149.  
  150. /* if (msg.sender.) {
  151.  
  152. }
  153. */
  154. }
  155.  
  156.  
  157. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement