-
Notifications
You must be signed in to change notification settings - Fork 0
/
Case.sol
147 lines (116 loc) · 4.96 KB
/
Case.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import "ArbiterConfig.sol";
import "CaseLibrary.sol";
contract Case {
using CaseLibrary for CaseLibrary.Data;
CaseLibrary.Data caseData;
ArbiterConfig internal config;
address public OriginatingParty;
uint public dateIssued;
event ClaimAcknowledged(bytes32 indexed claimID, address indexed acknowledgedBy, uint dateAcknowledged);
event NewClaim();
event ClaimResponse();
event PenaltyIncurred;
event AcknowledgeMessage;
event DocumentSubmitted(string indexed documentHash, uint dateSubmitted);
function Case(address _originatingParty, address[] _opposingParties, address _config){
OriginatingParty = _originatingParty;
dateIssued = now;
config = ArbiterConfig(_config);
caseData.originatingParties.primaryContract = _originatingParty;
caseData.originatingParties.members.push(_originatingParty);
caseData.originatingParties.isMember[_originatingParty] = true;
caseData.opposingParties.primaryContract = _opposingParties[0];
caseData.opposingParties.members = _opposingParties;
for(var i = 0; i < _opposingParties.length; i++){
caseData.opposingParties.isMember[_opposingParties[i]] = true;
}
}
function addClaim(string _description, uint _desiredSettlementValue) public returns(bool){
if(!caseData.newClaim(_description, _desiredSettlementValue)){
return false;
} else {
return true;
}
}
function getClaim(bytes32 _id) constant returns(string _description, uint _desiredSettlementValue,
bytes32 _status, uint _dateIssued, uint _dateAmended, uint _dateDecided, uint _amountPaid){
CaseLibrary.Claim memory c = caseData.claims[_id];
return (c.description, c.desiredSettlementValue, c.status, c.dateIssued, c.dateAmended, c.dateDecided, c.amountPaid);
}
function initialAcknowledgement(bytes32 _id) isOpposingParty() public returns(bool){
CaseLibrary.Claim memory c = caseData.claims[_id];
if(now - c.dateIssued > config.gracePeriod()){
caseData.penalties[_id][msg.sender] = config.PenaltyFee(c.dateIssued);
caseData.claims[_id].acknowledged = true;
return true;
} else {
caseData.claims[_id].acknowledged = true;
return true;
}
}
function claimResponse(bytes32 _id, uint _proposedSettlementValue) isOpposingParty() isNegotiable(_id) public returns(bool){
if(!caseData.respondToClaim(_id, _proposedSettlementValue)){
return false;
} else {
return true;
}
}
function getClaims() constant returns(bytes32[]){
return caseData.claimIDs;
}
function negotiateClaim(bytes32 _id, bool _decision) isOriginatingParty() isNegotiable(_id) public returns(bool){
// Do we agree with the claim response from the opposing party?
// if yes => close claim, update status;
// if no => reject claimResponse and update claim if desired settlement value decreases;
CaseLibrary.ClaimResponse memory CR = caseData.responses[_id][caseData.responses[_id].length - 1];
CaseLibrary.Claim memory c = caseData.claims[_id];
if(_decision){
uint platformFee = CR.amountPaid*25/1000; //.25% platform fee; Place in a config Arbiter contract for later;
if(!caseData.originatingParties.primaryContract.send(CR.amountPaid - platformFee)){
throw;
} else {
// Update the Claim
c.status = "resolved";
c.dateDecided = now;
c.amountPaid = CR.amountPaid;
caseData.claims[_id] = c;
// Update The Claim Response;
CR.dateReceived = now;
CR.accepted = true;
caseData.responses[_id][caseData.responses[_id].length - 1] = CR;
return true;
}
} else {
CR.dateReceived = now;
caseData.responses[_id][caseData.responses[_id].length - 1] = CR;
return true;
}
}
function getClaimResponse(bytes32 id) constant returns(bytes32 _claimID,
uint _amountPaid, uint _counterSettlementValue, uint _dateResponded, bool _accepted){
CaseLibrary.ClaimResponse memory CR;
CR = caseData.responses[id][caseData.responses[id].length - 1];
return (
CR.claimID,
CR.amountPaid,
CR.counterSettlementValue,
CR.dateResponded,
CR.accepted
);
}
modifier isOriginatingParty(){
if(!caseData.originatingParties.isMember[msg.sender]){
throw;
} _
}
modifier isOpposingParty(){
if(!caseData.opposingParties.isMember[msg.sender]){
throw;
} _
}
modifier isNegotiable(bytes32 id){
if(caseData.claims[id].status == "verifying" || caseData.claims[id].status == "resolved" ){
throw;
} _
}
}