-
Notifications
You must be signed in to change notification settings - Fork 3
/
Survey.sol
52 lines (41 loc) · 1.67 KB
/
Survey.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
pragma solidity ^0.4.17;
/*
SurveyFactory serves as a hub (deployed on the blockchain upon the launching of bEquality)
Company can create their own survey by providing a list of permitted user address.
*/
contract SurveyFactory {
//address owner;
mapping(uint => address) public SurveyContracts;
// function SurveyFactory(address adr) public {
// owner = adr;
//}
function createNewSurvey(uint companyID, address[] addressessOfEmployees, string _hashToaddressessOfEmployees) public returns(address newContract) {
// require(msg.sender == owner);
require(SurveyContracts[companyID] == 0x0);
Survey c = new Survey(addressessOfEmployees, _hashToaddressessOfEmployees);
SurveyContracts[companyID] = c;
return c;
}
function getContractAddress(uint companyID) public constant returns (address) {
return SurveyContracts[companyID];
}
}
/*
Survey is the child contract created by the SurveyFactory where only the permitted user can modify.
*/
contract Survey {
mapping (address => string) public hashes;
mapping (address => bool) public isAllowedToSumbitSurvey;
string hashToaddressessOfEmployees;
function Survey(address[] addressessOfEmployees, string _hashToaddressessOfEmployees) public {
hashToaddressessOfEmployees = _hashToaddressessOfEmployees;
for (uint256 index = 0; index < addressessOfEmployees.length; index++) {
isAllowedToSumbitSurvey[addressessOfEmployees[index]] = true;
}
}
function submitResults(string myHash) public {
require(bytes(hashes[msg.sender]).length == 0);
require(isAllowedToSumbitSurvey[msg.sender]);
hashes[msg.sender] = myHash;
}
}