Skip to content

Instantly share code, notes, and snippets.

@computerphysicslab
Last active September 1, 2017 13:32
Show Gist options
  • Save computerphysicslab/5ef16811325fd74fc482bc556b3b9d86 to your computer and use it in GitHub Desktop.
Save computerphysicslab/5ef16811325fd74fc482bc556b3b9d86 to your computer and use it in GitHub Desktop.
/*
Watafan issuers Smart Contract v1.0
developed by:
MarketPay.io , 2017
https://marketpay.io/
http://lnked.in/blockchain
v1.0 https://gist.github.com/computerphysicslab/5ef16811325fd74fc482bc556b3b9d86
+ Owner grants new issuers and revokes them too
+ This is a mortal contract
*/
pragma solidity ^0.4.6;
/*
* @title Mortal
*
* Abstract contract that allows children to implement the functionality of killing the contract and other generic functions.
*
*/
contract Mortal {
address owner;
// @notice Constructor sets owner
function Mortal() { owner = msg.sender; }
// @notice For debugging purposes when using solidity online browser
function whoAmI() constant returns (address) {
return msg.sender;
}
// @notice Get the current timestamp from last mined block
function timestamp() constant returns (uint256) {
return block.timestamp;
}
// **** EVENTS
// @notice A generic error log
event Error(string error);
// @notice Triggered when owner kills the contract
event Kill(address killer, uint256 _timestamp);
// **** MORE FUNCTIONS
// @notice To limit functions usage to contract owner
modifier onlyOwner() {
if (msg.sender != owner) {
Error('Mortal: onlyOwner function called by user that is not owner');
} else {
_;
}
}
// @notice To kill the contract
function kill() onlyOwner {
Kill(msg.sender, timestamp());
suicide(owner);
}
}
contract Issuers is Mortal {
// **** DATA
mapping (address => bool) issuers;
// **** METHODS
// Checks whether a given user is an authorized issuer
function isIssuer(address _issuer) constant returns (bool) {
return (issuers[_issuer]);
}
function grantIssuer(address _issuer) external onlyOwner {
issuers[_issuer] = true;
GrantIssuer(_issuer, timestamp()); // Event log
}
function revokeIssuer(address _issuer) external onlyOwner {
issuers[_issuer] = false;
RevokeIssuer(_issuer, timestamp()); // Event log
}
// **** EVENTS
// Triggered when a user is granted to become an issuer
event GrantIssuer(address who, uint256 _timestamp);
// Triggered when a user is revoked for being an issuer
event RevokeIssuer(address who, uint256 _timestamp);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment