-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMedicineRequest.sol
More file actions
99 lines (72 loc) · 2.24 KB
/
MedicineRequest.sol
File metadata and controls
99 lines (72 loc) · 2.24 KB
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
pragma solidity ^0.4.23;
import './Request.sol';
contract MedicineRequest is Request{
string medicineId;
string name;
string description;
uint value;
uint validity;
address[] approvers;
uint approveCounts;
event ApprovedBy(address approver);
event Approved(string medicineId);
event NewApprover(address newApprover);
modifier notApproved{
require(!approved, "This has already been approved");
_;
}
modifier hasntVoted{
require(!voted[msg.sender], "has already voted");
_;
}
modifier onlyAprover{
bool isAprover = false;
for(uint i = 0; i < approvers.length; i++){
if(approvers[i] == msg.sender){
isAprover = true;
}
}
require(isAprover);
_;
}
constructor(uint _id, string _medicineId, string _name, string _description, uint _value, uint _validity, address[] _approvers)public{
id = _id;
medicineId = _medicineId;
name = _name;
description = _description;
value = _value;
validity = _validity;
approvers = _approvers;
approveCounts = 0;
approved = false;
}
function getMedicineName()public view returns(string){
return name;
}
function getMedicineDescription()public view returns(string){
return description;
}
function getMedicineValue()public view returns(uint){
return value;
}
function getMedicineValidity()public view returns(uint){
return validity;
}
function getMedicineId()public view returns(string){
return medicineId;
}
function approve()public hasntVoted notApproved onlyAprover returns(bool){
approveCounts += 1;
voted[msg.sender] = true;
emit ApprovedBy(msg.sender);
if(approveCounts >= approvers.length / 2){
approved = true;
emit Approved(medicineId);
}
return approved;
}
function updateApprovers(address newApprover)public{
approvers.push(newApprover);
emit NewApprover(newApprover);
}
}