forked from hishamaborob/ethereum-smart-contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
agreement.sol
63 lines (42 loc) · 1.76 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
pragma solidity ^0.4.6;
contract Agreement {
address public borrower;
address public lender;
struct agreementDocument {
bool approvedByBorrower;
bool approvedByLender;
}
// Publicly explorable data
mapping(bytes32 => agreementDocument) public agreementDocuments;
bytes32[] public documentsList; // all
bytes32[] public approvedDocuments; // approved
// Events for listeners
event LogProposedDocument(address proposer, bytes32 docHash);
event LogApprovedDocument(address approver, bytes32 docHash);
// constructor borrower and lender
function Agreement(address borrowerAddress, address lenderAddress) public {
borrower = borrowerAddress;
lender = lenderAddress;
}
function getDocumentsCount() public constant returns (uint documentsCount) {
return documentsList.length;
}
function getApprovedDocumentsCount() public constant returns (uint approvedDocumentsCount) {
return approvedDocuments.length;
}
function agreeDocument(bytes32 documentHash) public returns (bool success) {
require(msg.sender != borrower && msg.sender != lender);
if (msg.sender == borrower) agreementDocuments[documentHash].approvedByBorrower = true;
if (msg.sender == lender) agreementDocuments[documentHash].approvedByLender = true;
if (
agreementDocuments[documentHash].approvedByBorrower == true &&
agreementDocuments[documentHash].approvedByLender == true) {
approvedDocuments.push(documentHash);
LogApprovedDocument(msg.sender, documentHash);
} else {
documentsList.push(documentHash);
LogProposedDocument(msg.sender, documentHash);
}
return true;
}
}