|
// Copyright 2018 Parity Technologies (UK) Ltd. |
|
// |
|
// Licensed under the Apache License, Version 2.0 (the "License"); |
|
// you may not use this file except in compliance with the License. |
|
// You may obtain a copy of the License at |
|
// |
|
// http://www.apache.org/licenses/LICENSE-2.0 |
|
// |
|
// Unless required by applicable law or agreed to in writing, software |
|
// distributed under the License is distributed on an "AS IS" BASIS, |
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
// See the License for the specific language governing permissions and |
|
// limitations under the License. |
|
|
|
pragma solidity ^0.4.24; |
|
|
|
|
|
interface BlockReward { |
|
// produce rewards for the given beneficiaries, with corresponding reward codes. |
|
// only callable by `SYSTEM_ADDRESS` |
|
function reward(address[] beneficiaries, uint16[] kind) |
|
external |
|
returns (address[], uint256[]); |
|
} |
|
|
|
|
|
// Implements the Musicoin block reward as defined in |
|
// https://github.com/Musicoin/MCIPs/blob/master/MCIPS/mcip-3.md |
|
contract MusicoinBlockReward is BlockReward { |
|
address constant SYSTEM_ADDRESS = 0xffffFFFfFFffffffffffffffFfFFFfffFFFfFFfE; |
|
|
|
uint256 constant BLOCK_REWARD = 0x1105a0185b50a80000; // only used to calculate uncle rewards |
|
uint256 constant MINER_REWARD = 0xd8d726b7177a80000; |
|
uint256 constant UBI_REWARD = 0x2b5e3af16b1880000; |
|
address constant UBI_CONTRACT = 0x00eFdd5883eC628983E9063c7d969fE268BBf310; |
|
uint256 constant DEV_REWARD = 0xc249fdd327780000; |
|
address constant DEV_CONTRACT = 0x00756cF8159095948496617F5FB17ED95059f536; |
|
|
|
modifier onlySystem { |
|
require(msg.sender == SYSTEM_ADDRESS); |
|
_; |
|
} |
|
|
|
// produce rewards for the given benefactors, with corresponding reward codes. |
|
// only callable by `SYSTEM_ADDRESS` |
|
function reward(address[] beneficiaries, uint16[] kind) |
|
external |
|
onlySystem |
|
returns (address[], uint256[]) |
|
{ |
|
require(beneficiaries.length == kind.length); |
|
|
|
address[] memory addresses = new address[](3); // minimum 3 for author, ubi contract and dev contract |
|
uint256[] memory rewards = new uint256[](3); |
|
|
|
addresses[1] = UBI_CONTRACT; |
|
rewards[1] = UBI_REWARD; |
|
|
|
addresses[2] = DEV_CONTRACT; |
|
rewards[2] = DEV_REWARD; |
|
|
|
for (uint i = 0; i < beneficiaries.length; i++) { |
|
if (kind[i] == 0) { // author |
|
addresses[0] = beneficiaries[i]; |
|
rewards[0] = MINER_REWARD; |
|
|
|
} else if (kind[i] >= 100) { // uncle |
|
uint16 depth = kind[i] - 100; |
|
uint256 uncleReward = (BLOCK_REWARD * (8 - depth)) >> 3; |
|
|
|
addresses = pushAddressArray(addresses, beneficiaries[i]); |
|
rewards = pushUint256Array(rewards, uncleReward); |
|
} |
|
} |
|
|
|
return (addresses, rewards); |
|
} |
|
|
|
function pushAddressArray(address[] arr, address addr) |
|
internal |
|
pure |
|
returns (address[]) |
|
{ |
|
address[] memory ret = new address[](arr.length + 1); |
|
for (uint i = 0; i < arr.length; i++) { |
|
ret[i] = arr[i]; |
|
} |
|
ret[ret.length - 1] = addr; |
|
return ret; |
|
} |
|
|
|
function pushUint256Array(uint256[] arr, uint256 u) |
|
internal |
|
pure |
|
returns (uint256[]) |
|
{ |
|
uint256[] memory ret = new uint256[](arr.length + 1); |
|
for (uint i = 0; i < arr.length; i++) { |
|
ret[i] = arr[i]; |
|
} |
|
ret[ret.length - 1] = u; |
|
return ret; |
|
} |
|
} |