...
 
Commits (2)
//17copyright
//17copyright
#include <random>
#include <tuple>
......@@ -1082,7 +1082,7 @@ void wallet2::process_new_blockchain_entry(const cryptonote::block& b, const cry
" not match with daemon response size=" + std::to_string(o_indices.indices.size()));
//handle transactions from new block
//optimization: seeking only for blocks that are not older then the wallet creation time plus 1 day. 1 day is for possible user incorrect time setup
if(b.timestamp + 60*60*24 > m_account.get_createtime() && height >= m_refresh_from_block_height)
{
......@@ -1646,7 +1646,7 @@ bool wallet2::add_address_book_row(const cryptonote::account_public_address &add
a.m_address = address;
a.m_payment_id = payment_id;
a.m_description = description;
auto old_size = m_address_book.size();
m_address_book.push_back(a);
if(m_address_book.size() == old_size+1)
......@@ -1657,7 +1657,7 @@ bool wallet2::add_address_book_row(const cryptonote::account_public_address &add
bool wallet2::delete_address_book_row(std::size_t row_id) {
if(m_address_book.size() <= row_id)
return false;
m_address_book.erase(m_address_book.begin()+row_id);
return true;
......@@ -3086,7 +3086,7 @@ std::vector<std::vector<cryptonote::tx_destination_entry>> split_amounts(
{
amount += dsts[j].amount % num_splits;
}
de.addr = dsts[j].addr;
de.amount = amount;
......@@ -3136,7 +3136,7 @@ crypto::hash8 wallet2::get_short_payment_id(const pending_tx &ptx) const
{
if(get_encrypted_payment_id_from_tx_extra_nonce(extra_nonce.nonce, payment_id8))
{
decrypt_payment_id(payment_id8, ptx.dests[0].addr.m_view_public_key, ptx.tx_key);
decrypt_payment_id(payment_id8, ptx.dests[0].addr.m_view_public_key, ptx.tx_key);
}
}
return payment_id8;
......@@ -3214,7 +3214,7 @@ bool wallet2::save_tx(const std::vector<pending_tx>& ptx_vector, const std::stri
for (auto &tx: ptx_vector)
{
tx_construction_data construction_data = tx.construction_data;
// Short payment id is encrypted with tx_key.
// Short payment id is encrypted with tx_key.
// Since sign_tx() generates new tx_keys and encrypts the payment id, we need to save the decrypted payment ID
// Get decrypted payment id from pending_tx
crypto::hash8 payment_id = get_short_payment_id(tx);
......@@ -3230,12 +3230,12 @@ bool wallet2::save_tx(const std::vector<pending_tx>& ptx_vector, const std::stri
LOG_ERROR("Failed to add decrypted payment id to tx extra");
return false;
}
LOG_PRINT_L1("Decrypted payment ID: " << payment_id);
LOG_PRINT_L1("Decrypted payment ID: " << payment_id);
}
// Save tx construction_data to unsigned_tx_set
txs.txes.push_back(construction_data);
txs.txes.push_back(construction_data);
}
txs.transfers = m_transfers;
// save as binary
std::ostringstream oss;
......@@ -3249,7 +3249,7 @@ bool wallet2::save_tx(const std::vector<pending_tx>& ptx_vector, const std::stri
return false;
}
LOG_PRINT_L2("Saving unsigned tx data: " << oss.str());
return epee::file_io_utils::save_string_to_file(filename, std::string(UNSIGNED_TX_PREFIX) + oss.str());
return epee::file_io_utils::save_string_to_file(filename, std::string(UNSIGNED_TX_PREFIX) + oss.str());
}
//----------------------------------------------------------------------------------------------------
bool wallet2::load_unsigned_tx(const std::string &unsigned_filename, unsigned_tx_set &exported_txs)
......@@ -3280,7 +3280,7 @@ bool wallet2::load_unsigned_tx(const std::string &unsigned_filename, unsigned_tx
boost::archive::portable_binary_iarchive ar(iss);
ar >> exported_txs;
}
catch (...)
catch (...)
{
LOG_PRINT_L0("Failed to parse data from " << unsigned_filename);
return false;
......@@ -3295,7 +3295,7 @@ bool wallet2::sign_tx(const std::string &unsigned_filename, const std::string &s
unsigned_tx_set exported_txs;
if(!load_unsigned_tx(unsigned_filename, exported_txs))
return false;
if (accept_func && !accept_func(exported_txs))
{
LOG_PRINT_L1("Transactions rejected by callback");
......@@ -3379,7 +3379,7 @@ bool wallet2::sign_tx(unsigned_tx_set &exported_txs, const std::string &signed_f
return false;
}
LOG_PRINT_L3("Saving signed tx data: " << oss.str());
return epee::file_io_utils::save_string_to_file(signed_filename, std::string(SIGNED_TX_PREFIX) + oss.str());
return epee::file_io_utils::save_string_to_file(signed_filename, std::string(SIGNED_TX_PREFIX) + oss.str());
}
//----------------------------------------------------------------------------------------------------
bool wallet2::load_tx(const std::string &signed_filename, std::vector<tools::wallet2::pending_tx> &ptx, std::function<bool(const signed_tx_set&)> accept_func)
......@@ -3858,7 +3858,7 @@ void wallet2::get_outs(std::vector<std::vector<tools::wallet2::get_outs_entry>>
}
template<typename T>
void wallet2::transfer_selected(const std::vector<cryptonote::tx_destination_entry>& dsts, const std::list<size_t> selected_transfers, size_t fake_outputs_count,
void wallet2::transfer_selected(const std::vector<cryptonote::tx_destination_entry>& dsts, const std::list<size_t> selected_transfers, size_t fake_outputs_count,
std::vector<std::vector<tools::wallet2::get_outs_entry>> &outs,
uint64_t unlock_time, uint64_t fee, const std::vector<uint8_t>& extra, T destination_split_strategy, const tx_dust_policy& dust_policy, cryptonote::transaction& tx, pending_tx &ptx)
{
......@@ -3973,11 +3973,11 @@ void wallet2::transfer_selected(const std::vector<cryptonote::tx_destination_ent
return true;
});
THROW_WALLET_EXCEPTION_IF(!all_are_txin_to_key, error::unexpected_txin_type, tx);
bool dust_sent_elsewhere = (dust_policy.addr_for_dust.m_view_public_key != change_dts.addr.m_view_public_key
|| dust_policy.addr_for_dust.m_spend_public_key != change_dts.addr.m_spend_public_key);
if (dust_policy.add_to_fee || dust_sent_elsewhere) change_dts.amount -= dust;
ptx.key_images = key_images;
......@@ -4352,7 +4352,8 @@ std::vector<wallet2::pending_tx> wallet2::create_transactions_2(std::vector<cryp
}
else
{
THROW_WALLET_EXCEPTION_IF(original_output_index > dsts.size(), error::wallet_internal_error, "original_output_index too large");
THROW_WALLET_EXCEPTION_IF(original_output_index > dsts.size(), error::wallet_internal_error,
std::string("original_output_index too large: ") + std::to_string(original_output_index) + " > " + std::to_string(dsts.size()));
if (original_output_index == dsts.size())
dsts.push_back(tx_destination_entry(0,addr));
THROW_WALLET_EXCEPTION_IF(memcmp(&dsts[original_output_index].addr, &addr, sizeof(addr)), error::wallet_internal_error, "Mismatched destination address");
......@@ -4630,6 +4631,7 @@ std::vector<wallet2::pending_tx> wallet2::create_transactions_2(std::vector<cryp
{
LOG_PRINT_L2("We have more to pay, starting another tx");
txes.push_back(TX());
original_output_index = 0;
}
}
}
......@@ -5209,7 +5211,7 @@ bool wallet2::export_key_images(const std::string filename)
// encrypt data, keep magic plaintext
std::string ciphertext = encrypt_with_view_secret_key(data);
return epee::file_io_utils::save_string_to_file(filename, magic + ciphertext);
return epee::file_io_utils::save_string_to_file(filename, magic + ciphertext);
}
//----------------------------------------------------------------------------------------------------
......@@ -5322,8 +5324,8 @@ uint64_t wallet2::import_key_images(const std::string &filename, uint64_t &spent
ski.push_back(std::make_pair(key_image, signature));
}
return import_key_images(ski, spent, unspent);
return import_key_images(ski, spent, unspent);
}
//----------------------------------------------------------------------------------------------------
......@@ -5766,7 +5768,7 @@ uint64_t wallet2::get_blockchain_height_by_date(uint16_t year, uint8_t month, ui
uint64_t timestamp_max = blk_max.timestamp;
if (!(timestamp_min <= timestamp_mid && timestamp_mid <= timestamp_max))
{
// the timestamps are not in the chronological order.
// the timestamps are not in the chronological order.
// assuming they're sufficiently close to each other, simply return the smallest height
return std::min({height_min, height_mid, height_max});
}
......