-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAgreement.sol
99 lines (82 loc) · 3.68 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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract Agreement {
enum AgreementStatus { Created, Signed, Disputed }
struct AgreementDetails {
address[] actors;
uint256 creationTimestamp;
uint256 expirationTimestamp;
AgreementStatus status;
}
mapping(uint256 => AgreementDetails) public agreements;
mapping(address => uint256[]) public actorToAgreements; // Actor Address -> List of Agreement IDs
mapping(uint256 => mapping(address => string)) public signatures; // Agreement ID -> Actor Address -> Signature Location
uint256 public agreementCount = 0;
event AgreementCreated(uint256 agreementId, address[] actors);
event AgreementSigned(uint256 agreementId, address actor, string signatureLink);
event AgreementDisputed(uint256 agreementId, address actor);
event ActorAdded(uint256 agreementId, address actor);
function createAgreement(address _actor, uint256 _expirationTimestamp) public {
address[] memory actors = new address[](2);
actors[0] = _actor;
actors[1] = msg.sender;
AgreementDetails memory newAgreement = AgreementDetails({
actors: actors,
creationTimestamp: block.timestamp,
expirationTimestamp: _expirationTimestamp,
status: AgreementStatus.Created
});
agreements[agreementCount] = newAgreement;
actorToAgreements[_actor].push(agreementCount);
actorToAgreements[msg.sender].push(agreementCount);
emit AgreementCreated(agreementCount, actors);
agreementCount++;
}
function signAgreement(uint256 _agreementId, string memory _signatureLink) public {
require(_agreementId < agreementCount, "Invalid agreement ID");
AgreementDetails storage agreement = agreements[_agreementId];
bool isActor = false;
for (uint256 i = 0; i < agreement.actors.length; i++) {
if (agreement.actors[i] == msg.sender) {
isActor = true;
break;
}
}
require(isActor, "Only actors can sign the agreement");
signatures[_agreementId][msg.sender] = _signatureLink;
agreement.status = AgreementStatus.Signed;
emit AgreementSigned(_agreementId, msg.sender, _signatureLink);
}
function disputeAgreement(uint256 _agreementId) public {
require(_agreementId < agreementCount, "Invalid agreement ID");
AgreementDetails storage agreement = agreements[_agreementId];
bool isActor = false;
for (uint256 i = 0; i < agreement.actors.length; i++) {
if (agreement.actors[i] == msg.sender) {
isActor = true;
break;
}
}
require(isActor, "Only actors can dispute the agreement");
agreement.status = AgreementStatus.Disputed;
emit AgreementDisputed(_agreementId, msg.sender);
}
function addActor(uint256 _agreementId, address _actor) public {
require(_agreementId < agreementCount, "Invalid agreement ID");
AgreementDetails storage agreement = agreements[_agreementId];
bool isExistingActor = false;
for (uint256 i = 0; i < agreement.actors.length; i++) {
if (agreement.actors[i] == msg.sender) {
isExistingActor = true;
break;
}
}
require(isExistingActor, "Only existing actors can add new actors");
agreement.actors.push(_actor);
actorToAgreements[_actor].push(_agreementId);
emit ActorAdded(_agreementId, _actor);
}
function getAgreementsForActor(address _actor) public view returns (uint256[] memory) {
return actorToAgreements[_actor];
}
}