Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add: transfer tokens to country address depending on NDC reporting #23

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ certs/server.key
index.html
sprojects/ecdsa/ecdsa
sprojects/ot/ot
.idea
9 changes: 9 additions & 0 deletions blockchain/contracts/access/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
sections:
- title: Library
contracts:
- Roles
- subdirectory: roles
---

> This page is incomplete. We're working to improve it for the next release. Stay tuned!
36 changes: 36 additions & 0 deletions blockchain/contracts/access/Roles.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
pragma solidity ^0.5.0;

/**
* @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(!has(role, account), "Roles: account already has role");
role.bearer[account] = true;
}

/**
* @dev Remove an account's access to this role.
*/
function remove(Role storage role, address account) internal {
require(has(role, account), "Roles: account does not have 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), "Roles: account is the zero address");
return role.bearer[account];
}
}
43 changes: 43 additions & 0 deletions blockchain/contracts/access/roles/CapperRole.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
pragma solidity ^0.5.0;

import "../Roles.sol";

contract CapperRole {
using Roles for Roles.Role;

event CapperAdded(address indexed account);
event CapperRemoved(address indexed account);

Roles.Role private _cappers;

constructor () internal {
_addCapper(msg.sender);
}

modifier onlyCapper() {
require(isCapper(msg.sender), "CapperRole: caller does not have the Capper role");
_;
}

function isCapper(address account) public view returns (bool) {
return _cappers.has(account);
}

function addCapper(address account) public onlyCapper {
_addCapper(account);
}

function renounceCapper() public {
_removeCapper(msg.sender);
}

function _addCapper(address account) internal {
_cappers.add(account);
emit CapperAdded(account);
}

function _removeCapper(address account) internal {
_cappers.remove(account);
emit CapperRemoved(account);
}
}
43 changes: 43 additions & 0 deletions blockchain/contracts/access/roles/MinterRole.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
pragma solidity ^0.5.0;

import "../Roles.sol";

contract MinterRole {
using Roles for Roles.Role;

event MinterAdded(address indexed account);
event MinterRemoved(address indexed account);

Roles.Role private _minters;

constructor () internal {
_addMinter(msg.sender);
}

modifier onlyMinter() {
require(isMinter(msg.sender), "MinterRole: caller does not have the Minter role");
_;
}

function isMinter(address account) public view returns (bool) {
return _minters.has(account);
}

function addMinter(address account) public onlyMinter {
_addMinter(account);
}

function renounceMinter() public {
_removeMinter(msg.sender);
}

function _addMinter(address account) internal {
_minters.add(account);
emit MinterAdded(account);
}

function _removeMinter(address account) internal {
_minters.remove(account);
emit MinterRemoved(account);
}
}
43 changes: 43 additions & 0 deletions blockchain/contracts/access/roles/PauserRole.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
pragma solidity ^0.5.0;

import "../Roles.sol";

contract PauserRole {
using Roles for Roles.Role;

event PauserAdded(address indexed account);
event PauserRemoved(address indexed account);

Roles.Role private _pausers;

constructor () internal {
_addPauser(msg.sender);
}

modifier onlyPauser() {
require(isPauser(msg.sender), "PauserRole: caller does not have the Pauser role");
_;
}

function isPauser(address account) public view returns (bool) {
return _pausers.has(account);
}

function addPauser(address account) public onlyPauser {
_addPauser(account);
}

function renouncePauser() public {
_removePauser(msg.sender);
}

function _addPauser(address account) internal {
_pausers.add(account);
emit PauserAdded(account);
}

function _removePauser(address account) internal {
_pausers.remove(account);
emit PauserRemoved(account);
}
}
43 changes: 43 additions & 0 deletions blockchain/contracts/access/roles/SignerRole.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
pragma solidity ^0.5.0;

import "../Roles.sol";

contract SignerRole {
using Roles for Roles.Role;

event SignerAdded(address indexed account);
event SignerRemoved(address indexed account);

Roles.Role private _signers;

constructor () internal {
_addSigner(msg.sender);
}

modifier onlySigner() {
require(isSigner(msg.sender), "SignerRole: caller does not have the Signer role");
_;
}

function isSigner(address account) public view returns (bool) {
return _signers.has(account);
}

function addSigner(address account) public onlySigner {
_addSigner(account);
}

function renounceSigner() public {
_removeSigner(msg.sender);
}

function _addSigner(address account) internal {
_signers.add(account);
emit SignerAdded(account);
}

function _removeSigner(address account) internal {
_signers.remove(account);
emit SignerRemoved(account);
}
}
47 changes: 47 additions & 0 deletions blockchain/contracts/access/roles/WhitelistAdminRole.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
pragma solidity ^0.5.0;

import "../Roles.sol";

/**
* @title WhitelistAdminRole
* @dev WhitelistAdmins are responsible for assigning and removing Whitelisted accounts.
*/
contract WhitelistAdminRole {
using Roles for Roles.Role;

event WhitelistAdminAdded(address indexed account);
event WhitelistAdminRemoved(address indexed account);

Roles.Role private _whitelistAdmins;

constructor () internal {
_addWhitelistAdmin(msg.sender);
}

modifier onlyWhitelistAdmin() {
require(isWhitelistAdmin(msg.sender), "WhitelistAdminRole: caller does not have the WhitelistAdmin role");
_;
}

function isWhitelistAdmin(address account) public view returns (bool) {
return _whitelistAdmins.has(account);
}

function addWhitelistAdmin(address account) public onlyWhitelistAdmin {
_addWhitelistAdmin(account);
}

function renounceWhitelistAdmin() public {
_removeWhitelistAdmin(msg.sender);
}

function _addWhitelistAdmin(address account) internal {
_whitelistAdmins.add(account);
emit WhitelistAdminAdded(account);
}

function _removeWhitelistAdmin(address account) internal {
_whitelistAdmins.remove(account);
emit WhitelistAdminRemoved(account);
}
}
50 changes: 50 additions & 0 deletions blockchain/contracts/access/roles/WhitelistedRole.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
pragma solidity ^0.5.0;

import "../Roles.sol";
import "./WhitelistAdminRole.sol";

/**
* @title WhitelistedRole
* @dev Whitelisted accounts have been approved by a WhitelistAdmin to perform certain actions (e.g. participate in a
* crowdsale). This role is special in that the only accounts that can add it are WhitelistAdmins (who can also remove
* it), and not Whitelisteds themselves.
*/
contract WhitelistedRole is WhitelistAdminRole {
using Roles for Roles.Role;

event WhitelistedAdded(address indexed account);
event WhitelistedRemoved(address indexed account);

Roles.Role private _whitelisteds;

modifier onlyWhitelisted() {
require(isWhitelisted(msg.sender), "WhitelistedRole: caller does not have the Whitelisted role");
_;
}

function isWhitelisted(address account) public view returns (bool) {
return _whitelisteds.has(account);
}

function addWhitelisted(address account) public onlyWhitelistAdmin {
_addWhitelisted(account);
}

function removeWhitelisted(address account) public onlyWhitelistAdmin {
_removeWhitelisted(account);
}

function renounceWhitelisted() public {
_removeWhitelisted(msg.sender);
}

function _addWhitelisted(address account) internal {
_whitelisteds.add(account);
emit WhitelistedAdded(account);
}

function _removeWhitelisted(address account) internal {
_whitelisteds.remove(account);
emit WhitelistedRemoved(account);
}
}