mirror of
https://codeberg.org/anoncontributorxmr/monero.git
synced 2024-11-23 19:33:28 +01:00
wallet: improve show_transfers
More information is now saved and displayed
This commit is contained in:
parent
725ae4e710
commit
b3d4d41e29
@ -1998,24 +1998,29 @@ bool simple_wallet::show_transfers(const std::vector<std::string> &args_)
|
||||
std::vector<std::string> local_args = args_;
|
||||
bool in = true;
|
||||
bool out = true;
|
||||
bool pending = true;
|
||||
uint64_t min_height = 0;
|
||||
uint64_t max_height = (uint64_t)-1;
|
||||
|
||||
if(local_args.size() > 3) {
|
||||
fail_msg_writer() << tr("Usage: show_transfers [in|out] [<min_height> [<max_height>]]");
|
||||
fail_msg_writer() << tr("Usage: show_transfers [in|out|all|pending] [<min_height> [<max_height>]]");
|
||||
return true;
|
||||
}
|
||||
|
||||
// optional in/out selector
|
||||
if (local_args.size() > 0) {
|
||||
if (local_args[0] == "in" || local_args[0] == "incoming") {
|
||||
out = false;
|
||||
out = pending = false;
|
||||
local_args.erase(local_args.begin());
|
||||
}
|
||||
else if (local_args[0] == "out" || local_args[0] == "outgoing") {
|
||||
in = false;
|
||||
local_args.erase(local_args.begin());
|
||||
}
|
||||
else if (local_args[0] == "pending") {
|
||||
in = out = false;
|
||||
local_args.erase(local_args.begin());
|
||||
}
|
||||
else if (local_args[0] == "all" || local_args[0] == "both") {
|
||||
local_args.erase(local_args.begin());
|
||||
}
|
||||
@ -2055,7 +2060,7 @@ bool simple_wallet::show_transfers(const std::vector<std::string> &args_)
|
||||
std::string payment_id = string_tools::pod_to_hex(i->first);
|
||||
if (payment_id.substr(16).find_first_not_of('0') == std::string::npos)
|
||||
payment_id = payment_id.substr(0,16);
|
||||
output.insert(std::make_pair(pd.m_block_height, std::make_pair(true, (boost::format("%20.20s %s %s") % print_money(pd.m_amount) % string_tools::pod_to_hex(pd.m_tx_hash) % payment_id).str())));
|
||||
output.insert(std::make_pair(pd.m_block_height, std::make_pair(true, (boost::format("%20.20s %s %s %s") % print_money(pd.m_amount) % string_tools::pod_to_hex(pd.m_tx_hash) % payment_id % "-").str())));
|
||||
}
|
||||
}
|
||||
|
||||
@ -2066,8 +2071,16 @@ bool simple_wallet::show_transfers(const std::vector<std::string> &args_)
|
||||
const tools::wallet2::confirmed_transfer_details &pd = i->second;
|
||||
uint64_t fee = pd.m_amount_in - pd.m_amount_out;
|
||||
uint64_t change = pd.m_change == (uint64_t)-1 ? 0 : pd.m_change; // change may not be known
|
||||
LOG_PRINT_L2("out: in " << print_money(pd.m_amount_in) << ", out " << print_money(pd.m_amount_out) << ", change " << print_money(change) << ", fee " << print_money(fee));
|
||||
output.insert(std::make_pair(pd.m_block_height, std::make_pair(false, (boost::format("%20.20s %s") % print_money(pd.m_amount_in - change - fee) % "-").str())));
|
||||
std::string dests;
|
||||
for (const auto &d: pd.m_dests) {
|
||||
if (!dests.empty())
|
||||
dests += ", ";
|
||||
dests += get_account_address_as_str(m_wallet->testnet(), d.addr) + ": " + print_money(d.amount);
|
||||
}
|
||||
std::string payment_id = string_tools::pod_to_hex(i->second.m_payment_id);
|
||||
if (payment_id.substr(16).find_first_not_of('0') == std::string::npos)
|
||||
payment_id = payment_id.substr(0,16);
|
||||
output.insert(std::make_pair(pd.m_block_height, std::make_pair(false, (boost::format("%20.20s %s %s %14.14s %s") % print_money(pd.m_amount_in - change - fee) % string_tools::pod_to_hex(i->first) % payment_id % print_money(fee) % dests).str())));
|
||||
}
|
||||
}
|
||||
|
||||
@ -2079,14 +2092,18 @@ bool simple_wallet::show_transfers(const std::vector<std::string> &args_)
|
||||
}
|
||||
|
||||
// print unconfirmed last
|
||||
if (out) {
|
||||
if (pending) {
|
||||
std::list<std::pair<crypto::hash, tools::wallet2::unconfirmed_transfer_details>> upayments;
|
||||
m_wallet->get_unconfirmed_payments_out(upayments);
|
||||
for (std::list<std::pair<crypto::hash, tools::wallet2::unconfirmed_transfer_details>>::const_iterator i = upayments.begin(); i != upayments.end(); ++i) {
|
||||
const tools::wallet2::unconfirmed_transfer_details &pd = i->second;
|
||||
uint64_t amount = 0;
|
||||
cryptonote::get_inputs_money_amount(pd.m_tx, amount);
|
||||
message_writer() << (boost::format("%8.8s %6.6s %20.20s") % tr("pending") % tr("out") % print_money(amount - pd.m_change)).str();
|
||||
uint64_t fee = amount - get_outs_money_amount(pd.m_tx);
|
||||
std::string payment_id = string_tools::pod_to_hex(i->second.m_payment_id);
|
||||
if (payment_id.substr(16).find_first_not_of('0') == std::string::npos)
|
||||
payment_id = payment_id.substr(0,16);
|
||||
message_writer() << (boost::format("%8.8s %6.6s %20.20s %s %s %14.14s") % tr("pending") % tr("out") % print_money(amount - pd.m_change) % string_tools::pod_to_hex(i->first) % payment_id % print_money(fee)).str();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1225,12 +1225,14 @@ uint64_t wallet2::select_transfers(uint64_t needed_money, bool add_dust, uint64_
|
||||
return found_money;
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
void wallet2::add_unconfirmed_tx(const cryptonote::transaction& tx, uint64_t change_amount)
|
||||
void wallet2::add_unconfirmed_tx(const cryptonote::transaction& tx, const std::vector<cryptonote::tx_destination_entry> &dests, const crypto::hash &payment_id, uint64_t change_amount)
|
||||
{
|
||||
unconfirmed_transfer_details& utd = m_unconfirmed_txs[cryptonote::get_transaction_hash(tx)];
|
||||
utd.m_change = change_amount;
|
||||
utd.m_sent_time = time(NULL);
|
||||
utd.m_tx = tx;
|
||||
utd.m_dests = dests;
|
||||
utd.m_payment_id = payment_id;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
@ -1364,6 +1366,30 @@ std::string wallet2::address_from_txt_record(const std::string& s)
|
||||
return std::string();
|
||||
}
|
||||
|
||||
crypto::hash wallet2::get_payment_id(const pending_tx &ptx) const
|
||||
{
|
||||
std::vector<tx_extra_field> tx_extra_fields;
|
||||
if(!parse_tx_extra(ptx.tx.extra, tx_extra_fields))
|
||||
return cryptonote::null_hash;
|
||||
tx_extra_nonce extra_nonce;
|
||||
crypto::hash payment_id = null_hash;
|
||||
if (find_tx_extra_field_by_type(tx_extra_fields, extra_nonce))
|
||||
{
|
||||
crypto::hash8 payment_id8 = null_hash8;
|
||||
if(get_encrypted_payment_id_from_tx_extra_nonce(extra_nonce.nonce, payment_id8))
|
||||
{
|
||||
if (decrypt_payment_id(payment_id8, ptx.dests[0].addr.m_view_public_key, ptx.tx_key))
|
||||
{
|
||||
memcpy(payment_id.data, payment_id8.data, 8);
|
||||
}
|
||||
}
|
||||
else if (!get_payment_id_from_tx_extra_nonce(extra_nonce.nonce, payment_id))
|
||||
{
|
||||
payment_id = cryptonote::null_hash;
|
||||
}
|
||||
}
|
||||
return payment_id;
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// take a pending tx and actually send it to the daemon
|
||||
void wallet2::commit_tx(pending_tx& ptx)
|
||||
@ -1380,7 +1406,14 @@ void wallet2::commit_tx(pending_tx& ptx)
|
||||
THROW_WALLET_EXCEPTION_IF(daemon_send_resp.status != CORE_RPC_STATUS_OK, error::tx_rejected, ptx.tx, daemon_send_resp.status);
|
||||
|
||||
txid = get_transaction_hash(ptx.tx);
|
||||
add_unconfirmed_tx(ptx.tx, ptx.change_dts.amount);
|
||||
crypto::hash payment_id = cryptonote::null_hash;
|
||||
std::vector<cryptonote::tx_destination_entry> dests;
|
||||
if (store_tx_keys())
|
||||
{
|
||||
payment_id = get_payment_id(ptx);
|
||||
dests = ptx.dests;
|
||||
}
|
||||
add_unconfirmed_tx(ptx.tx, dests, payment_id, ptx.change_dts.amount);
|
||||
if (store_tx_keys())
|
||||
m_tx_keys.insert(std::make_pair(txid, ptx.tx_key));
|
||||
|
||||
@ -1658,6 +1691,7 @@ void wallet2::transfer_selected(const std::vector<cryptonote::tx_destination_ent
|
||||
ptx.change_dts = change_dts;
|
||||
ptx.selected_transfers = selected_transfers;
|
||||
ptx.tx_key = tx_key;
|
||||
ptx.dests = dsts;
|
||||
}
|
||||
|
||||
// Another implementation of transaction creation that is hopefully better
|
||||
@ -2006,6 +2040,7 @@ void wallet2::transfer_dust(size_t num_outputs, uint64_t unlock_time, uint64_t n
|
||||
ptx.change_dts = change_dts;
|
||||
ptx.selected_transfers = selected_transfers;
|
||||
ptx.tx_key = tx_key;
|
||||
ptx.dests = dsts;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
|
@ -107,6 +107,8 @@ namespace tools
|
||||
cryptonote::transaction m_tx;
|
||||
uint64_t m_change;
|
||||
time_t m_sent_time;
|
||||
std::vector<cryptonote::tx_destination_entry> m_dests;
|
||||
crypto::hash m_payment_id;
|
||||
};
|
||||
|
||||
struct confirmed_transfer_details
|
||||
@ -115,9 +117,12 @@ namespace tools
|
||||
uint64_t m_amount_out;
|
||||
uint64_t m_change;
|
||||
uint64_t m_block_height;
|
||||
confirmed_transfer_details(): m_amount_in(0), m_amount_out(0), m_change((uint64_t)-1), m_block_height(0) {}
|
||||
std::vector<cryptonote::tx_destination_entry> m_dests;
|
||||
crypto::hash m_payment_id;
|
||||
|
||||
confirmed_transfer_details(): m_amount_in(0), m_amount_out(0), m_change((uint64_t)-1), m_block_height(0), m_payment_id(cryptonote::null_hash) {}
|
||||
confirmed_transfer_details(const unconfirmed_transfer_details &utd, uint64_t height):
|
||||
m_amount_out(get_outs_money_amount(utd.m_tx)), m_change(utd.m_change), m_block_height(height) { get_inputs_money_amount(utd.m_tx, m_amount_in); }
|
||||
m_amount_out(get_outs_money_amount(utd.m_tx)), m_change(utd.m_change), m_block_height(height), m_dests(utd.m_dests), m_payment_id(utd.m_payment_id) { get_inputs_money_amount(utd.m_tx, m_amount_in); }
|
||||
};
|
||||
|
||||
typedef std::vector<transfer_details> transfer_container;
|
||||
@ -131,6 +136,7 @@ namespace tools
|
||||
std::list<transfer_container::iterator> selected_transfers;
|
||||
std::string key_images;
|
||||
crypto::secret_key tx_key;
|
||||
std::vector<cryptonote::tx_destination_entry> dests;
|
||||
};
|
||||
|
||||
struct keys_file_data
|
||||
@ -342,10 +348,11 @@ namespace tools
|
||||
bool prepare_file_names(const std::string& file_path);
|
||||
void process_unconfirmed(const cryptonote::transaction& tx, uint64_t height);
|
||||
void process_outgoing(const cryptonote::transaction& tx, uint64_t height, uint64_t spent, uint64_t received);
|
||||
void add_unconfirmed_tx(const cryptonote::transaction& tx, uint64_t change_amount);
|
||||
void add_unconfirmed_tx(const cryptonote::transaction& tx, const std::vector<cryptonote::tx_destination_entry> &dests, const crypto::hash &payment_id, uint64_t change_amount);
|
||||
void generate_genesis(cryptonote::block& b);
|
||||
void check_genesis(const crypto::hash& genesis_hash) const; //throws
|
||||
bool generate_chacha8_key_from_secret_keys(crypto::chacha8_key &key) const;
|
||||
crypto::hash get_payment_id(const pending_tx &ptx) const;
|
||||
|
||||
cryptonote::account_base m_account;
|
||||
std::string m_daemon_address;
|
||||
@ -377,7 +384,7 @@ namespace tools
|
||||
uint32_t m_default_mixin;
|
||||
};
|
||||
}
|
||||
BOOST_CLASS_VERSION(tools::wallet2, 9)
|
||||
BOOST_CLASS_VERSION(tools::wallet2, 10)
|
||||
|
||||
namespace boost
|
||||
{
|
||||
@ -400,6 +407,10 @@ namespace boost
|
||||
a & x.m_change;
|
||||
a & x.m_sent_time;
|
||||
a & x.m_tx;
|
||||
if (ver < 9)
|
||||
return;
|
||||
a & x.m_dests;
|
||||
a & x.m_payment_id;
|
||||
}
|
||||
|
||||
template <class Archive>
|
||||
@ -409,6 +420,10 @@ namespace boost
|
||||
a & x.m_amount_out;
|
||||
a & x.m_change;
|
||||
a & x.m_block_height;
|
||||
if (ver < 9)
|
||||
return;
|
||||
a & x.m_dests;
|
||||
a & x.m_payment_id;
|
||||
}
|
||||
|
||||
template <class Archive>
|
||||
@ -419,6 +434,13 @@ namespace boost
|
||||
a & x.m_block_height;
|
||||
a & x.m_unlock_time;
|
||||
}
|
||||
|
||||
template <class Archive>
|
||||
inline void serialize(Archive& a, cryptonote::tx_destination_entry& x, const boost::serialization::version_type ver)
|
||||
{
|
||||
a & x.amount;
|
||||
a & x.addr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -629,6 +651,7 @@ namespace tools
|
||||
ptx.change_dts = change_dts;
|
||||
ptx.selected_transfers = selected_transfers;
|
||||
ptx.tx_key = tx_key;
|
||||
ptx.dests = dsts;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user