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

(Feature) Add BlockReward contract to security-audit branch #83

Merged
merged 1 commit into from
May 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions contracts/BlockReward.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
pragma solidity ^0.4.23;

import "./interfaces/IBlockReward.sol";
import "./interfaces/IKeysManager.sol";
import "./interfaces/IProxyStorage.sol";


contract BlockReward is IBlockReward {
address constant SYSTEM_ADDRESS = 0xffffFFFfFFffffffffffffffFfFFFfffFFFfFFfE;

IProxyStorage public proxyStorage;
address public emissionFunds;
uint256 public blockRewardAmount;
uint256 public emissionFundsAmount;

modifier onlySystem {
require(msg.sender == SYSTEM_ADDRESS);
_;
}

constructor(
address _proxyStorage,
address _emissionFunds,
uint256 _blockRewardAmount,
uint256 _emissionFundsAmount
) public {
require(_proxyStorage != address(0));
require(_blockRewardAmount != 0);
proxyStorage = IProxyStorage(_proxyStorage);
emissionFunds = _emissionFunds;
blockRewardAmount = _blockRewardAmount;
emissionFundsAmount = _emissionFundsAmount;
}

function reward(address[] benefactors, uint16[] kind)
external
onlySystem
returns (address[], uint256[])
{
require(benefactors.length == kind.length);
require(benefactors.length == 1);
require(kind[0] == 0);

address miningKey = benefactors[0];
address payoutKey = _getPayoutByMining(miningKey);

require(payoutKey != address(0));

uint256 receiversLength = 2;

if (emissionFunds == address(0) || emissionFundsAmount == 0) {
receiversLength = 1;
}

address[] memory receivers = new address[](receiversLength);
uint256[] memory rewards = new uint256[](receiversLength);

receivers[0] = payoutKey;
rewards[0] = blockRewardAmount;

if (receiversLength == 2) {
receivers[1] = emissionFunds;
rewards[1] = emissionFundsAmount;
}

return (receivers, rewards);
}

function _getPayoutByMining(address _miningKey)
private
view
returns (address)
{
IKeysManager keysManager = IKeysManager(proxyStorage.getKeysManager());
return keysManager.getPayoutByMining(_miningKey);
}
}
8 changes: 8 additions & 0 deletions contracts/interfaces/IBlockReward.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
pragma solidity ^0.4.23;


interface IBlockReward {
// Produce rewards for the given benefactors, with corresponding reward codes.
// Only callable by `SYSTEM_ADDRESS`
function reward(address[], uint16[]) external returns (address[], uint256[]);
}