Skip to content

Instantly share code, notes, and snippets.

@andresilva
Last active September 21, 2018 00:31
Show Gist options
  • Save andresilva/6f2afaf9486732a0797f4bdeae018ee9 to your computer and use it in GitHub Desktop.
Save andresilva/6f2afaf9486732a0797f4bdeae018ee9 to your computer and use it in GitHub Desktop.
MusicoinBlockReward

Readme

module.exports = {
  ...
  solc: {
    optimizer: {
      enabled: true,
      runs: 1000
    }
  }
}
  • yarn compile
  • cat build/contracts/MusicoinBlockReward.json | jq .deployedBytecode

The resulting bytecode should be the same as in this gist. We need to use deployedBytecode since we're going to inline the code into the engine using blockRewardContractCode and therefore won't be creating the contract in a transaction and running its constructor. If we were deploying with blockRewardContractAddress we would use bytecode instead.

Solidity version: 0.4.24

0x6080604052600436106100405763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663f91c28988114610045575b600080fd5b34801561005157600080fd5b50610071602460048035828101929082013591813591820191013561010a565b604051808060200180602001838103835285818151815260200191508051906020019060200280838360005b838110156100b557818101518382015260200161009d565b50505050905001838103825284818151815260200191508051906020019060200280838360005b838110156100f45781810151838201526020016100dc565b5050505090500194505050505060405180910390f35b6060808080600080803373fffffffffffffffffffffffffffffffffffffffe1461013357600080fd5b89881461013f57600080fd5b60408051600380825260808201909252906020820160608038833950506040805160038082526080820190925292975090506020820160608038833901905050935072efdd5883ec628983e9063c7d969fe268bbf3108560018151811015156101a457fe5b73ffffffffffffffffffffffffffffffffffffffff90921660209283029091019091015283516802b5e3af16b188000090859060019081106101e257fe5b60209081029091010152845172756cf8159095948496617f5fb17ed95059f536908690600290811061021057fe5b73ffffffffffffffffffffffffffffffffffffffff909216602092830290910190910152835167c249fdd327780000908590600290811061024d57fe5b60209081029091010152600092505b898310156103b75788888481811061027057fe5b9050602002013561ffff1661ffff166000141561030c578a8a8481811061029357fe5b9050602002013573ffffffffffffffffffffffffffffffffffffffff168560008151811015156102bf57fe5b73ffffffffffffffffffffffffffffffffffffffff9092166020928302909101909101528351680d8d726b7177a8000090859060009081106102fd57fe5b602090810290910101526103ac565b606489898581811061031a57fe5b9050602002013561ffff1661ffff161015156103ac57606489898581811061033e57fe5b9050602002013561ffff1603915060038260080361ffff16681105a0185b50a80000029060020a9004905061039d858c8c86818110151561037b57fe5b9050602002013573ffffffffffffffffffffffffffffffffffffffff166103c8565b94506103a9848261049f565b93505b60019092019161025c565b509299919850909650505050505050565b606080600084516001016040519080825280602002602001820160405280156103fb578160200160208202803883390190505b509150600090505b845181101561045e57848181518110151561041a57fe5b90602001906020020151828281518110151561043257fe5b73ffffffffffffffffffffffffffffffffffffffff909216602092830290910190910152600101610403565b8382600184510381518110151561047157fe5b73ffffffffffffffffffffffffffffffffffffffff9290921660209283029190910190910152509392505050565b606080600084516001016040519080825280602002602001820160405280156104d2578160200160208202803883390190505b509150600090505b845181101561051b5784818151811015156104f157fe5b90602001906020020151828281518110151561050957fe5b602090810290910101526001016104da565b8382600184510381518110151561052e57fe5b60209081029190910101525093925050505600a165627a7a72305820c9ab92a56245040e76af5fc4f3ac4cf4315336b503db06677c21aa1e00aaa8e20029
// 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;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment