|
| 1 | +pragma solidity ^0.4.23; |
| 2 | + |
| 3 | +import "./Administratable.sol"; |
| 4 | +import "zeppelin-solidity/contracts/math/SafeMath.sol"; |
| 5 | +import "./Orders.sol"; |
| 6 | + |
| 7 | + |
| 8 | +contract ChangeRequests is Administratable { |
| 9 | + using SafeMath for uint256; |
| 10 | + |
| 11 | + mapping(uint => ChangeRequest) requests; |
| 12 | + |
| 13 | + mapping(uint => uint[2]) actualRequests; |
| 14 | + |
| 15 | + uint requestsAmount; |
| 16 | + |
| 17 | + struct ChangeRequest { |
| 18 | + uint dealID; |
| 19 | + Orders.OrderType requestType; |
| 20 | + uint price; |
| 21 | + uint duration; |
| 22 | + RequestStatus status; |
| 23 | + } |
| 24 | + |
| 25 | + enum RequestStatus { |
| 26 | + REQUEST_UNKNOWN, |
| 27 | + REQUEST_CREATED, |
| 28 | + REQUEST_CANCELED, |
| 29 | + REQUEST_REJECTED, |
| 30 | + REQUEST_ACCEPTED |
| 31 | + } |
| 32 | + |
| 33 | + |
| 34 | + constructor() public { |
| 35 | + owner = msg.sender; |
| 36 | + administrator = msg.sender; |
| 37 | + } |
| 38 | + |
| 39 | + function Write( |
| 40 | + uint _dealID, |
| 41 | + Orders.OrderType _requestType, |
| 42 | + uint _price, |
| 43 | + uint _duration, |
| 44 | + RequestStatus _status) public onlyOwner returns(uint){ |
| 45 | + |
| 46 | + requestsAmount = requestsAmount.add(1); |
| 47 | + |
| 48 | + requests[requestsAmount] = ChangeRequest(_dealID, _requestType, _price, _duration, _status); |
| 49 | + |
| 50 | + return requestsAmount; |
| 51 | + } |
| 52 | + |
| 53 | + //SETTERS |
| 54 | + |
| 55 | + function SetChangeRequestDealID(uint _changeRequestID, uint _dealID) public onlyOwner { |
| 56 | + requests[_changeRequestID].dealID = _dealID; |
| 57 | + } |
| 58 | + |
| 59 | + function SetChangeRequestType(uint _changeRequestID, Orders.OrderType _type) public onlyOwner { |
| 60 | + requests[_changeRequestID].requestType = _type; |
| 61 | + } |
| 62 | + |
| 63 | + function SetChangeRequestPrice(uint _changeRequestID, uint _price) public onlyOwner { |
| 64 | + requests[_changeRequestID].price = _price; |
| 65 | + } |
| 66 | + |
| 67 | + function SetChangeRequestDuration(uint _changeRequestID, uint _duration) public onlyOwner { |
| 68 | + requests[_changeRequestID].duration = _duration; |
| 69 | + } |
| 70 | + |
| 71 | + function SetChangeRequestStatus(uint _changeRequestID, RequestStatus _status) public onlyOwner { |
| 72 | + requests[_changeRequestID].status = _status; |
| 73 | + } |
| 74 | + |
| 75 | + function SetActualChangeRequest(uint dealID, uint role, uint _changeRequestID) public onlyOwner { |
| 76 | + actualRequests[dealID][role] = _changeRequestID; |
| 77 | + } |
| 78 | + |
| 79 | + // GETTERS |
| 80 | + |
| 81 | + function GetChangeRequestDealID(uint _changeRequestID) public view returns(uint) { |
| 82 | + return requests[_changeRequestID].dealID; |
| 83 | + } |
| 84 | + |
| 85 | + function GetChangeRequestType(uint _changeRequestID) public view returns(Orders.OrderType) { |
| 86 | + return requests[_changeRequestID].requestType; |
| 87 | + } |
| 88 | + |
| 89 | + function GetChangeRequestPrice(uint _changeRequestID) public view returns(uint) { |
| 90 | + return requests[_changeRequestID].price; |
| 91 | + } |
| 92 | + |
| 93 | + function GetChangeRequestDuration(uint _changeRequestID) public view returns(uint) { |
| 94 | + return requests[_changeRequestID].duration; |
| 95 | + } |
| 96 | + |
| 97 | + function GetChangeRequestStatus(uint _changeRequestID) public view returns(RequestStatus) { |
| 98 | + return requests[_changeRequestID].status; |
| 99 | + } |
| 100 | + |
| 101 | + function GetActualChangeRequest(uint dealID, uint role)public view returns(uint) { |
| 102 | + return actualRequests[dealID][role]; |
| 103 | + |
| 104 | + } |
| 105 | + |
| 106 | + function GetChangeRequestsAmount() public view returns(uint) { |
| 107 | + return requestsAmount; |
| 108 | + } |
| 109 | + |
| 110 | + function GetChangeRequestInfo(uint changeRequestID) public view |
| 111 | + returns ( |
| 112 | + uint dealID, |
| 113 | + Orders.OrderType requestType, |
| 114 | + uint price, |
| 115 | + uint duration, |
| 116 | + RequestStatus status |
| 117 | + ) { |
| 118 | + return ( |
| 119 | + requests[changeRequestID].dealID, |
| 120 | + requests[changeRequestID].requestType, |
| 121 | + requests[changeRequestID].price, |
| 122 | + requests[changeRequestID].duration, |
| 123 | + requests[changeRequestID].status |
| 124 | + ); |
| 125 | + } |
| 126 | + |
| 127 | + |
| 128 | +} |
0 commit comments