-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontract.txt
75 lines (60 loc) · 3.04 KB
/
contract.txt
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
pragma solidity 0.5.16;
contract SupplyChain {
struct Partner {
string name;
bool committed;
bool riskFound;
bool commitmentChanged;
bool newsUpdated;
bool hasBackupPlan;
uint8 score;
bool assigned;
}
mapping(address => Partner) public partners;
address[] public rankingPartners;
event CommitmentStatusRecorded(address indexed partnerAddress, bool committed);
event RiskFoundStatusRecorded(address indexed partnerAddress, bool riskFound);
event CommitmentChangedStatusRecorded(address indexed partnerAddress, bool commitmentChanged);
event UpdatedNewsRecorded(address indexed partnerAddress, bool newsUpdated);
event BackupPlanRecorded(address indexed partnerAddress, bool hasBackupPlan);
// Assigns a ranking partner to answer the survey
function assignRankingPartner(address partnerAddress) public {
require(!partners[partnerAddress].assigned, "Partner is already assigned");
partners[partnerAddress].assigned = true;
rankingPartners.push(partnerAddress);
}
// Records the ranking partner's answer for the CommitmentStatus
function recordCommitmentStatus(address partnerAddress, bool committed) public {
require(partners[partnerAddress].assigned, "Partner is not assigned");
partners[partnerAddress].committed = committed;
emit CommitmentStatusRecorded(partnerAddress, committed);
}
// Records the ranking partner's answer for the RiskFoundStatus
function recordRiskFoundStatus(address partnerAddress, bool riskFound) public {
require(partners[partnerAddress].assigned, "Partner is not assigned");
partners[partnerAddress].riskFound = riskFound;
emit RiskFoundStatusRecorded(partnerAddress, riskFound);
}
// Records the ranking partner's answer for the CommitmentChangedStatus
function recordCommitmentChangedStatus(address partnerAddress, bool commitmentChanged) public {
require(partners[partnerAddress].assigned, "Partner is not assigned");
partners[partnerAddress].commitmentChanged = commitmentChanged;
emit CommitmentChangedStatusRecorded(partnerAddress, commitmentChanged);
}
// Records the ranking partner's answer for the UpdatedNews
function recordUpdatedNews(address partnerAddress, bool newsUpdated) public {
require(partners[partnerAddress].assigned, "Partner is not assigned");
partners[partnerAddress].newsUpdated = newsUpdated;
emit UpdatedNewsRecorded(partnerAddress, newsUpdated);
}
// Records the ranking partner's answer for the BackupPlan
function recordBackupPlan(address partnerAddress, bool hasBackupPlan) public {
require(partners[partnerAddress].assigned, "Partner is not assigned");
partners[partnerAddress].hasBackupPlan = hasBackupPlan;
emit BackupPlanRecorded(partnerAddress, hasBackupPlan);
}
// Retrieves the ranking partners
function getRankingPartners() public view returns (address[] memory) {
return rankingPartners;
}
}