Skip to content

Commit

Permalink
fix reward returned in getblockbyheaderheight for "donation" blocks.
Browse files Browse the repository at this point in the history
thanks to theonenirvana on Slack for finding this
  • Loading branch information
clintar committed May 3, 2017
1 parent f0a6222 commit f601f83
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/currency_core/blockchain_storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ namespace currency
void print_blockchain(uint64_t start_index, uint64_t end_index);
void print_blockchain_index();
void print_blockchain_outs(const std::string& file);
bool lookfor_donation(const transaction& tx, uint64_t& donation, uint64_t& royalty);

private:
typedef std::unordered_map<crypto::hash, size_t> blocks_by_id_index;
Expand Down Expand Up @@ -246,7 +247,6 @@ namespace currency
uint64_t get_adjusted_time();
bool complete_timestamps_vector(uint64_t start_height, std::vector<uint64_t>& timestamps);
bool update_next_comulative_size_limit();
bool lookfor_donation(const transaction& tx, uint64_t& donation, uint64_t& royalty);
bool get_block_for_scratchpad_alt(uint64_t connection_height, uint64_t block_index, std::list<blockchain_storage::blocks_ext_by_hash::iterator>& alt_chain, block & b);
bool process_blockchain_tx_extra(const transaction& tx);
bool unprocess_blockchain_tx_extra(const transaction& tx);
Expand Down
11 changes: 11 additions & 0 deletions src/rpc/core_rpc_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -521,10 +521,21 @@ namespace currency
uint64_t core_rpc_server::get_block_reward(const block& blk)
{
uint64_t reward = 0;
uint64_t royalty = 0;
uint64_t donation = 0;
uint64_t h = get_block_height(blk);
BOOST_FOREACH(const tx_out& out, blk.miner_tx.vout)
{
reward += out.amount;
}

if(h && !(h%CURRENCY_DONATIONS_INTERVAL) /*&& h > 21600*/)
{
bool r = m_core.get_blockchain_storage().lookfor_donation(blk.miner_tx, donation, royalty);
CHECK_AND_ASSERT_MES(r, false, "Failed to lookfor_donation");
reward -= donation + royalty;
}

return reward;
}
//------------------------------------------------------------------------------------------------------------------------------
Expand Down

0 comments on commit f601f83

Please sign in to comment.