pragma solidity ^0.4.18;
/**
* @title Ownable
* @dev The Ownable contract has an owner address, and provides basic authorization control
* functions, this simplifies the implementation of "user permissions".
*/
contract Ownable {
address public owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev The Ownable constructor sets the original `owner` of the contract to the sender
* account.
*/
function Ownable() public {
owner = msg.sender;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
/**
* @dev Allows the current owner to transfer control of the contract to a newOwner.
* @param newOwner The address to transfer ownership to.
*/
function transferOwnership(address newOwner) public onlyOwner {
require(newOwner != address(0));
OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
}
contract InsightsNetworkContributions is Ownable {
string public name;
uint256 public cap;
uint256 public contributionMinimum;
uint256 public contributionMaximum;
uint256 public gasPriceMaximum;
bool enabled;
uint256 total;
mapping (address => bool) public registered;
mapping (address => uint256) public balances;
event Approval(address indexed account, bool valid);
event Contribution(address indexed contributor, uint256 amount);
event Transfer(address indexed recipient, uint256 amount, address owner);
function InsightsNetworkContributions(string _name, uint256 _cap, uint256 _contributionMinimum, uint256 _contributionMaximum, uint256 _gasPriceMaximum) public {
require(_contributionMinimum <= _contributionMaximum);
require(_contributionMaximum > 0);
require(_contributionMaximum <= _cap);
name = _name;
cap = _cap;
contributionMinimum = _contributionMinimum;
contributionMaximum = _contributionMaximum;
gasPriceMaximum = _gasPriceMaximum;
enabled = false;
}
function () external payable {
contribute();
}
function contribute() public payable {
require(enabled);
require(tx.gasprice <= gasPriceMaximum);
address sender = msg.sender;
require(registered[sender]);
uint256 value = msg.value;
uint256 balance = balances[sender] + value;
require(balance >= contributionMinimum);
require(balance <= contributionMaximum);
require(total + value <= cap);
balances[sender] = balance;
total += value;
Contribution(sender, value);
}
function enable(bool _enabled) public onlyOwner {
enabled = _enabled;
}
function register(address account, bool valid) public onlyOwner {
require(account != 0);
registered[account] = valid;
Approval(account, valid);
}
function registerMultiple(address[] accounts, bool valid) public onlyOwner {
require(accounts.length <= 128);
for (uint index = 0; index < accounts.length; index++) {
address account = accounts[index];
require(account != 0);
registered[account] = valid;
Approval(account, valid);
}
}
function transfer(address recipient, uint256 amount) public onlyOwner {
require(recipient != 0);
require(amount <= this.balance);
Transfer(recipient, amount, owner);
recipient.transfer(amount);
}
function selfDestruct() public onlyOwner {
require(!enabled);
require(this.balance == 0);
selfdestruct(owner);
}
}
{
"compilationTarget": {
"InsightsNetworkContributions.sol": "InsightsNetworkContributions"
},
"libraries": {},
"optimizer": {
"enabled": false,
"runs": 200
},
"remappings": []
}
[{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"balances","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"cap","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_enabled","type":"bool"}],"name":"enable","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"contributionMinimum","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"gasPriceMaximum","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"accounts","type":"address[]"},{"name":"valid","type":"bool"}],"name":"registerMultiple","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"selfDestruct","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"recipient","type":"address"},{"name":"amount","type":"uint256"}],"name":"transfer","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"account","type":"address"},{"name":"valid","type":"bool"}],"name":"register","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"registered","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"contributionMaximum","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"contribute","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},{"constant":false,"inputs":[{"name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"inputs":[{"name":"_name","type":"string"},{"name":"_cap","type":"uint256"},{"name":"_contributionMinimum","type":"uint256"},{"name":"_contributionMaximum","type":"uint256"},{"name":"_gasPriceMaximum","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"payable":true,"stateMutability":"payable","type":"fallback"},{"anonymous":false,"inputs":[{"indexed":true,"name":"account","type":"address"},{"indexed":false,"name":"valid","type":"bool"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"contributor","type":"address"},{"indexed":false,"name":"amount","type":"uint256"}],"name":"Contribution","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"recipient","type":"address"},{"indexed":false,"name":"amount","type":"uint256"},{"indexed":false,"name":"owner","type":"address"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"previousOwner","type":"address"},{"indexed":true,"name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"}]