-
Notifications
You must be signed in to change notification settings - Fork 32
/
Agreement.sol
182 lines (156 loc) · 4.73 KB
/
Agreement.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
pragma solidity 0.4.26;
import "./AccessControl/AccessControlled.sol";
import "./AccessRoles.sol";
import "./Standards/IAgreement.sol";
/**
* @title legally binding smart contract
* @dev read IAgreement for details
**/
contract Agreement is
IAgreement,
AccessControlled,
AccessRoles
{
////////////////////////
// Type declarations
////////////////////////
/// @notice agreement with signature of the platform operator representative
struct SignedAgreement {
address contractLegalRepresentative;
uint256 signedBlockTimestamp;
string agreementUri;
}
////////////////////////
// Immutable state
////////////////////////
IEthereumForkArbiter private ETHEREUM_FORK_ARBITER;
////////////////////////
// Mutable state
////////////////////////
// stores all amendments to the agreement, first amendment is the original
SignedAgreement[] private _amendments;
// stores block numbers of all addresses that signed the agreement (signatory => block number)
mapping(address => uint256) private _signatories;
////////////////////////
// Modifiers
////////////////////////
/// @notice logs that agreement was accepted by platform user
/// @dev intended to be added to functions that if used make 'accepter' origin to enter legally binding agreement
modifier acceptAgreement(address accepter) {
acceptAgreementInternal(accepter);
_;
}
modifier onlyLegalRepresentative(address legalRepresentative) {
require(mCanAmend(legalRepresentative));
_;
}
////////////////////////
// Constructor
////////////////////////
constructor(IAccessPolicy accessPolicy, IEthereumForkArbiter forkArbiter)
AccessControlled(accessPolicy)
internal
{
require(forkArbiter != IEthereumForkArbiter(0x0));
ETHEREUM_FORK_ARBITER = forkArbiter;
}
////////////////////////
// Public functions
////////////////////////
function amendAgreement(string agreementUri)
public
onlyLegalRepresentative(msg.sender)
{
SignedAgreement memory amendment = SignedAgreement({
contractLegalRepresentative: msg.sender,
signedBlockTimestamp: block.timestamp,
agreementUri: agreementUri
});
_amendments.push(amendment);
emit LogAgreementAmended(msg.sender, agreementUri);
}
function ethereumForkArbiter()
public
constant
returns (IEthereumForkArbiter)
{
return ETHEREUM_FORK_ARBITER;
}
function currentAgreement()
public
constant
returns
(
address contractLegalRepresentative,
uint256 signedBlockTimestamp,
string agreementUri,
uint256 index
)
{
require(_amendments.length > 0);
uint256 last = _amendments.length - 1;
SignedAgreement storage amendment = _amendments[last];
return (
amendment.contractLegalRepresentative,
amendment.signedBlockTimestamp,
amendment.agreementUri,
last
);
}
function pastAgreement(uint256 amendmentIndex)
public
constant
returns
(
address contractLegalRepresentative,
uint256 signedBlockTimestamp,
string agreementUri,
uint256 index
)
{
SignedAgreement storage amendment = _amendments[amendmentIndex];
return (
amendment.contractLegalRepresentative,
amendment.signedBlockTimestamp,
amendment.agreementUri,
amendmentIndex
);
}
function agreementSignedAtBlock(address signatory)
public
constant
returns (uint256 blockNo)
{
return _signatories[signatory];
}
function amendmentsCount()
public
constant
returns (uint256)
{
return _amendments.length;
}
////////////////////////
// Internal functions
////////////////////////
/// provides direct access to derived contract
function acceptAgreementInternal(address accepter)
internal
{
if(_signatories[accepter] == 0) {
require(_amendments.length > 0);
_signatories[accepter] = block.number;
emit LogAgreementAccepted(accepter);
}
}
//
// MAgreement Internal interface (todo: extract)
//
/// default amend permission goes to ROLE_PLATFORM_OPERATOR_REPRESENTATIVE
function mCanAmend(address legalRepresentative)
internal
returns (bool)
{
return accessPolicy().allowed(legalRepresentative, ROLE_PLATFORM_OPERATOR_REPRESENTATIVE, this, msg.sig);
}
}