Skip to content

Commit a610670

Browse files
authored
Update Attestation.sol
1 parent 3b0b407 commit a610670

File tree

1 file changed

+77
-89
lines changed

1 file changed

+77
-89
lines changed

contracts/Attestation.sol

Lines changed: 77 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,110 +1,98 @@
1-
pragma solidity ^0.4.19;
1+
pragma solidity 0.4.19;
22

3+
contract Attestation {
34

4-
/**
5-
* @title Ownable
6-
* @dev The Ownable contract has an owner address, and provides basic authorization control
7-
* functions, this simplifies the implementation of “user permissions”.
8-
*/
5+
enum Direction {Forwards, Backwards}
96

10-
contract Ownable {
11-
address public owner;
12-
13-
14-
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
7+
struct UserDetails {
8+
bool active;
9+
bytes32 data;
10+
mapping (address => mapping (bytes32 => Connection)) connections;
11+
}
1512

16-
/**
17-
* @dev The Ownable constructor sets the original `owner` of the contract to the sender
18-
* account.
19-
*/
20-
function Ownable() {
21-
owner = msg.sender;
22-
}
13+
struct CompanyDetails {
14+
bool active;
15+
address owner;
16+
bytes32 data;
17+
}
2318

19+
struct Connection {
20+
bool active;
21+
bytes32 data;
22+
Direction direction;
23+
}
2424

25-
/**
26-
* @dev Throws if called by any account other than the owner.
27-
*/
28-
modifier onlyOwner() {
29-
require(msg.sender == owner);
30-
_;
31-
}
25+
mapping (address => UserDetails) public Users;
26+
mapping (address => CompanyDetails) public Company;
3227

28+
mapping (address => mapping(address => uint)) CompanyUsers;
3329

34-
/**
35-
* @dev Allows the current owner to transfer control of the contract to a newOwner.
36-
* @param newOwner The address to transfer ownership to.
37-
*/
38-
function transferOwnership(address newOwner) onlyOwner public {
39-
require(newOwner != address(0));
40-
OwnershipTransferred(owner, newOwner);
41-
owner = newOwner;
42-
}
30+
modifier onlyCompanyOwner(address _company_address) {
31+
require(CompanyUsers[_company_address][msg.sender] == 1);
32+
_;
33+
}
4334

44-
}
35+
modifier onlyCompanyUser(address _company_address) {
36+
require(CompanyUsers[_company_address][msg.sender] != 0);
37+
_;
38+
}
4539

46-
/**
47-
* @title Pausable
48-
* @dev Base contract which allows children to implement an emergency stop mechanism.
49-
*/
50-
51-
contract Pausable is Ownable {
52-
event Pause();
53-
event Unpause();
54-
55-
bool public paused = false;
56-
57-
58-
/**
59-
* @dev Modifier to make a function callable only when the contract is not paused.
60-
*/
61-
modifier whenNotPaused() {
62-
require(!paused);
63-
_;
64-
}
65-
66-
/**
67-
* @dev Modifier to make a function callable only when the contract is paused.
68-
*/
69-
modifier whenPaused() {
70-
require(paused);
71-
_;
72-
}
73-
74-
/**
75-
* @dev called by the owner to pause, triggers stopped state
76-
*/
77-
function pause() onlyOwner whenNotPaused public {
78-
paused = true;
79-
Pause();
80-
}
81-
82-
/**
83-
* @dev called by the owner to unpause, returns to normal state
84-
*/
85-
function unpause() onlyOwner whenPaused public {
86-
paused = false;
87-
Unpause();
88-
}
89-
}
40+
modifier companyExist(address _company_address) {
41+
require(!Company[_company_address].active);
42+
_;
43+
}
9044

91-
contract Attestation is Ownable,Pausable {
45+
function createUser(address _user_address,bytes32 _data) {
46+
require(!Users[_user_address].active);
47+
UserDetails storage userDetails = Users[_user_address];
48+
userDetails.active = true;
49+
userDetails.data = _data;
50+
}
9251

93-
event Attest(address indexed _from, string indexed _type);
52+
function createCompany(bytes32 _data,address _company_address) {
53+
require(!Company[_company_address].active);
54+
/* create company */
55+
CompanyDetails storage companyDetails = Company[_company_address];
56+
companyDetails.active = true;
57+
companyDetails.owner = msg.sender;
58+
companyDetails.data = _data;
59+
/* setting owner */
60+
CompanyUsers[_company_address][msg.sender] = 1;
61+
}
9462

95-
function Attestation(){
63+
function attestByUser(address _company_address, bytes32 _connection_type, Direction _direction) companyExist(_company_address){
64+
if(!Users[msg.sender].active)
65+
{
66+
createUser(msg.sender,bytes32(0));
67+
}
68+
createConnection(msg.sender,_company_address,_connection_type,_direction);
69+
}
9670

71+
function attestByCompany(address _user_address,address _company_address, bytes32 _connection_type, Direction _direction) companyExist(_company_address) onlyCompanyUser(_company_address) {
72+
if(!Users[_user_address].active)
73+
{
74+
createUser(_user_address,bytes32(0));
75+
}
76+
createConnection(_user_address,_company_address,_connection_type,_direction);
9777
}
9878

99-
function save(string _event_type,string _data) whenNotPaused {
100-
Attest(msg.sender,_event_type);
79+
function createConnection(address _user_address,address _company_address,bytes32 _connection_type, Direction _direction)
80+
{
81+
UserDetails storage userDetails = Users[_user_address];
82+
assert(!userDetails.connections[_company_address][_connection_type].active);
83+
Connection storage connection = userDetails.connections[_company_address][_connection_type];
84+
connection.active = true;
85+
connection.direction = _direction;
10186
}
10287

103-
/*
104-
function to kill contract
105-
*/
88+
function changeCompanyOwner(address _company_address,address _new_owner_address) companyExist(_company_address) onlyCompanyOwner(_company_address) {
89+
Company[_company_address].owner = _new_owner_address;
90+
delete CompanyUsers[_company_address][msg.sender];
91+
CompanyUsers[_company_address][_new_owner_address] = 1;
92+
}
10693

107-
function kill() onlyOwner {
108-
selfdestruct(owner);
94+
function addCompanyUser(address _company_address,address _address) companyExist(_company_address) onlyCompanyOwner(_company_address) {
95+
CompanyUsers[_company_address][_address] = 2;
10996
}
97+
11098
}

0 commit comments

Comments
 (0)