Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pragma solidity ^0.4.0;
- /// @title Feedback Requests on the Blockchain
- contract Connect {
- struct Agent {
- bool active;
- uint tip_amount;
- }
- struct Request
- {
- bytes32 stella_id;
- int stars;
- address customer;
- address agent;
- uint end_time;
- }
- // The amount of time a request is valid for
- uint public request_valid_for;
- // The address of the person who initiates feedback requests
- address public designated_requester;
- // stores an `Agent` struct
- mapping(address => Agent) public agents;
- // stores `Request` structs
- mapping(bytes32 => Request) public requests;
- modifier isAdmin() {
- if (msg.sender != designated_requester) throw;
- _;
- }
- modifier isAgentInGoodStanding() {
- if (!agents[msg.sender].active) throw;
- _;
- }
- function CreateAgent(address agent, uint tip_amount)
- isAdmin
- {
- agents[agent] = Agent({
- active: true,
- tip_amount: tip_amount
- });
- }
- // Request feedback on a particular agent as an admin
- function RequestFeedbackOnAgent(bytes32 stella_id, address agent, address customer)
- isAdmin
- {
- requests[stella_id] = Request({
- agent: agent,
- stars: -1,
- customer: customer,
- stella_id: stella_id,
- end_time: now + request_valid_for
- });
- }
- // Request feedback on oneself
- function RequestFeedbackOnSelf(bytes32 stella_id, address customer)
- isAgentInGoodStanding
- {
- requests[stella_id] = Request({
- agent: msg.sender,
- stars: -1,
- customer: customer,
- stella_id: stella_id,
- end_time: now + request_valid_for
- });
- }
- // For a customer - send feedback on request
- function SendFeedback(bytes32 stella_id, int stars)
- {
- Request request = requests[stella_id];
- // ensure customer can respond for this request
- // that it hasn't been filled out
- // and it's not overdue
- if (msg.sender != request.customer) { throw; }
- if (request.stars > -1) { throw; }
- if (now > request.end_time) { throw; }
- // set stars
- request.stars = stars;
- // pay agent if 5 star
- if (stars == 5) {
- Agent agent = agents[request.agent];
- request.agent.send(agent.tip_amount);
- }
- }
- function updateTipAmount(address agent, uint tip_amount)
- isAdmin
- {
- agents[agent].tip_amount = tip_amount;
- }
- function refundAll()
- isAdmin
- {
- designated_requester.send(this.balance);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement