mirror of
https://git.wownero.com/wownero/wownero.git
synced 2024-12-22 23:08:53 +00:00
Merge pull request #6225
987c3139
print_coinbase_tx_sum now supports 128 bits sums (moneromooo-monero)
This commit is contained in:
commit
4371ac4265
@ -996,17 +996,31 @@ namespace cryptonote
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------
|
//---------------------------------------------------------------
|
||||||
std::string print_money(uint64_t amount, unsigned int decimal_point)
|
static void insert_money_decimal_point(std::string &s, unsigned int decimal_point)
|
||||||
{
|
{
|
||||||
if (decimal_point == (unsigned int)-1)
|
if (decimal_point == (unsigned int)-1)
|
||||||
decimal_point = default_decimal_point;
|
decimal_point = default_decimal_point;
|
||||||
std::string s = std::to_string(amount);
|
|
||||||
if(s.size() < decimal_point+1)
|
if(s.size() < decimal_point+1)
|
||||||
{
|
{
|
||||||
s.insert(0, decimal_point+1 - s.size(), '0');
|
s.insert(0, decimal_point+1 - s.size(), '0');
|
||||||
}
|
}
|
||||||
if (decimal_point > 0)
|
if (decimal_point > 0)
|
||||||
s.insert(s.size() - decimal_point, ".");
|
s.insert(s.size() - decimal_point, ".");
|
||||||
|
}
|
||||||
|
//---------------------------------------------------------------
|
||||||
|
std::string print_money(uint64_t amount, unsigned int decimal_point)
|
||||||
|
{
|
||||||
|
std::string s = std::to_string(amount);
|
||||||
|
insert_money_decimal_point(s, decimal_point);
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
//---------------------------------------------------------------
|
||||||
|
std::string print_money(const boost::multiprecision::uint128_t &amount, unsigned int decimal_point)
|
||||||
|
{
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << amount;
|
||||||
|
std::string s = ss.str();
|
||||||
|
insert_money_decimal_point(s, decimal_point);
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------
|
//---------------------------------------------------------------
|
||||||
|
@ -38,6 +38,7 @@
|
|||||||
#include "crypto/crypto.h"
|
#include "crypto/crypto.h"
|
||||||
#include "crypto/hash.h"
|
#include "crypto/hash.h"
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
#include <boost/multiprecision/cpp_int.hpp>
|
||||||
|
|
||||||
namespace epee
|
namespace epee
|
||||||
{
|
{
|
||||||
@ -139,6 +140,7 @@ namespace cryptonote
|
|||||||
unsigned int get_default_decimal_point();
|
unsigned int get_default_decimal_point();
|
||||||
std::string get_unit(unsigned int decimal_point = -1);
|
std::string get_unit(unsigned int decimal_point = -1);
|
||||||
std::string print_money(uint64_t amount, unsigned int decimal_point = -1);
|
std::string print_money(uint64_t amount, unsigned int decimal_point = -1);
|
||||||
|
std::string print_money(const boost::multiprecision::uint128_t &amount, unsigned int decimal_point = -1);
|
||||||
//---------------------------------------------------------------
|
//---------------------------------------------------------------
|
||||||
template<class t_object>
|
template<class t_object>
|
||||||
bool t_serializable_object_from_blob(t_object& to, const blobdata& b_blob)
|
bool t_serializable_object_from_blob(t_object& to, const blobdata& b_blob)
|
||||||
|
@ -1175,10 +1175,10 @@ namespace cryptonote
|
|||||||
return m_mempool.check_for_key_images(key_im, spent);
|
return m_mempool.check_for_key_images(key_im, spent);
|
||||||
}
|
}
|
||||||
//-----------------------------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------------------------
|
||||||
std::pair<uint64_t, uint64_t> core::get_coinbase_tx_sum(const uint64_t start_offset, const size_t count)
|
std::pair<boost::multiprecision::uint128_t, boost::multiprecision::uint128_t> core::get_coinbase_tx_sum(const uint64_t start_offset, const size_t count)
|
||||||
{
|
{
|
||||||
uint64_t emission_amount = 0;
|
boost::multiprecision::uint128_t emission_amount = 0;
|
||||||
uint64_t total_fee_amount = 0;
|
boost::multiprecision::uint128_t total_fee_amount = 0;
|
||||||
if (count)
|
if (count)
|
||||||
{
|
{
|
||||||
const uint64_t end = start_offset + count - 1;
|
const uint64_t end = start_offset + count - 1;
|
||||||
@ -1200,7 +1200,7 @@ namespace cryptonote
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return std::pair<uint64_t, uint64_t>(emission_amount, total_fee_amount);
|
return std::pair<boost::multiprecision::uint128_t, boost::multiprecision::uint128_t>(emission_amount, total_fee_amount);
|
||||||
}
|
}
|
||||||
//-----------------------------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------------------------
|
||||||
bool core::check_tx_inputs_keyimages_diff(const transaction& tx) const
|
bool core::check_tx_inputs_keyimages_diff(const transaction& tx) const
|
||||||
|
@ -765,7 +765,7 @@ namespace cryptonote
|
|||||||
*
|
*
|
||||||
* @return the number of blocks to sync in one go
|
* @return the number of blocks to sync in one go
|
||||||
*/
|
*/
|
||||||
std::pair<uint64_t, uint64_t> get_coinbase_tx_sum(const uint64_t start_offset, const size_t count);
|
std::pair<boost::multiprecision::uint128_t, boost::multiprecision::uint128_t> get_coinbase_tx_sum(const uint64_t start_offset, const size_t count);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief get the network type we're on
|
* @brief get the network type we're on
|
||||||
|
@ -1905,9 +1905,9 @@ bool t_rpc_command_executor::print_coinbase_tx_sum(uint64_t height, uint64_t cou
|
|||||||
|
|
||||||
tools::msg_writer() << "Sum of coinbase transactions between block heights ["
|
tools::msg_writer() << "Sum of coinbase transactions between block heights ["
|
||||||
<< height << ", " << (height + count) << ") is "
|
<< height << ", " << (height + count) << ") is "
|
||||||
<< cryptonote::print_money(res.emission_amount + res.fee_amount) << " "
|
<< cryptonote::print_money(boost::multiprecision::uint128_t(res.wide_emission_amount) + boost::multiprecision::uint128_t(res.wide_fee_amount)) << " "
|
||||||
<< "consisting of " << cryptonote::print_money(res.emission_amount)
|
<< "consisting of " << cryptonote::print_money(boost::multiprecision::uint128_t(res.wide_emission_amount))
|
||||||
<< " in emissions, and " << cryptonote::print_money(res.fee_amount) << " in fees";
|
<< " in emissions, and " << cryptonote::print_money(boost::multiprecision::uint128_t(res.wide_fee_amount)) << " in fees";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,11 +125,16 @@ namespace
|
|||||||
return (value + quantum - 1) / quantum * quantum;
|
return (value + quantum - 1) / quantum * quantum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void store_128(boost::multiprecision::uint128_t value, uint64_t &slow64, std::string &swide, uint64_t &stop64)
|
||||||
|
{
|
||||||
|
slow64 = (value & 0xffffffffffffffff).convert_to<uint64_t>();
|
||||||
|
swide = cryptonote::hex(value);
|
||||||
|
stop64 = ((value >> 64) & 0xffffffffffffffff).convert_to<uint64_t>();
|
||||||
|
}
|
||||||
|
|
||||||
void store_difficulty(cryptonote::difficulty_type difficulty, uint64_t &sdiff, std::string &swdiff, uint64_t &stop64)
|
void store_difficulty(cryptonote::difficulty_type difficulty, uint64_t &sdiff, std::string &swdiff, uint64_t &stop64)
|
||||||
{
|
{
|
||||||
sdiff = (difficulty & 0xffffffffffffffff).convert_to<uint64_t>();
|
store_128(difficulty, sdiff, swdiff, stop64);
|
||||||
swdiff = cryptonote::hex(difficulty);
|
|
||||||
stop64 = ((difficulty >> 64) & 0xffffffffffffffff).convert_to<uint64_t>();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2499,9 +2504,9 @@ namespace cryptonote
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
CHECK_PAYMENT_MIN1(req, res, COST_PER_COINBASE_TX_SUM_BLOCK * req.count, false);
|
CHECK_PAYMENT_MIN1(req, res, COST_PER_COINBASE_TX_SUM_BLOCK * req.count, false);
|
||||||
std::pair<uint64_t, uint64_t> amounts = m_core.get_coinbase_tx_sum(req.height, req.count);
|
std::pair<boost::multiprecision::uint128_t, boost::multiprecision::uint128_t> amounts = m_core.get_coinbase_tx_sum(req.height, req.count);
|
||||||
res.emission_amount = amounts.first;
|
store_128(amounts.first, res.emission_amount, res.wide_emission_amount, res.emission_amount_top64);
|
||||||
res.fee_amount = amounts.second;
|
store_128(amounts.second, res.fee_amount, res.wide_fee_amount, res.fee_amount_top64);
|
||||||
res.status = CORE_RPC_STATUS_OK;
|
res.status = CORE_RPC_STATUS_OK;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -2023,12 +2023,20 @@ namespace cryptonote
|
|||||||
struct response_t: public rpc_access_response_base
|
struct response_t: public rpc_access_response_base
|
||||||
{
|
{
|
||||||
uint64_t emission_amount;
|
uint64_t emission_amount;
|
||||||
|
std::string wide_emission_amount;
|
||||||
|
uint64_t emission_amount_top64;
|
||||||
uint64_t fee_amount;
|
uint64_t fee_amount;
|
||||||
|
std::string wide_fee_amount;
|
||||||
|
uint64_t fee_amount_top64;
|
||||||
|
|
||||||
BEGIN_KV_SERIALIZE_MAP()
|
BEGIN_KV_SERIALIZE_MAP()
|
||||||
KV_SERIALIZE_PARENT(rpc_access_response_base)
|
KV_SERIALIZE_PARENT(rpc_access_response_base)
|
||||||
KV_SERIALIZE(emission_amount)
|
KV_SERIALIZE(emission_amount)
|
||||||
|
KV_SERIALIZE(wide_emission_amount)
|
||||||
|
KV_SERIALIZE(emission_amount_top64)
|
||||||
KV_SERIALIZE(fee_amount)
|
KV_SERIALIZE(fee_amount)
|
||||||
|
KV_SERIALIZE(wide_fee_amount)
|
||||||
|
KV_SERIALIZE(fee_amount_top64)
|
||||||
END_KV_SERIALIZE_MAP()
|
END_KV_SERIALIZE_MAP()
|
||||||
};
|
};
|
||||||
typedef epee::misc_utils::struct_init<response_t> response;
|
typedef epee::misc_utils::struct_init<response_t> response;
|
||||||
|
@ -203,10 +203,15 @@ class BlockchainTest():
|
|||||||
res_sum = daemon.get_coinbase_tx_sum(i, 1)
|
res_sum = daemon.get_coinbase_tx_sum(i, 1)
|
||||||
res_header = daemon.getblockheaderbyheight(i)
|
res_header = daemon.getblockheaderbyheight(i)
|
||||||
assert res_sum.emission_amount == res_header.block_header.reward
|
assert res_sum.emission_amount == res_header.block_header.reward
|
||||||
|
assert res_sum.emission_amount_top64 == 0
|
||||||
|
assert res_sum.emission_amount == int(res_sum.wide_emission_amount, 16)
|
||||||
|
assert res_sum.fee_amount == int(res_sum.wide_fee_amount, 16)
|
||||||
|
|
||||||
res = daemon.get_coinbase_tx_sum(0, 1)
|
res = daemon.get_coinbase_tx_sum(0, 1)
|
||||||
assert res.emission_amount == 17592186044415
|
assert res.emission_amount == 17592186044415
|
||||||
|
assert res.emission_amount_top64 == 0
|
||||||
assert res.fee_amount == 0
|
assert res.fee_amount == 0
|
||||||
|
assert res.fee_amount_top64 == 0
|
||||||
sum_blocks = height + nblocks - 1
|
sum_blocks = height + nblocks - 1
|
||||||
res = daemon.get_coinbase_tx_sum(0, sum_blocks)
|
res = daemon.get_coinbase_tx_sum(0, sum_blocks)
|
||||||
extrapolated = 17592186044415 + 17592186044415 * 2 * (sum_blocks - 1)
|
extrapolated = 17592186044415 + 17592186044415 * 2 * (sum_blocks - 1)
|
||||||
|
Loading…
Reference in New Issue
Block a user