github.com/codingfuture/orig-energi3@v0.8.4/energi/contracts/src/BlockRewardV1.sol (about) 1 // Copyright 2019 The Energi Core Authors 2 // This file is part of Energi Core. 3 // 4 // Energi Core is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Energi Core is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Energi Core. If not, see <http://www.gnu.org/licenses/>. 16 17 // Energi Governance system is the fundamental part of Energi Core. 18 19 // NOTE: It's not allowed to change the compiler due to byte-to-byte 20 // match requirement. 21 pragma solidity 0.5.16; 22 //pragma experimental SMTChecker; 23 24 import { GovernedContract } from "./GovernedContract.sol"; 25 import { IBlockReward } from "./IBlockReward.sol"; 26 import { IGovernedProxy } from "./IGovernedProxy.sol"; 27 import { NonReentrant } from "./NonReentrant.sol"; 28 29 /** 30 * Genesis hardcoded version of SporkReward 31 * 32 * NOTE: it MUST NOT change after blockchain launch! 33 */ 34 contract BlockRewardV1 is 35 GovernedContract, 36 IBlockReward, 37 NonReentrant 38 { 39 uint constant internal GET_GAS = 10000; 40 41 IGovernedProxy[] public reward_proxies; 42 43 // IGovernedContract 44 //--------------------------------- 45 constructor(address _proxy, IGovernedProxy[] memory _reward_proxies) 46 public 47 GovernedContract(_proxy) 48 { 49 for (uint i = 0; i < _reward_proxies.length; ++i) { 50 reward_proxies.push(_reward_proxies[i]); 51 } 52 } 53 54 // IBlockReward 55 //--------------------------------- 56 function reward() 57 external payable 58 noReentry 59 { 60 uint len = reward_proxies.length; 61 uint gas_per_reward = (gasleft() / len) - GET_GAS; 62 63 for (uint i = 0; i < len; ++i) { 64 IBlockReward impl = IBlockReward(address(reward_proxies[i].impl())); 65 66 uint amount = impl.getReward.gas(GET_GAS)(block.number); 67 68 // solium-disable-next-line security/no-call-value 69 address(impl).call.value(amount).gas(gas_per_reward)(abi.encode(impl.reward.selector)); 70 } 71 } 72 73 function getReward(uint _blockNumber) 74 external view 75 returns(uint amount) 76 { 77 for (uint i = reward_proxies.length; i-- > 0;) { 78 IBlockReward impl = IBlockReward(address(reward_proxies[i].impl())); 79 amount += impl.getReward(_blockNumber); 80 } 81 } 82 83 // Safety 84 //--------------------------------- 85 function () external payable { 86 revert("Not supported"); 87 } 88 }