Advertisement
Guest User

Untitled

a guest
Nov 18th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.33 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 period; //Период
  16. uint time; //
  17. uint start; //Дата начала
  18. uint finish;
  19. State status;
  20. }
  21.  
  22. Loan loan;
  23.  
  24.  
  25. event CreditNew(address borrower, uint amount, uint time);
  26. event AcceptedLoan(address borrower);
  27. event ActivatedLoan(address borrower, bytes key);
  28. event Pay(address from, uint amount);
  29. event ChangeStatus(address who, State status);
  30. event Withdrawal(address _who, uint refund);
  31.  
  32. modifier onlyAdmin() {
  33. require (msg.sender == admin);
  34. _;
  35. }
  36.  
  37.  
  38. modifier onlyBank() {
  39. require(msg.sender == admin);
  40. _;
  41. }
  42.  
  43. modifier onlyBorrower() {
  44. require(msg.sender == loan.borrower);
  45. _;
  46. }
  47.  
  48. modifier checkAmount() {
  49. require(msg.value > loan.amount);
  50. _;
  51. }
  52.  
  53. function SuperContract(address borrower, uint amount, uint time) {
  54. admin = msg.sender;
  55. CreditNew(borrower, amount, time);
  56.  
  57. loan.borrower = borrower;
  58. loan.amount = amount;
  59. loan.time = time;
  60. loan.status = State.New;
  61. }
  62.  
  63. function acceptLoan() onlyBorrower {
  64.  
  65. require(loan.status == State.New);
  66.  
  67. AcceptedLoan(msg.sender);
  68. //ChangeStatus(msg.sender, State.Accepted);
  69.  
  70. loan.status = State.Accepted;
  71. }
  72.  
  73. function activateLoan(address borrower, bytes key) onlyBank {
  74. require(loan.status == State.Accepted);
  75.  
  76. ActivatedLoan(borrower, key);
  77. //ChangeStatus(borrower, State.Paid);
  78.  
  79. loan.status = State.Paid;
  80. loan.start = now;
  81. }
  82.  
  83. function pay() checkAmount onlyBorrower payable {
  84. Pay(msg.sender, msg.value);
  85. uint _value = loan.current;
  86. //Need to add SafeMath
  87. loan.current = _value + msg.value;
  88.  
  89. if (loan.current > loan.amount) {
  90. ChangeStatus(msg.sender, State.Finished);
  91. loan.status = State.Finished;
  92. }
  93. }
  94.  
  95. function check(address _who) constant returns (State status) {
  96. State currentStatus = loan.status;
  97.  
  98. //Нужно прописать проверки
  99. if (false) {
  100. ChangeStatus(_who, State.Suspended);
  101. loan.status = State.Suspended;
  102. }
  103.  
  104. if (false) {
  105. ChangeStatus(_who, State.Locked);
  106. loan.status = State.Locked;
  107. }
  108.  
  109.  
  110. return loan.status;
  111. }
  112. function blockAccount(address _who) {}
  113.  
  114. function getCurrent() constant returns (uint currentAmount) {
  115. return loan.current;
  116. }
  117.  
  118. function withdraw(address _who) onlyBorrower {
  119. require(loan.status == State.Finished);
  120. require(loan.current > loan.amount);
  121.  
  122. //Need to add SafeMath
  123. uint refund = loan.current - loan.amount;
  124.  
  125. Withdrawal(_who, refund);
  126. loan.current = loan.amount;
  127.  
  128. /* if (msg.sender.) {
  129.  
  130. }
  131. */
  132. }
  133.  
  134.  
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement