wallet: use incoming blocks to keep track of payments too

This commit is contained in:
moneromooo-monero 2015-11-21 23:22:15 +00:00
parent 00790a8921
commit 725ae4e710
No known key found for this signature in database
GPG key ID: 686F07454D6CEFC3
3 changed files with 27 additions and 5 deletions

View file

@ -2055,7 +2055,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("%18.18s %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") % print_money(pd.m_amount) % string_tools::pod_to_hex(pd.m_tx_hash) % payment_id).str())));
}
}
@ -2065,14 +2065,16 @@ bool simple_wallet::show_transfers(const std::vector<std::string> &args_)
for (std::list<std::pair<crypto::hash, tools::wallet2::confirmed_transfer_details>>::const_iterator i = payments.begin(); i != payments.end(); ++i) {
const tools::wallet2::confirmed_transfer_details &pd = i->second;
uint64_t fee = pd.m_amount_in - pd.m_amount_out;
output.insert(std::make_pair(pd.m_block_height, std::make_pair(false, (boost::format("%18.18s %s") % print_money(pd.m_amount_in - pd.m_change - fee) % "-").str())));
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())));
}
}
// 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) {
message_writer(i->second.first ? epee::log_space::console_color_magenta : epee::log_space::console_color_green, false) <<
boost::format("[%8.8llu] %4.4s %s") %
boost::format("%8.8llu %6.6s %s") %
((unsigned long long)i->first) % (i->second.first ? tr("in") : tr("out")) % i->second.second;
}
@ -2084,7 +2086,7 @@ bool simple_wallet::show_transfers(const std::vector<std::string> &args_)
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] %4.4s %18.18s") % tr("pending") % tr("out") % print_money(amount - pd.m_change)).str();
message_writer() << (boost::format("%8.8s %6.6s %20.20s") % tr("pending") % tr("out") % print_money(amount - pd.m_change)).str();
}
}

View file

@ -270,7 +270,14 @@ void wallet2::process_new_transaction(const cryptonote::transaction& tx, uint64_
LOG_PRINT_L2("Found unencrypted payment ID: " << payment_id);
}
}
uint64_t received = (tx_money_spent_in_ins < tx_money_got_in_outs) ? tx_money_got_in_outs - tx_money_spent_in_ins : 0;
if (tx_money_spent_in_ins > 0)
{
process_outgoing(tx, height, tx_money_spent_in_ins, tx_money_got_in_outs);
}
if (0 < received)
{
payment_details payment;
@ -301,6 +308,18 @@ void wallet2::process_unconfirmed(const cryptonote::transaction& tx, uint64_t he
}
}
//----------------------------------------------------------------------------------------------------
void wallet2::process_outgoing(const cryptonote::transaction &tx, uint64_t height, uint64_t spent, uint64_t received)
{
crypto::hash txid = get_transaction_hash(tx);
confirmed_transfer_details &ctd = m_confirmed_txs[txid];
// operator[] creates if not found
// fill with the info we know, some info might already be there
ctd.m_amount_in = spent;
ctd.m_amount_out = get_outs_money_amount(tx);
ctd.m_change = received;
ctd.m_block_height = height;
}
//----------------------------------------------------------------------------------------------------
void wallet2::process_new_blockchain_entry(const cryptonote::block& b, cryptonote::block_complete_entry& bche, crypto::hash& bl_id, uint64_t height)
{
//handle transactions from new block

View file

@ -115,7 +115,7 @@ namespace tools
uint64_t m_amount_out;
uint64_t m_change;
uint64_t m_block_height;
confirmed_transfer_details() {}
confirmed_transfer_details(): m_amount_in(0), m_amount_out(0), m_change((uint64_t)-1), m_block_height(0) {}
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); }
};
@ -341,6 +341,7 @@ namespace tools
uint64_t select_transfers(uint64_t needed_money, bool add_dust, uint64_t dust, std::list<transfer_container::iterator>& selected_transfers);
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 generate_genesis(cryptonote::block& b);
void check_genesis(const crypto::hash& genesis_hash) const; //throws