Merge pull request #4153

37f0799 wallet: distinguish coinbase from other txes in show_transfers (moneromooo-monero)
This commit is contained in:
luigi1111 2018-08-15 17:23:56 -05:00
commit 5e795ee7af
No known key found for this signature in database
GPG Key ID: F4ACA0183641E010
4 changed files with 35 additions and 16 deletions

View File

@ -2335,7 +2335,7 @@ simple_wallet::simple_wallet()
tr("Check a signature proving that the owner of <address> holds at least this much, optionally with a challenge string <message>.")); tr("Check a signature proving that the owner of <address> holds at least this much, optionally with a challenge string <message>."));
m_cmd_binder.set_handler("show_transfers", m_cmd_binder.set_handler("show_transfers",
boost::bind(&simple_wallet::show_transfers, this, _1), boost::bind(&simple_wallet::show_transfers, this, _1),
tr("show_transfers [in|out|pending|failed|pool] [index=<N1>[,<N2>,...]] [<min_height> [<max_height>]]"), tr("show_transfers [in|out|pending|failed|pool|coinbase] [index=<N1>[,<N2>,...]] [<min_height> [<max_height>]]"),
tr("Show the incoming/outgoing transfers within an optional height range.")); tr("Show the incoming/outgoing transfers within an optional height range."));
m_cmd_binder.set_handler("unspent_outputs", m_cmd_binder.set_handler("unspent_outputs",
boost::bind(&simple_wallet::unspent_outputs, this, _1), boost::bind(&simple_wallet::unspent_outputs, this, _1),
@ -6281,12 +6281,13 @@ bool simple_wallet::show_transfers(const std::vector<std::string> &args_)
bool pending = true; bool pending = true;
bool failed = true; bool failed = true;
bool pool = true; bool pool = true;
bool coinbase = true;
uint64_t min_height = 0; uint64_t min_height = 0;
uint64_t max_height = (uint64_t)-1; uint64_t max_height = (uint64_t)-1;
boost::optional<uint32_t> subaddr_index; boost::optional<uint32_t> subaddr_index;
if(local_args.size() > 4) { if(local_args.size() > 4) {
fail_msg_writer() << tr("usage: show_transfers [in|out|all|pending|failed] [index=<N1>[,<N2>,...]] [<min_height> [<max_height>]]"); fail_msg_writer() << tr("usage: show_transfers [in|out|all|pending|failed|coinbase] [index=<N1>[,<N2>,...]] [<min_height> [<max_height>]]");
return true; return true;
} }
@ -6299,19 +6300,24 @@ bool simple_wallet::show_transfers(const std::vector<std::string> &args_)
local_args.erase(local_args.begin()); local_args.erase(local_args.begin());
} }
else if (local_args[0] == "out" || local_args[0] == "outgoing") { else if (local_args[0] == "out" || local_args[0] == "outgoing") {
in = pool = false; in = pool = coinbase = false;
local_args.erase(local_args.begin()); local_args.erase(local_args.begin());
} }
else if (local_args[0] == "pending") { else if (local_args[0] == "pending") {
in = out = failed = false; in = out = failed = coinbase = false;
local_args.erase(local_args.begin()); local_args.erase(local_args.begin());
} }
else if (local_args[0] == "failed") { else if (local_args[0] == "failed") {
in = out = pending = pool = false; in = out = pending = pool = coinbase = false;
local_args.erase(local_args.begin()); local_args.erase(local_args.begin());
} }
else if (local_args[0] == "pool") { else if (local_args[0] == "pool") {
in = out = pending = failed = false; in = out = pending = failed = coinbase = false;
local_args.erase(local_args.begin());
}
else if (local_args[0] == "coinbase") {
in = out = pending = failed = pool = false;
coinbase = true;
local_args.erase(local_args.begin()); local_args.erase(local_args.begin());
} }
else if (local_args[0] == "all" || local_args[0] == "both") { else if (local_args[0] == "all" || local_args[0] == "both") {
@ -6352,20 +6358,23 @@ bool simple_wallet::show_transfers(const std::vector<std::string> &args_)
local_args.erase(local_args.begin()); local_args.erase(local_args.begin());
} }
std::multimap<uint64_t, std::pair<bool,std::string>> output; std::multimap<uint64_t, std::tuple<epee::console_colors, std::string, std::string>> output;
PAUSE_READLINE(); PAUSE_READLINE();
if (in) { if (in || coinbase) {
std::list<std::pair<crypto::hash, tools::wallet2::payment_details>> payments; std::list<std::pair<crypto::hash, tools::wallet2::payment_details>> payments;
m_wallet->get_payments(payments, min_height, max_height, m_current_subaddress_account, subaddr_indices); m_wallet->get_payments(payments, min_height, max_height, m_current_subaddress_account, subaddr_indices);
for (std::list<std::pair<crypto::hash, tools::wallet2::payment_details>>::const_iterator i = payments.begin(); i != payments.end(); ++i) { for (std::list<std::pair<crypto::hash, tools::wallet2::payment_details>>::const_iterator i = payments.begin(); i != payments.end(); ++i) {
const tools::wallet2::payment_details &pd = i->second; const tools::wallet2::payment_details &pd = i->second;
if (!pd.m_coinbase && !in)
continue;
std::string payment_id = string_tools::pod_to_hex(i->first); std::string payment_id = string_tools::pod_to_hex(i->first);
if (payment_id.substr(16).find_first_not_of('0') == std::string::npos) if (payment_id.substr(16).find_first_not_of('0') == std::string::npos)
payment_id = payment_id.substr(0,16); payment_id = payment_id.substr(0,16);
std::string note = m_wallet->get_tx_note(pd.m_tx_hash); std::string note = m_wallet->get_tx_note(pd.m_tx_hash);
output.insert(std::make_pair(pd.m_block_height, std::make_pair(true, (boost::format("%25.25s %20.20s %s %s %d %s %s") % get_human_readable_timestamp(pd.m_timestamp) % print_money(pd.m_amount) % string_tools::pod_to_hex(pd.m_tx_hash) % payment_id % pd.m_subaddr_index.minor % "-" % note).str()))); const std::string type = pd.m_coinbase ? tr("block") : tr("in");
output.insert(std::make_pair(pd.m_block_height, std::make_tuple(epee::console_color_green, type, (boost::format("%25.25s %20.20s %s %s %d %s %s") % get_human_readable_timestamp(pd.m_timestamp) % print_money(pd.m_amount) % string_tools::pod_to_hex(pd.m_tx_hash) % payment_id % pd.m_subaddr_index.minor % "-" % note).str())));
} }
} }
@ -6398,15 +6407,15 @@ bool simple_wallet::show_transfers(const std::vector<std::string> &args_)
if (payment_id.substr(16).find_first_not_of('0') == std::string::npos) if (payment_id.substr(16).find_first_not_of('0') == std::string::npos)
payment_id = payment_id.substr(0,16); payment_id = payment_id.substr(0,16);
std::string note = m_wallet->get_tx_note(i->first); std::string note = m_wallet->get_tx_note(i->first);
output.insert(std::make_pair(pd.m_block_height, std::make_pair(false, (boost::format("%25.25s %20.20s %s %s %14.14s %s %s - %s") % get_human_readable_timestamp(pd.m_timestamp) % print_money(pd.m_amount_in - change - fee) % string_tools::pod_to_hex(i->first) % payment_id % print_money(fee) % dests % print_subaddr_indices(pd.m_subaddr_indices) % note).str()))); output.insert(std::make_pair(pd.m_block_height, std::make_tuple(epee::console_color_magenta, tr("out"), (boost::format("%25.25s %20.20s %s %s %14.14s %s %s - %s") % get_human_readable_timestamp(pd.m_timestamp) % print_money(pd.m_amount_in - change - fee) % string_tools::pod_to_hex(i->first) % payment_id % print_money(fee) % dests % print_subaddr_indices(pd.m_subaddr_indices) % note).str())));
} }
} }
// print in and out sorted by height // print in and out sorted by height
for (std::map<uint64_t, std::pair<bool, std::string>>::const_iterator i = output.begin(); i != output.end(); ++i) { for (std::multimap<uint64_t, std::tuple<epee::console_colors, std::string, std::string>>::const_iterator i = output.begin(); i != output.end(); ++i) {
message_writer(i->second.first ? console_color_green : console_color_magenta, false) << message_writer(std::get<0>(i->second), false) <<
boost::format("%8.8llu %6.6s %s") % boost::format("%8.8llu %6.6s %s") %
((unsigned long long)i->first) % (i->second.first ? tr("in") : tr("out")) % i->second.second; ((unsigned long long)i->first) % std::get<1>(i->second) % std::get<2>(i->second);
} }
if (pool) { if (pool) {

View File

@ -1599,6 +1599,7 @@ void wallet2::process_new_transaction(const crypto::hash &txid, const cryptonote
payment.m_block_height = height; payment.m_block_height = height;
payment.m_unlock_time = tx.unlock_time; payment.m_unlock_time = tx.unlock_time;
payment.m_timestamp = ts; payment.m_timestamp = ts;
payment.m_coinbase = miner_tx;
payment.m_subaddr_index = i.first; payment.m_subaddr_index = i.first;
if (pool) { if (pool) {
emplace_or_replace(m_unconfirmed_payments, payment_id, pool_payment_details{payment, double_spend_seen}); emplace_or_replace(m_unconfirmed_payments, payment_id, pool_payment_details{payment, double_spend_seen});
@ -7556,6 +7557,7 @@ void wallet2::light_wallet_get_address_txs()
payment.m_block_height = t.height; payment.m_block_height = t.height;
payment.m_unlock_time = t.unlock_time; payment.m_unlock_time = t.unlock_time;
payment.m_timestamp = t.timestamp; payment.m_timestamp = t.timestamp;
payment.m_coinbase = t.coinbase;
if (t.mempool) { if (t.mempool) {
if (std::find(unconfirmed_payments_txs.begin(), unconfirmed_payments_txs.end(), tx_hash) == unconfirmed_payments_txs.end()) { if (std::find(unconfirmed_payments_txs.begin(), unconfirmed_payments_txs.end(), tx_hash) == unconfirmed_payments_txs.end()) {

View File

@ -260,12 +260,12 @@ namespace tools
uint64_t m_block_height; uint64_t m_block_height;
uint64_t m_unlock_time; uint64_t m_unlock_time;
uint64_t m_timestamp; uint64_t m_timestamp;
bool m_coinbase;
cryptonote::subaddress_index m_subaddr_index; cryptonote::subaddress_index m_subaddr_index;
}; };
struct address_tx : payment_details struct address_tx : payment_details
{ {
bool m_coinbase;
bool m_mempool; bool m_mempool;
bool m_incoming; bool m_incoming;
}; };
@ -1324,7 +1324,7 @@ BOOST_CLASS_VERSION(tools::wallet2::transfer_details, 9)
BOOST_CLASS_VERSION(tools::wallet2::multisig_info, 1) BOOST_CLASS_VERSION(tools::wallet2::multisig_info, 1)
BOOST_CLASS_VERSION(tools::wallet2::multisig_info::LR, 0) BOOST_CLASS_VERSION(tools::wallet2::multisig_info::LR, 0)
BOOST_CLASS_VERSION(tools::wallet2::multisig_tx_set, 1) BOOST_CLASS_VERSION(tools::wallet2::multisig_tx_set, 1)
BOOST_CLASS_VERSION(tools::wallet2::payment_details, 3) BOOST_CLASS_VERSION(tools::wallet2::payment_details, 4)
BOOST_CLASS_VERSION(tools::wallet2::pool_payment_details, 1) BOOST_CLASS_VERSION(tools::wallet2::pool_payment_details, 1)
BOOST_CLASS_VERSION(tools::wallet2::unconfirmed_transfer_details, 8) BOOST_CLASS_VERSION(tools::wallet2::unconfirmed_transfer_details, 8)
BOOST_CLASS_VERSION(tools::wallet2::confirmed_transfer_details, 6) BOOST_CLASS_VERSION(tools::wallet2::confirmed_transfer_details, 6)
@ -1591,16 +1591,24 @@ namespace boost
a & x.m_timestamp; a & x.m_timestamp;
if (ver < 2) if (ver < 2)
{ {
x.m_coinbase = false;
x.m_subaddr_index = {}; x.m_subaddr_index = {};
return; return;
} }
a & x.m_subaddr_index; a & x.m_subaddr_index;
if (ver < 3) if (ver < 3)
{ {
x.m_coinbase = false;
x.m_fee = 0; x.m_fee = 0;
return; return;
} }
a & x.m_fee; a & x.m_fee;
if (ver < 4)
{
x.m_coinbase = false;
return;
}
a & x.m_coinbase;
} }
template <class Archive> template <class Archive>

View File

@ -270,7 +270,7 @@ namespace tools
entry.unlock_time = pd.m_unlock_time; entry.unlock_time = pd.m_unlock_time;
entry.fee = pd.m_fee; entry.fee = pd.m_fee;
entry.note = m_wallet->get_tx_note(pd.m_tx_hash); entry.note = m_wallet->get_tx_note(pd.m_tx_hash);
entry.type = "in"; entry.type = pd.m_coinbase ? "block" : "in";
entry.subaddr_index = pd.m_subaddr_index; entry.subaddr_index = pd.m_subaddr_index;
entry.address = m_wallet->get_subaddress_as_str(pd.m_subaddr_index); entry.address = m_wallet->get_subaddress_as_str(pd.m_subaddr_index);
set_confirmations(entry, m_wallet->get_blockchain_current_height(), m_wallet->get_last_block_reward()); set_confirmations(entry, m_wallet->get_blockchain_current_height(), m_wallet->get_last_block_reward());