Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
brandon-zimmerman committed Jul 28, 2019
0 parents commit 32ae86e
Show file tree
Hide file tree
Showing 20 changed files with 10,797 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
7 changes: 7 additions & 0 deletions .gitignore
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/*
6 changes: 6 additions & 0 deletions contracts/Main.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pragma solidity ^0.4.24;

contract Main {

constructor () internal {}
}
23 changes: 23 additions & 0 deletions contracts/Migrations.sol
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);
}
}
54 changes: 54 additions & 0 deletions contracts/pharmaceuticalaccesscontrol/ConsumerRole.sol
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);
}
}
54 changes: 54 additions & 0 deletions contracts/pharmaceuticalaccesscontrol/DistributorRole.sol
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 contracts/pharmaceuticalaccesscontrol/ManufacturerRole.sol
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);
}
}
54 changes: 54 additions & 0 deletions contracts/pharmaceuticalaccesscontrol/RetailerRole.sol
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);
}
}
44 changes: 44 additions & 0 deletions contracts/pharmaceuticalaccesscontrol/Roles.sol
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];
}
}
Loading

0 comments on commit 32ae86e

Please sign in to comment.