Skip to content

Instantly share code, notes, and snippets.

@jorpic
Last active July 9, 2017 02:08
Show Gist options
  • Save jorpic/4dfb355a85f007a56d12a79763fceab9 to your computer and use it in GitHub Desktop.
Save jorpic/4dfb355a85f007a56d12a79763fceab9 to your computer and use it in GitHub Desktop.
SONM contracts

Check compiler version:

$ solc-0.4.11 --version
solc, the solidity compiler commandline interface
Version: 0.4.11+commit.68ef5810.Linux.g++

Compile from standard JSON (fetch standard-input.json from this gist and feed it to solc):

$ curl -s https://gist.githubusercontent.com/jorpic/4dfb355a85f007a56d12a79763fceab9/raw/7ca8940391e129382a339203c54be0ef05644f3e/standard-input.json | solc-0.4.11 --standard-json > standard-output.json

Get contract bytecode (standard-output.json is huuuge, so I'm using jq tool get only relevant part from it):

$ jq -r '.contracts."/home/user/t/ico-contracts/contracts/SNM.sol".SNM.evm.deployedBytecode.object' standard-output.json
606060405236156100a95763ffffffff60e060020a60003504166306fdde0381146100ab578063095ea7b31461013b57806318160ddd1461015c57806323b872
dd1461017e578063313ce567146101a557806340c10f19146101c75780635d452201146101e857806370a082311461021457806395d89b4114610242578063a9
059cbb146102d2578063ca67065f146102f3578063dd62ed3e14610317578063f21cdf6f1461034b575bfe5b34156100b357fe5b6100bb61035d565b60408051
6020808252835181830152835191928392908301918501908083838215610101575b80518252602083111561010157601f1990920191602091820191016100e1
565b505050905090810190601f16801561012d5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34156101
4357fe5b61015a600160a060020a03600435166024356103eb565b005b341561016457fe5b61016c610412565b60408051918252519081900360200190f35b34
1561018657fe5b61015a600160a060020a0360043581169060243516604435610418565b005b34156101ad57fe5b61016c610441565b60408051918252519081
900360200190f35b34156101cf57fe5b61015a600160a060020a0360043516602435610447565b005b34156101f057fe5b6101f86104db565b60408051600160
a060020a039092168252519081900360200190f35b341561021c57fe5b61016c600160a060020a03600435166104ea565b604080519182525190819003602001
90f35b341561024a57fe5b6100bb610509565b604080516020808252835181830152835191928392908301918501908083838215610101575b80518252602083
111561010157601f1990920191602091820191016100e1565b505050905090810190601f16801561012d5780820380516001836020036101000a031916815260
200191505b509250505060405180910390f35b34156102da57fe5b61015a600160a060020a0360043516602435610597565b005b34156102fb57fe5b61030361
05be565b604080519115158252519081900360200190f35b341561031f57fe5b61016c600160a060020a03600435811690602435166105ce565b604080519182
52519081900360200190f35b341561035357fe5b61015a6105fb565b005b6003805460408051602060026001851615610100026000190190941693909304601f
810184900484028201840190925281815292918301828280156103e35780601f106103b8576101008083540402835291602001916103e3565b82019190600052
6020600020905b8154815290600101906020018083116103c657829003601f168201915b505050505081565b60065460a060020a900460ff1615610403576000
6000fd5b61040d828261062a565b5b5050565b60005481565b60065460a060020a900460ff16156104305760006000fd5b61043b83838361068c565b5b505050
565b60055481565b60065433600160a060020a039081169116146104635760006000fd5b8015156104705760006000fd5b6000546b016f44a83aab6c233c0000
00908201111561048f5760006000fd5b600160a060020a0382166000818152600160209081526040808320805486019055825485018355805185815290516000
80516020610889833981519152929181900390910190a35b5050565b600654600160a060020a031681565b600160a060020a0381166000908152600160205260
409020545b919050565b6004805460408051602060026001851615610100026000190190941693909304601f8101849004840282018401909252818152929183
01828280156103e35780601f106103b8576101008083540402835291602001916103e3565b820191906000526020600020905b81548152906001019060200180
83116103c657829003601f168201915b505050505081565b60065460a060020a900460ff16156105af5760006000fd5b61040d8282610786565b5b5050565b60
065460a060020a900460ff1681565b600160a060020a038083166000908152600260209081526040808320938516835292905220545b92915050565b60065433
600160a060020a039081169116146106175760006000fd5b6006805460a060020a60ff02191690555b565b600160a060020a0333811660008181526002602090
8152604080832094871680845294825291829020859055815185815291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92592
81900390910190a35b5050565b600160a060020a0380841660009081526002602090815260408083203385168452825280832054938616835260019091529020
546106d0908363ffffffff61084216565b600160a060020a038085166000908152600160205260408082209390935590861681522054610705908363ffffffff
61085e16565b600160a060020a03851660009081526001602052604090205561072e818363ffffffff61085e16565b600160a060020a03808616600081815260
026020908152604080832033861684528252918290209490945580518681529051928716939192600080516020610889833981519152929181900390910190a3
5b50505050565b604060443610156107975760006000fd5b600160a060020a0333166000908152600160205260409020546107c0908363ffffffff61085e1656
5b600160a060020a0333811660009081526001602052604080822093909355908516815220546107f5908363ffffffff61084216565b600160a060020a038085
1660008181526001602090815260409182902094909455805186815290519193339093169260008051602061088983398151915292918290030190a35b5b5050
50565b600082820161085384821015610877565b8091505b5092915050565b600061086c83831115610877565b508082035b92915050565b8015156108845760
006000fd5b5b505600ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3efa165627a7a7230582042e76545ee7d511e0aa7fca37631
944e7267b5027e080bb4f9ae0f5efc6b22eb0029
{
"language": "Solidity",
"sources": {
"/home/user/t/ico-contracts/contracts/ICO.sol": {
"content": "\npragma solidity ^0.4.11;\n\nimport \"./PreICO.sol\";\nimport \"./SNM.sol\";\nimport \"./installed/token/ERC20.sol\";\n\n\ncontract ICO {\n\n // Constants\n // =========\n\n uint public constant TOKEN_PRICE = 2824; // SNM per ETH\n uint public constant TOKENS_FOR_SALE = 331360000 * 1e18;\n uint public constant SNM_PER_SPT = 4; // Migration rate\n\n\n // Events\n // ======\n\n event ForeignBuy(address holder, uint snmValue, string txHash);\n event Migrate(address holder, uint snmValue);\n event RunIco();\n event PauseIco();\n event FinishIco(address teamFund, address ecosystemFund, address bountyFund);\n\n\n // State variables\n // ===============\n\n PreICO preICO;\n SNM public snm;\n\n address public team;\n address public tradeRobot;\n modifier teamOnly { require(msg.sender == team); _; }\n modifier robotOnly { require(msg.sender == tradeRobot); _; }\n\n uint tokensSold = 0;\n\n enum IcoState { Created, Running, Paused, Finished }\n IcoState icoState = IcoState.Created;\n\n\n // Constructor\n // ===========\n\n function ICO(address _team, address _preICO, address _tradeRobot) {\n snm = new SNM(this);\n preICO = PreICO(_preICO);\n team = _team;\n tradeRobot = _tradeRobot;\n }\n\n\n\n // Public functions\n // ================\n\n // Here you can buy some tokens (just don't forget to provide enough gas).\n function() external payable {\n buyFor(msg.sender);\n }\n\n\n function buyFor(address _investor) public payable {\n require(icoState == IcoState.Running);\n require(msg.value > 0);\n buy(_investor, msg.value * TOKEN_PRICE);\n }\n\n\n function getBonus(uint _value, uint _sold)\n public constant returns (uint)\n {\n uint[8] memory _bonusPattern = [ 150, 125, 100, 75, 50, 38, 25, uint(13) ];\n uint _step = TOKENS_FOR_SALE / 10;\n uint _bonus = 0;\n\n for(uint8 i = 0; _value > 0 && i < _bonusPattern.length; ++i) {\n uint _min = _step * i;\n uint _max = _step * (i+1);\n\n if(_sold >= _min && _sold < _max) {\n uint _bonusedPart = min(_value, _max - _sold);\n _bonus += _bonusedPart * _bonusPattern[i] / 1000;\n _value -= _bonusedPart;\n _sold += _bonusedPart;\n }\n }\n\n return _bonus;\n }\n\n\n\n // Priveleged functions\n // ====================\n\n\n // This is called by our friendly robot to allow you to buy SNM for various\n // cryptos.\n function foreignBuy(address _investor, uint _snmValue, string _txHash)\n external robotOnly\n {\n require(icoState == IcoState.Running);\n require(_snmValue > 0);\n buy(_investor, _snmValue);\n ForeignBuy(_investor, _snmValue, _txHash);\n }\n\n\n // Team can replace tradeRobot in case of malfunction.\n function setRobot(address _robot) external teamOnly {\n tradeRobot = _robot;\n }\n\n\n // We can force migration for early investors\n function migrateSome(address[] _investors) external robotOnly {\n for(uint i = 0; i < _investors.length; i++)\n doMigration(_investors[i]);\n }\n\n\n // ICO state management: start / pause / finish\n // --------------------------------------------\n\n function startIco() external teamOnly {\n require(icoState == IcoState.Created || icoState == IcoState.Paused);\n icoState = IcoState.Running;\n RunIco();\n }\n\n\n function pauseIco() external teamOnly {\n require(icoState == IcoState.Running);\n icoState = IcoState.Paused;\n PauseIco();\n }\n\n\n function finishIco(\n address _teamFund,\n address _ecosystemFund,\n address _bountyFund\n )\n external teamOnly\n {\n require(icoState == IcoState.Running || icoState == IcoState.Paused);\n\n uint alreadyMinted = snm.totalSupply();\n uint totalAmount = alreadyMinted * 1110 / 889;\n // totalAmount = alreadyMinted + ecosystem + team + bounty;\n\n snm.mint(_teamFund, 10 * totalAmount / 111);\n snm.mint(_ecosystemFund, totalAmount / 10);\n snm.mint(_bountyFund, totalAmount / 111);\n snm.defrost();\n\n icoState = IcoState.Finished;\n FinishIco(_teamFund, _ecosystemFund, _bountyFund);\n }\n\n\n // Withdraw all collected ethers to the team's multisig wallet\n function withdrawEther(uint _value) external teamOnly {\n team.transfer(_value);\n }\n\n function withdrawToken(address _tokenContract, uint _val) external teamOnly\n {\n ERC20 _tok = ERC20(_tokenContract);\n _tok.transfer(team, _val);\n }\n\n\n\n // Private functions\n // =================\n\n function min(uint a, uint b) internal constant returns (uint) {\n return a < b ? a : b;\n }\n\n\n function buy(address _investor, uint _snmValue) internal {\n uint _bonus = getBonus(_snmValue, tokensSold);\n uint _total = _snmValue + _bonus;\n\n require(tokensSold + _total <= TOKENS_FOR_SALE);\n\n snm.mint(_investor, _total);\n tokensSold += _total;\n }\n\n\n function doMigration(address _investor) internal {\n // Migration must be completed before ICO is finished, because\n // total amount of tokens must be known to calculate amounts minted for\n // funds (bounty, team, ecosystem).\n require(icoState != IcoState.Finished);\n\n uint _sptBalance = preICO.balanceOf(_investor);\n require(_sptBalance > 0);\n\n preICO.burnTokens(_investor);\n\n // Mint extra amount of tokens for our generous early investors.\n uint _snmValue = _sptBalance * SNM_PER_SPT;\n snm.mint(_investor, _snmValue);\n\n Migrate(_investor, _snmValue);\n }\n}\n"
},
"/home/user/t/ico-contracts/contracts/PreICO.sol": {
"content": "\npragma solidity ^0.4.11;\n\n\n// This is a part of the PreICO contract interface.\n// https://github.com/sonm-io/presale-token/blob/master/contracts/PresaleToken.sol\n// We specify here only the parts that are relevant to token migration.\n\ncontract PreICO {\n function balanceOf(address _owner) constant returns (uint256);\n function burnTokens(address _owner);\n}\n"
},
"/home/user/t/ico-contracts/contracts/SNM.sol": {
"content": "\npragma solidity ^0.4.11;\n\nimport \"./installed/token/StandardToken.sol\";\n\ncontract SNM is StandardToken {\n\n // Constants\n // =========\n\n string public name = \"SONM Token\";\n string public symbol = \"SNM\";\n uint public decimals = 18;\n uint constant TOKEN_LIMIT = 444 * 1e6 * 1e18;\n\n\n // State variables\n // ===============\n\n address public ico;\n\n // We block token transfers until ICO is finished.\n bool public tokensAreFrozen = true;\n\n\n // Constructor\n // ===========\n\n function SNM(address _ico) {\n ico = _ico;\n }\n\n\n // Priveleged functions\n // ====================\n\n // Mint few tokens and transefer them to some address.\n function mint(address _holder, uint _value) external {\n require(msg.sender == ico);\n require(_value != 0);\n require(totalSupply + _value <= TOKEN_LIMIT);\n\n balances[_holder] += _value;\n totalSupply += _value;\n Transfer(0x0, _holder, _value);\n }\n\n\n // Allow token transfer.\n function defrost() external {\n require(msg.sender == ico);\n tokensAreFrozen = false;\n }\n\n\n // ERC20 functions\n // =========================\n\n function transfer(address _to, uint _value) public {\n require(!tokensAreFrozen);\n super.transfer(_to, _value);\n }\n\n\n function transferFrom(address _from, address _to, uint _value) public {\n require(!tokensAreFrozen);\n super.transferFrom(_from, _to, _value);\n }\n\n\n function approve(address _spender, uint _value) public {\n require(!tokensAreFrozen);\n super.approve(_spender, _value);\n }\n}\n"
},
"/home/user/t/ico-contracts/contracts/installed/token/StandardToken.sol": {
"content": "pragma solidity ^0.4.8;\n\n\nimport './BasicToken.sol';\nimport './ERC20.sol';\n\n\n/**\n * Standard ERC20 token\n *\n * https://github.com/ethereum/EIPs/issues/20\n * Based on code by FirstBlood:\n * https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol\n */\ncontract StandardToken is BasicToken, ERC20 {\n\n mapping (address => mapping (address => uint)) allowed;\n\n function transferFrom(address _from, address _to, uint _value) {\n var _allowance = allowed[_from][msg.sender];\n\n // Check is not needed because sub(_allowance, _value) will already throw if this condition is not met\n // if (_value > _allowance) throw;\n\n balances[_to] = balances[_to].add(_value);\n balances[_from] = balances[_from].sub(_value);\n allowed[_from][msg.sender] = _allowance.sub(_value);\n Transfer(_from, _to, _value);\n }\n\n function approve(address _spender, uint _value) {\n allowed[msg.sender][_spender] = _value;\n Approval(msg.sender, _spender, _value);\n }\n\n function allowance(address _owner, address _spender) constant returns (uint remaining) {\n return allowed[_owner][_spender];\n }\n\n}\n"
},
"/home/user/t/ico-contracts/contracts/installed/token/BasicToken.sol": {
"content": "pragma solidity ^0.4.8;\n\n\nimport './ERC20Basic.sol';\nimport '../SafeMath.sol';\n\n\n/*\n * Basic token\n * Basic version of StandardToken, with no allowances\n */\ncontract BasicToken is ERC20Basic {\n using SafeMath for uint;\n\n mapping(address => uint) balances;\n\n /*\n * Fix for the ERC20 short address attack \n */\n modifier onlyPayloadSize(uint size) {\n if(msg.data.length < size + 4) {\n throw;\n }\n _;\n }\n\n function transfer(address _to, uint _value) onlyPayloadSize(2 * 32) {\n balances[msg.sender] = balances[msg.sender].sub(_value);\n balances[_to] = balances[_to].add(_value);\n Transfer(msg.sender, _to, _value);\n }\n\n function balanceOf(address _owner) constant returns (uint balance) {\n return balances[_owner];\n }\n \n}\n"
},
"/home/user/t/ico-contracts/contracts/installed/SafeMath.sol": {
"content": "pragma solidity ^0.4.8;\n\n\n/**\n * Math operations with safety checks\n */\nlibrary SafeMath {\n function mul(uint a, uint b) internal returns (uint) {\n uint c = a * b;\n assert(a == 0 || c / a == b);\n return c;\n }\n\n function div(uint a, uint b) internal returns (uint) {\n assert(b > 0);\n uint c = a / b;\n assert(a == b * c + a % b);\n return c;\n }\n\n function sub(uint a, uint b) internal returns (uint) {\n assert(b <= a);\n return a - b;\n }\n\n function add(uint a, uint b) internal returns (uint) {\n uint c = a + b;\n assert(c >= a);\n return c;\n }\n\n function max64(uint64 a, uint64 b) internal constant returns (uint64) {\n return a >= b ? a : b;\n }\n\n function min64(uint64 a, uint64 b) internal constant returns (uint64) {\n return a < b ? a : b;\n }\n\n function max256(uint256 a, uint256 b) internal constant returns (uint256) {\n return a >= b ? a : b;\n }\n\n function min256(uint256 a, uint256 b) internal constant returns (uint256) {\n return a < b ? a : b;\n }\n\n function assert(bool assertion) internal {\n if (!assertion) {\n throw;\n }\n }\n}\n"
},
"/home/user/t/ico-contracts/contracts/installed/token/ERC20Basic.sol": {
"content": "pragma solidity ^0.4.8;\n\n\n/*\n * ERC20Basic\n * Simpler version of ERC20 interface\n * see https://github.com/ethereum/EIPs/issues/20\n */\ncontract ERC20Basic {\n uint public totalSupply;\n function balanceOf(address who) constant returns (uint);\n function transfer(address to, uint value);\n event Transfer(address indexed from, address indexed to, uint value);\n}\n"
},
"/home/user/t/ico-contracts/contracts/installed/token/ERC20.sol": {
"content": "pragma solidity ^0.4.8;\n\n\nimport './ERC20Basic.sol';\n\n\n/*\n * ERC20 interface\n * see https://github.com/ethereum/EIPs/issues/20\n */\ncontract ERC20 is ERC20Basic {\n function allowance(address owner, address spender) constant returns (uint);\n function transferFrom(address from, address to, uint value);\n function approve(address spender, uint value);\n event Approval(address indexed owner, address indexed spender, uint value);\n}\n"
},
"/home/user/t/ico-contracts/contracts/Migrations.sol": {
"content": "pragma solidity ^0.4.4;\n\ncontract Migrations {\n address public owner;\n uint public last_completed_migration;\n\n modifier restricted() {\n if (msg.sender == owner) _;\n }\n\n function Migrations() {\n owner = msg.sender;\n }\n\n function setCompleted(uint completed) restricted {\n last_completed_migration = completed;\n }\n\n function upgrade(address new_address) restricted {\n Migrations upgraded = Migrations(new_address);\n upgraded.setCompleted(last_completed_migration);\n }\n}\n"
},
"/home/user/t/ico-contracts/contracts/MockPreICO.sol": {
"content": "pragma solidity ^0.4.11;\n\nimport \"./PreICO.sol\";\n\n\ncontract MockPreICO is PreICO {\n\n mapping (address => uint) balance;\n\n function setBalance(uint _value) {\n balance[msg.sender] = _value;\n }\n\n function balanceOf(address _owner) constant returns (uint256) {\n return balance[_owner];\n }\n\n function burnTokens(address _owner) {\n balance[_owner] = 0;\n }\n}\n"
},
"/home/user/t/ico-contracts/contracts/installed/MultiSigWallet.sol": {
"content": "pragma solidity ^0.4.4;\n\n\n/// @title Multisignature wallet - Allows multiple parties to agree on transactions before execution.\n/// @author Stefan George - <stefan.george@consensys.net>\ncontract MultiSigWallet {\n\n uint constant public MAX_OWNER_COUNT = 50;\n\n event Confirmation(address indexed sender, uint indexed transactionId);\n event Revocation(address indexed sender, uint indexed transactionId);\n event Submission(uint indexed transactionId);\n event Execution(uint indexed transactionId);\n event ExecutionFailure(uint indexed transactionId);\n event Deposit(address indexed sender, uint value);\n event OwnerAddition(address indexed owner);\n event OwnerRemoval(address indexed owner);\n event RequirementChange(uint required);\n\n mapping (uint => Transaction) public transactions;\n mapping (uint => mapping (address => bool)) public confirmations;\n mapping (address => bool) public isOwner;\n address[] public owners;\n uint public required;\n uint public transactionCount;\n\n struct Transaction {\n address destination;\n uint value;\n bytes data;\n bool executed;\n }\n\n modifier onlyWallet() {\n if (msg.sender != address(this))\n throw;\n _;\n }\n\n modifier ownerDoesNotExist(address owner) {\n if (isOwner[owner])\n throw;\n _;\n }\n\n modifier ownerExists(address owner) {\n if (!isOwner[owner])\n throw;\n _;\n }\n\n modifier transactionExists(uint transactionId) {\n if (transactions[transactionId].destination == 0)\n throw;\n _;\n }\n\n modifier confirmed(uint transactionId, address owner) {\n if (!confirmations[transactionId][owner])\n throw;\n _;\n }\n\n modifier notConfirmed(uint transactionId, address owner) {\n if (confirmations[transactionId][owner])\n throw;\n _;\n }\n\n modifier notExecuted(uint transactionId) {\n if (transactions[transactionId].executed)\n throw;\n _;\n }\n\n modifier notNull(address _address) {\n if (_address == 0)\n throw;\n _;\n }\n\n modifier validRequirement(uint ownerCount, uint _required) {\n if ( ownerCount > MAX_OWNER_COUNT\n || _required > ownerCount\n || _required == 0\n || ownerCount == 0)\n throw;\n _;\n }\n\n /// @dev Fallback function allows to deposit ether.\n function()\n payable\n {\n if (msg.value > 0)\n Deposit(msg.sender, msg.value);\n }\n\n /*\n * Public functions\n */\n /// @dev Contract constructor sets initial owners and required number of confirmations.\n /// @param _owners List of initial owners.\n /// @param _required Number of required confirmations.\n function MultiSigWallet(address[] _owners, uint _required)\n public\n validRequirement(_owners.length, _required)\n {\n for (uint i=0; i<_owners.length; i++) {\n if (isOwner[_owners[i]] || _owners[i] == 0)\n throw;\n isOwner[_owners[i]] = true;\n }\n owners = _owners;\n required = _required;\n }\n\n /// @dev Allows to add a new owner. Transaction has to be sent by wallet.\n /// @param owner Address of new owner.\n function addOwner(address owner)\n public\n onlyWallet\n ownerDoesNotExist(owner)\n notNull(owner)\n validRequirement(owners.length + 1, required)\n {\n isOwner[owner] = true;\n owners.push(owner);\n OwnerAddition(owner);\n }\n\n /// @dev Allows to remove an owner. Transaction has to be sent by wallet.\n /// @param owner Address of owner.\n function removeOwner(address owner)\n public\n onlyWallet\n ownerExists(owner)\n {\n isOwner[owner] = false;\n for (uint i=0; i<owners.length - 1; i++)\n if (owners[i] == owner) {\n owners[i] = owners[owners.length - 1];\n break;\n }\n owners.length -= 1;\n if (required > owners.length)\n changeRequirement(owners.length);\n OwnerRemoval(owner);\n }\n\n /// @dev Allows to replace an owner with a new owner. Transaction has to be sent by wallet.\n /// @param owner Address of owner to be replaced.\n /// @param owner Address of new owner.\n function replaceOwner(address owner, address newOwner)\n public\n onlyWallet\n ownerExists(owner)\n ownerDoesNotExist(newOwner)\n {\n for (uint i=0; i<owners.length; i++)\n if (owners[i] == owner) {\n owners[i] = newOwner;\n break;\n }\n isOwner[owner] = false;\n isOwner[newOwner] = true;\n OwnerRemoval(owner);\n OwnerAddition(newOwner);\n }\n\n /// @dev Allows to change the number of required confirmations. Transaction has to be sent by wallet.\n /// @param _required Number of required confirmations.\n function changeRequirement(uint _required)\n public\n onlyWallet\n validRequirement(owners.length, _required)\n {\n required = _required;\n RequirementChange(_required);\n }\n\n /// @dev Allows an owner to submit and confirm a transaction.\n /// @param destination Transaction target address.\n /// @param value Transaction ether value.\n /// @param data Transaction data payload.\n /// @return Returns transaction ID.\n function submitTransaction(address destination, uint value, bytes data)\n public\n returns (uint transactionId)\n {\n transactionId = addTransaction(destination, value, data);\n confirmTransaction(transactionId);\n }\n\n /// @dev Allows an owner to confirm a transaction.\n /// @param transactionId Transaction ID.\n function confirmTransaction(uint transactionId)\n public\n ownerExists(msg.sender)\n transactionExists(transactionId)\n notConfirmed(transactionId, msg.sender)\n {\n confirmations[transactionId][msg.sender] = true;\n Confirmation(msg.sender, transactionId);\n executeTransaction(transactionId);\n }\n\n /// @dev Allows an owner to revoke a confirmation for a transaction.\n /// @param transactionId Transaction ID.\n function revokeConfirmation(uint transactionId)\n public\n ownerExists(msg.sender)\n confirmed(transactionId, msg.sender)\n notExecuted(transactionId)\n {\n confirmations[transactionId][msg.sender] = false;\n Revocation(msg.sender, transactionId);\n }\n\n /// @dev Allows anyone to execute a confirmed transaction.\n /// @param transactionId Transaction ID.\n function executeTransaction(uint transactionId)\n public\n notExecuted(transactionId)\n {\n if (isConfirmed(transactionId)) {\n Transaction tx = transactions[transactionId];\n tx.executed = true;\n if (tx.destination.call.value(tx.value)(tx.data))\n Execution(transactionId);\n else {\n ExecutionFailure(transactionId);\n tx.executed = false;\n }\n }\n }\n\n /// @dev Returns the confirmation status of a transaction.\n /// @param transactionId Transaction ID.\n /// @return Confirmation status.\n function isConfirmed(uint transactionId)\n public\n constant\n returns (bool)\n {\n uint count = 0;\n for (uint i=0; i<owners.length; i++) {\n if (confirmations[transactionId][owners[i]])\n count += 1;\n if (count == required)\n return true;\n }\n }\n\n /*\n * Internal functions\n */\n /// @dev Adds a new transaction to the transaction mapping, if transaction does not exist yet.\n /// @param destination Transaction target address.\n /// @param value Transaction ether value.\n /// @param data Transaction data payload.\n /// @return Returns transaction ID.\n function addTransaction(address destination, uint value, bytes data)\n internal\n notNull(destination)\n returns (uint transactionId)\n {\n transactionId = transactionCount;\n transactions[transactionId] = Transaction({\n destination: destination,\n value: value,\n data: data,\n executed: false\n });\n transactionCount += 1;\n Submission(transactionId);\n }\n\n /*\n * Web3 call functions\n */\n /// @dev Returns number of confirmations of a transaction.\n /// @param transactionId Transaction ID.\n /// @return Number of confirmations.\n function getConfirmationCount(uint transactionId)\n public\n constant\n returns (uint count)\n {\n for (uint i=0; i<owners.length; i++)\n if (confirmations[transactionId][owners[i]])\n count += 1;\n }\n\n /// @dev Returns total number of transactions after filers are applied.\n /// @param pending Include pending transactions.\n /// @param executed Include executed transactions.\n /// @return Total number of transactions after filters are applied.\n function getTransactionCount(bool pending, bool executed)\n public\n constant\n returns (uint count)\n {\n for (uint i=0; i<transactionCount; i++)\n if ( pending && !transactions[i].executed\n || executed && transactions[i].executed)\n count += 1;\n }\n\n /// @dev Returns list of owners.\n /// @return List of owner addresses.\n function getOwners()\n public\n constant\n returns (address[])\n {\n return owners;\n }\n\n /// @dev Returns array with owner addresses, which confirmed transaction.\n /// @param transactionId Transaction ID.\n /// @return Returns array of owner addresses.\n function getConfirmations(uint transactionId)\n public\n constant\n returns (address[] _confirmations)\n {\n address[] memory confirmationsTemp = new address[](owners.length);\n uint count = 0;\n uint i;\n for (i=0; i<owners.length; i++)\n if (confirmations[transactionId][owners[i]]) {\n confirmationsTemp[count] = owners[i];\n count += 1;\n }\n _confirmations = new address[](count);\n for (i=0; i<count; i++)\n _confirmations[i] = confirmationsTemp[i];\n }\n\n /// @dev Returns list of transaction IDs in defined range.\n /// @param from Index start position of transaction array.\n /// @param to Index end position of transaction array.\n /// @param pending Include pending transactions.\n /// @param executed Include executed transactions.\n /// @return Returns array of transaction IDs.\n function getTransactionIds(uint from, uint to, bool pending, bool executed)\n public\n constant\n returns (uint[] _transactionIds)\n {\n uint[] memory transactionIdsTemp = new uint[](transactionCount);\n uint count = 0;\n uint i;\n for (i=0; i<transactionCount; i++)\n if ( pending && !transactions[i].executed\n || executed && transactions[i].executed)\n {\n transactionIdsTemp[count] = i;\n count += 1;\n }\n _transactionIds = new uint[](to - from);\n for (i=from; i<to; i++)\n _transactionIds[i - from] = transactionIdsTemp[i];\n }\n}\n"
}
},
"settings": {
"optimizer": {
"enabled": true,
"runs": 0
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode.object"
]
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment