Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. pragma solidity ^0.4.0;
  2.  
  3. /// @title Feedback Requests on the Blockchain
  4. contract Connect {
  5. struct Agent {
  6. bool active;
  7. uint tip_amount;
  8. }
  9.  
  10. struct Request
  11. {
  12. bytes32 stella_id;
  13. int stars;
  14. address customer;
  15. address agent;
  16. uint end_time;
  17. }
  18.  
  19. // The amount of time a request is valid for
  20. uint public request_valid_for;
  21.  
  22. // The address of the person who initiates feedback requests
  23. address public designated_requester;
  24.  
  25. // stores an `Agent` struct
  26. mapping(address => Agent) public agents;
  27.  
  28. // stores `Request` structs
  29. mapping(bytes32 => Request) public requests;
  30.  
  31. modifier isAdmin() {
  32. if (msg.sender != designated_requester) throw;
  33. _;
  34. }
  35.  
  36. modifier isAgentInGoodStanding() {
  37. if (!agents[msg.sender].active) throw;
  38. _;
  39. }
  40.  
  41. function CreateAgent(address agent, uint tip_amount)
  42. isAdmin
  43. {
  44. agents[agent] = Agent({
  45. active: true,
  46. tip_amount: tip_amount
  47. });
  48. }
  49.  
  50.  
  51. // Request feedback on a particular agent as an admin
  52. function RequestFeedbackOnAgent(bytes32 stella_id, address agent, address customer)
  53. isAdmin
  54. {
  55. requests[stella_id] = Request({
  56. agent: agent,
  57. stars: -1,
  58. customer: customer,
  59. stella_id: stella_id,
  60. end_time: now + request_valid_for
  61. });
  62. }
  63.  
  64. // Request feedback on oneself
  65. function RequestFeedbackOnSelf(bytes32 stella_id, address customer)
  66. isAgentInGoodStanding
  67. {
  68. requests[stella_id] = Request({
  69. agent: msg.sender,
  70. stars: -1,
  71. customer: customer,
  72. stella_id: stella_id,
  73. end_time: now + request_valid_for
  74. });
  75. }
  76.  
  77. // For a customer - send feedback on request
  78. function SendFeedback(bytes32 stella_id, int stars)
  79. {
  80. Request request = requests[stella_id];
  81. // ensure customer can respond for this request
  82. // that it hasn't been filled out
  83. // and it's not overdue
  84. if (msg.sender != request.customer) { throw; }
  85. if (request.stars > -1) { throw; }
  86. if (now > request.end_time) { throw; }
  87.  
  88. // set stars
  89. request.stars = stars;
  90. // pay agent if 5 star
  91. if (stars == 5) {
  92. Agent agent = agents[request.agent];
  93. request.agent.send(agent.tip_amount);
  94. }
  95. }
  96.  
  97. function updateTipAmount(address agent, uint tip_amount)
  98. isAdmin
  99. {
  100. agents[agent].tip_amount = tip_amount;
  101. }
  102.  
  103. function refundAll()
  104. isAdmin
  105. {
  106. designated_requester.send(this.balance);
  107. }
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement