-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 32ae86e
Showing
20 changed files
with
10,797 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Auto detect text files and perform LF normalization | ||
* text=auto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/node_modules/* | ||
.DS_Store | ||
package-lock.json | ||
/contracts/build/* | ||
/contracts/.env | ||
.vscode | ||
/build/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
pragma solidity ^0.4.24; | ||
|
||
contract Main { | ||
|
||
constructor () internal {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
pragma solidity ^0.4.23; | ||
|
||
contract Migrations { | ||
address public owner; | ||
uint public last_completed_migration; | ||
|
||
constructor() public { | ||
owner = msg.sender; | ||
} | ||
|
||
modifier restricted() { | ||
if (msg.sender == owner) _; | ||
} | ||
|
||
function setCompleted(uint completed) public restricted { | ||
last_completed_migration = completed; | ||
} | ||
|
||
function upgrade(address new_address) public restricted { | ||
Migrations upgraded = Migrations(new_address); | ||
upgraded.setCompleted(last_completed_migration); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
pragma solidity ^0.4.24; | ||
|
||
// Import the library 'Roles' | ||
import "./Roles.sol"; | ||
|
||
// Define a contract 'ConsumerRole' to manage this role - add, remove, check | ||
contract ConsumerRole { | ||
using Roles for Roles.Role; | ||
|
||
// Define 2 events, one for Adding, and other for Removing | ||
event ConsumerAdded(address indexed account); | ||
event ConsumerRemoved(address indexed account); | ||
|
||
// Define a struct 'consumers' by inheriting from 'Roles' library, struct Role | ||
Roles.Role private consumers; | ||
|
||
// In the constructor make the address that deploys this contract the 1st consumer | ||
constructor() public { | ||
_addConsumer(msg.sender); | ||
} | ||
|
||
// Define a modifier that checks to see if msg.sender has the appropriate role | ||
modifier onlyConsumer() { | ||
require(isConsumer(msg.sender), "sender is not a cosnumer"); | ||
_; | ||
} | ||
|
||
// Define a function 'isConsumer' to check this role | ||
function isConsumer(address account) public view returns (bool) { | ||
return consumers.has(account); | ||
} | ||
|
||
// Define a function 'addConsumer' that adds this role | ||
function addConsumer(address account) public onlyConsumer { | ||
_addConsumer(account); | ||
} | ||
|
||
// Define a function 'renounceConsumer' to renounce this role | ||
function renounceConsumer() public { | ||
_removeConsumer(msg.sender); | ||
} | ||
|
||
// Define an internal function '_addConsumer' to add this role, called by 'addConsumer' | ||
function _addConsumer(address account) internal { | ||
consumers.add(account); | ||
emit ConsumerAdded(account); | ||
} | ||
|
||
// Define an internal function '_removeConsumer' to remove this role, called by 'removeConsumer' | ||
function _removeConsumer(address account) internal { | ||
consumers.remove(account); | ||
emit ConsumerRemoved(account); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
pragma solidity ^0.4.24; | ||
|
||
// Import the library 'Roles' | ||
import "./Roles.sol"; | ||
|
||
// Define a contract 'DistributorRole' to manage this role - add, remove, check | ||
contract DistributorRole { | ||
using Roles for Roles.Role; | ||
|
||
// Define 2 events, one for Adding, and other for Removing | ||
event DistributorAdded(address indexed account); | ||
event DistributorRemoved(address indexed account); | ||
|
||
// Define a struct 'distributors' by inheriting from 'Roles' library, struct Role | ||
Roles.Role private distributors; | ||
|
||
// In the constructor make the address that deploys this contract the 1st distributor | ||
constructor() public { | ||
_addDistributor(msg.sender); | ||
} | ||
|
||
// Define a modifier that checks to see if msg.sender has the appropriate role | ||
modifier onlyDistributor() { | ||
require(isDistributor(msg.sender), "sender is not a distibutor"); | ||
_; | ||
} | ||
|
||
// Define a function 'isDistributor' to check this role | ||
function isDistributor(address account) public view returns (bool) { | ||
return distributors.has(account); | ||
} | ||
|
||
// Define a function 'addDistributor' that adds this role | ||
function addDistributor(address account) public onlyDistributor { | ||
_addDistributor(account); | ||
} | ||
|
||
// Define a function 'renounceDistributor' to renounce this role | ||
function renounceDistributor() public { | ||
_removeDistributor(msg.sender); | ||
} | ||
|
||
// Define an internal function '_addDistributor' to add this role, called by 'addDistributor' | ||
function _addDistributor(address account) internal { | ||
distributors.add(account); | ||
emit DistributorAdded(account); | ||
} | ||
|
||
// Define an internal function '_removeDistributor' to remove this role, called by 'removeDistributor' | ||
function _removeDistributor(address account) internal { | ||
distributors.remove(account); | ||
emit DistributorRemoved(account);(account); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
contracts/pharmaceuticalaccesscontrol/ManufacturerRole.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
pragma solidity ^0.4.24; | ||
|
||
// Import the library 'Roles' | ||
import "./Roles.sol"; | ||
|
||
// Define a contract 'ManufacturerRole' to manage this role - add, remove, check | ||
contract ManufacturerRole { | ||
using Roles for Roles.Role; | ||
|
||
// Define 2 events, one for Adding, and other for Removing | ||
event ManufacturerAdded(address indexed account); | ||
event ManufacturerRemoved(address indexed account); | ||
|
||
// Define a struct 'manufacturers' by inheriting from 'Roles' library, struct Role | ||
Roles.Role private manufacturers; | ||
|
||
// In the constructor make the address that deploys this contract the 1st manufacturer | ||
constructor() public { | ||
_addManufacturer(msg.sender); | ||
} | ||
|
||
// Define a modifier that checks to see if msg.sender has the appropriate role | ||
modifier onlyManufacturer() { | ||
require(isManufacturer(msg.sender), "sender is not a manufacturer"); | ||
_; | ||
} | ||
|
||
// Define a function 'isManufacturer' to check this role | ||
function isManufacturer(address account) public view returns (bool) { | ||
return manufacturers.has(account); | ||
} | ||
|
||
// Define a function 'addManufacturer' that adds this role | ||
function addManufacturer(address account) public onlyManufacturer { | ||
_addManufacturer(account); | ||
} | ||
|
||
// Define a function 'renounceManufacturer' to renounce this role | ||
function renounceManufacturer() public { | ||
_removeManufacturer(msg.sender); | ||
} | ||
|
||
// Define an internal function '_addManufacturer' to add this role, called by 'addManufacturer' | ||
function _addManufacturer(address account) internal { | ||
manufacturers.add(account); | ||
emit ManufacturerAdded(account); | ||
} | ||
|
||
// Define an internal function '_removeManufacturer' to remove this role, called by 'removeManufacturer' | ||
function _removeManufacturer(address account) internal { | ||
manufacturers.remove(account); | ||
emit ManufacturerRemoved(account); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
pragma solidity ^0.4.24; | ||
|
||
// Import the library 'Roles' | ||
import "./Roles.sol"; | ||
|
||
// Define a contract 'RetailerRole' to manage this role - add, remove, check | ||
contract RetailerRole { | ||
using Roles for Roles.Role; | ||
|
||
// Define 2 events, one for Adding, and other for Removing | ||
event RetailerAdded(address indexed account); | ||
event RetailerRemoved(address indexed account); | ||
|
||
// Define a struct 'retailers' by inheriting from 'Roles' library, struct Role | ||
Roles.Role private retailers; | ||
|
||
// In the constructor make the address that deploys this contract the 1st retailer | ||
constructor() public { | ||
_addRetailer(msg.sender); | ||
} | ||
|
||
// Define a modifier that checks to see if msg.sender has the appropriate role | ||
modifier onlyRetailer() { | ||
require(isRetailer(msg.sender), "sender is not a manufacturer"); | ||
_; | ||
} | ||
|
||
// Define a function 'isRetailer' to check this role | ||
function isRetailer(address account) public view returns (bool) { | ||
return retailers.has(account); | ||
} | ||
|
||
// Define a function 'addRetailer' that adds this role | ||
function addRetailer(address account) public onlyRetailer { | ||
_addRetailer(account); | ||
} | ||
|
||
// Define a function 'renounceRetailer' to renounce this role | ||
function renounceRetailer() public { | ||
_removeRetailer(msg.sender); | ||
} | ||
|
||
// Define an internal function '_addRetailer' to add this role, called by 'addRetailer' | ||
function _addRetailer(address account) internal { | ||
retailers.add(account); | ||
emit RetailerAdded(account); | ||
} | ||
|
||
// Define an internal function '_removeRetailer' to remove this role, called by 'removeRetailer' | ||
function _removeRetailer(address account) internal { | ||
retailers.remove(account); | ||
emit RetailerRemoved(account); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
pragma solidity ^0.4.24; | ||
|
||
/** | ||
* @title Roles | ||
* @dev Library for managing addresses assigned to a Role. | ||
*/ | ||
library Roles { | ||
struct Role { | ||
mapping (address => bool) bearer; | ||
} | ||
|
||
/** | ||
* @dev give an account access to this role | ||
*/ | ||
function add(Role storage role, address account) internal { | ||
require(account != address(0), "the account cannot be zero"); | ||
require(!has(role, account), "the account already has the given role"); | ||
|
||
role.bearer[account] = true; | ||
} | ||
|
||
/** | ||
* @dev remove an account's access to this role | ||
*/ | ||
function remove(Role storage role, address account) internal { | ||
require(account != address(0), "the account cannot be zero"); | ||
require(has(role, account), "the account does not have the given role"); | ||
|
||
role.bearer[account] = false; | ||
} | ||
|
||
/** | ||
* @dev check if an account has this role | ||
* @return bool | ||
*/ | ||
function has(Role storage role, address account) | ||
internal | ||
view | ||
returns (bool) | ||
{ | ||
require(account != address(0), "the account cannot be zero"); | ||
return role.bearer[account]; | ||
} | ||
} |
Oops, something went wrong.