void AddressBookImpl::refresh() { LOG_PRINT_L2("Refreshing addressbook"); clearRows(); // Fetch from Wallet2 and create vector of AddressBookRow objects std::vector<tools::wallet2::address_book_row> rows = m_wallet->m_wallet->get_address_book(); for (size_t i = 0; i < rows.size(); ++i) { tools::wallet2::address_book_row * row = &rows.at(i); std::string payment_id = (row->m_payment_id == crypto::null_hash)? "" : epee::string_tools::pod_to_hex(row->m_payment_id); std::string address = cryptonote::get_account_address_as_str(m_wallet->m_wallet->testnet(), row->m_is_subaddress, row->m_address); // convert the zero padded short payment id to integrated address if (!row->m_is_subaddress && payment_id.length() > 16 && payment_id.substr(16).find_first_not_of('0') == std::string::npos) { payment_id = payment_id.substr(0,16); crypto::hash8 payment_id_short; if(tools::wallet2::parse_short_payment_id(payment_id, payment_id_short)) { address = cryptonote::get_account_integrated_address_as_str(m_wallet->m_wallet->testnet(), row->m_address, payment_id_short); // Don't show payment id when integrated address is used payment_id = ""; } } AddressBookRow * abr = new AddressBookRow(i, address, payment_id, row->m_description); m_rows.push_back(abr); } }
//----------------------------------------------------------------------------------------------- //bool core::get_outs(uint64_t amount, std::list<crypto::public_key>& pkeys) //{ // return m_blockchain_storage.get_outs(amount, pkeys); //} //----------------------------------------------------------------------------------------------- bool core::add_new_tx(const Transaction& tx, const crypto::hash& tx_hash, const crypto::hash& tx_prefix_hash, size_t blob_size, tx_verification_context& tvc, bool keeped_by_block) { if (m_blockchain_storage.have_tx(tx_hash)) { LOG_PRINT_L2("tx " << tx_hash << " is already in blockchain"); return true; } // It's not very good to lock on m_mempool here, because it's very hard to understand the order of locking // tx_memory_pool::m_transactions_lock, blockchain_storage::m_blockchain_lock, and core::m_incoming_tx_lock CRITICAL_REGION_LOCAL(m_mempool); if (m_mempool.have_tx(tx_hash)) { LOG_PRINT_L2("tx " << tx_hash << " is already in transaction pool"); return true; } return m_mempool.add_tx(tx, tx_hash, blob_size, tvc, keeped_by_block); }
bool AddressBookImpl::deleteRow(std::size_t rowId) { LOG_PRINT_L2("Deleting address book row " << rowId); bool r = m_wallet->m_wallet->delete_address_book_row(rowId); if (r) refresh(); return r; }
//--------------------------------------------------------------------------------- bool tx_memory_pool::have_tx_keyimges_as_spent(const transaction& tx) { CRITICAL_REGION_LOCAL(m_transactions_lock); BOOST_FOREACH(const auto& in, tx.vin) { CHECKED_GET_SPECIFIC_VARIANT(in, const txin_to_key, tokey_in, true);//should never fail if (have_tx_keyimg_as_spent(tokey_in.k_image)) { LOG_PRINT_L2("tx_memory_pool: key img spent: " << tokey_in.k_image << ", amount: " << tokey_in.amount); std::stringstream ss; ss << "keyoffsets: "; BOOST_FOREACH(const auto& of, tokey_in.key_offsets) { ss << of << " "; } LOG_PRINT_L2(ss.str()); return true; } }
void SubaddressAccountImpl::refresh() { LOG_PRINT_L2("Refreshing subaddress account"); clearRows(); for (uint32_t i = 0; i < m_wallet->m_wallet->get_num_subaddress_accounts(); ++i) { m_rows.push_back(new SubaddressAccountRow( i, m_wallet->m_wallet->get_subaddress_as_str({i,0}), m_wallet->m_wallet->get_subaddress_label({i,0}), cryptonote::print_money(m_wallet->m_wallet->balance(i)), cryptonote::print_money(m_wallet->m_wallet->unlocked_balance(i)) )); } }
//--------------------------------------------------------------------------------- bool tx_memory_pool::add_alias_tx_pair(std::string & alias, crypto::hash id) { //check alias repeat or not if (alias.size()) { CRITICAL_REGION_LOCAL(m_aliases_lock); crypto::hash h = find_alias(alias); if (h != null_hash) { LOG_ERROR("the same alias " << alias << " exists in pool, id: " << h << ", so tx: " << id << " can't be added to pool."); return false; } m_aliases_to_txid[alias] = id; LOG_PRINT_L2("Add alias: " << alias << " into pool with tx: " << id); } return true; }
//--------------------------------------------------------------------------------- bool tx_memory_pool::remove_stuck_transactions() { LOG_PRINT_L2("tx_memory_pool::remove_stuck_transactions()"); CRITICAL_REGION_LOCAL(m_transactions_lock); for (auto it = m_transactions.begin(); it != m_transactions.end();) { uint64_t tx_age = time(nullptr) - it->second.receive_time; if ((tx_age > CURRENCY_MEMPOOL_TX_LIVETIME && !it->second.kept_by_block) || (tx_age > CURRENCY_MEMPOOL_TX_FROM_ALT_BLOCK_LIVETIME && it->second.kept_by_block)) { LOG_PRINT_L0("Tx " << it->first << " removed from tx pool due to outdated, age: " << tx_age); remove_alias_tx_pair(it->first); remove_transaction_keyimages(it->second.tx); m_transactions.erase(it++); } else ++it; } return true; }
//--------------------------------------------------------------- bool construct_tx_and_get_tx_key(const account_keys& sender_account_keys, const std::vector<tx_source_entry>& sources, const std::vector<tx_destination_entry>& destinations, std::vector<uint8_t> extra, transaction& tx, uint64_t unlock_time, crypto::secret_key &tx_key, bool rct) { std::vector<rct::key> amount_keys; tx.set_null(); amount_keys.clear(); tx.version = rct ? 2 : 1; tx.unlock_time = unlock_time; tx.extra = extra; keypair txkey = keypair::generate(); remove_field_from_tx_extra(tx.extra, typeid(tx_extra_pub_key)); add_tx_pub_key_to_extra(tx, txkey.pub); tx_key = txkey.sec; // if we have a stealth payment id, find it and encrypt it with the tx key now std::vector<tx_extra_field> tx_extra_fields; if (parse_tx_extra(tx.extra, tx_extra_fields)) { tx_extra_nonce extra_nonce; if (find_tx_extra_field_by_type(tx_extra_fields, extra_nonce)) { crypto::hash8 payment_id = null_hash8; if (get_encrypted_payment_id_from_tx_extra_nonce(extra_nonce.nonce, payment_id)) { LOG_PRINT_L2("Encrypting payment id " << payment_id); crypto::public_key view_key_pub = get_destination_view_key_pub(destinations, sender_account_keys); if (view_key_pub == null_pkey) { LOG_ERROR("Destinations have to have exactly one output to support encrypted payment ids"); return false; } if (!encrypt_payment_id(payment_id, view_key_pub, txkey.sec)) { LOG_ERROR("Failed to encrypt payment id"); return false; } std::string extra_nonce; set_encrypted_payment_id_to_tx_extra_nonce(extra_nonce, payment_id); remove_field_from_tx_extra(tx.extra, typeid(tx_extra_nonce)); if (!add_extra_nonce_to_tx_extra(tx.extra, extra_nonce)) { LOG_ERROR("Failed to add encrypted payment id to tx extra"); return false; } LOG_PRINT_L1("Encrypted payment ID: " << payment_id); } } } else { LOG_ERROR("Failed to parse tx extra"); return false; } struct input_generation_context_data { keypair in_ephemeral; }; std::vector<input_generation_context_data> in_contexts; uint64_t summary_inputs_money = 0; //fill inputs int idx = -1; for(const tx_source_entry& src_entr: sources) { ++idx; if(src_entr.real_output >= src_entr.outputs.size()) { LOG_ERROR("real_output index (" << src_entr.real_output << ")bigger than output_keys.size()=" << src_entr.outputs.size()); return false; } summary_inputs_money += src_entr.amount; //key_derivation recv_derivation; in_contexts.push_back(input_generation_context_data()); keypair& in_ephemeral = in_contexts.back().in_ephemeral; crypto::key_image img; if(!generate_key_image_helper(sender_account_keys, src_entr.real_out_tx_key, src_entr.real_output_in_tx_index, in_ephemeral, img)) return false; //check that derivated key is equal with real output key if( !(in_ephemeral.pub == src_entr.outputs[src_entr.real_output].second.dest) ) { LOG_ERROR("derived public key mismatch with output public key at index " << idx << ", real out " << src_entr.real_output << "! "<< ENDL << "derived_key:" << string_tools::pod_to_hex(in_ephemeral.pub) << ENDL << "real output_public_key:" << string_tools::pod_to_hex(src_entr.outputs[src_entr.real_output].second) ); LOG_ERROR("amount " << src_entr.amount << ", rct " << src_entr.rct); LOG_ERROR("tx pubkey " << src_entr.real_out_tx_key << ", real_output_in_tx_index " << src_entr.real_output_in_tx_index); return false; } //put key image into tx input txin_to_key input_to_key; input_to_key.amount = src_entr.amount; input_to_key.k_image = img; //fill outputs array and use relative offsets for(const tx_source_entry::output_entry& out_entry: src_entr.outputs) input_to_key.key_offsets.push_back(out_entry.first); input_to_key.key_offsets = absolute_output_offsets_to_relative(input_to_key.key_offsets); tx.vin.push_back(input_to_key); } // "Shuffle" outs std::vector<tx_destination_entry> shuffled_dsts(destinations); std::sort(shuffled_dsts.begin(), shuffled_dsts.end(), [](const tx_destination_entry& de1, const tx_destination_entry& de2) { return de1.amount < de2.amount; } ); uint64_t summary_outs_money = 0; //fill outputs size_t output_index = 0; for(const tx_destination_entry& dst_entr: shuffled_dsts) { CHECK_AND_ASSERT_MES(dst_entr.amount > 0 || tx.version > 1, false, "Destination with wrong amount: " << dst_entr.amount); crypto::key_derivation derivation; crypto::public_key out_eph_public_key; bool r = crypto::generate_key_derivation(dst_entr.addr.m_view_public_key, txkey.sec, derivation); CHECK_AND_ASSERT_MES(r, false, "at creation outs: failed to generate_key_derivation(" << dst_entr.addr.m_view_public_key << ", " << txkey.sec << ")"); if (tx.version > 1) { crypto::secret_key scalar1; crypto::derivation_to_scalar(derivation, output_index, scalar1); amount_keys.push_back(rct::sk2rct(scalar1)); } r = crypto::derive_public_key(derivation, output_index, dst_entr.addr.m_spend_public_key, out_eph_public_key); CHECK_AND_ASSERT_MES(r, false, "at creation outs: failed to derive_public_key(" << derivation << ", " << output_index << ", "<< dst_entr.addr.m_spend_public_key << ")"); tx_out out; out.amount = dst_entr.amount; txout_to_key tk; tk.key = out_eph_public_key; out.target = tk; tx.vout.push_back(out); output_index++; summary_outs_money += dst_entr.amount; } //check money if(summary_outs_money > summary_inputs_money ) { LOG_ERROR("Transaction inputs money ("<< summary_inputs_money << ") less than outputs money (" << summary_outs_money << ")"); return false; } // check for watch only wallet bool zero_secret_key = true; for (size_t i = 0; i < sizeof(sender_account_keys.m_spend_secret_key); ++i) zero_secret_key &= (sender_account_keys.m_spend_secret_key.data[i] == 0); if (zero_secret_key) { MDEBUG("Null secret key, skipping signatures"); } if (tx.version == 1) { //generate ring signatures crypto::hash tx_prefix_hash; get_transaction_prefix_hash(tx, tx_prefix_hash); std::stringstream ss_ring_s; size_t i = 0; for(const tx_source_entry& src_entr: sources) { ss_ring_s << "pub_keys:" << ENDL; std::vector<const crypto::public_key*> keys_ptrs; std::vector<crypto::public_key> keys(src_entr.outputs.size()); size_t ii = 0; for(const tx_source_entry::output_entry& o: src_entr.outputs) { keys[ii] = rct2pk(o.second.dest); keys_ptrs.push_back(&keys[ii]); ss_ring_s << o.second.dest << ENDL; ++ii; } tx.signatures.push_back(std::vector<crypto::signature>()); std::vector<crypto::signature>& sigs = tx.signatures.back(); sigs.resize(src_entr.outputs.size()); if (!zero_secret_key) crypto::generate_ring_signature(tx_prefix_hash, boost::get<txin_to_key>(tx.vin[i]).k_image, keys_ptrs, in_contexts[i].in_ephemeral.sec, src_entr.real_output, sigs.data()); ss_ring_s << "signatures:" << ENDL; std::for_each(sigs.begin(), sigs.end(), [&](const crypto::signature& s){ss_ring_s << s << ENDL;}); ss_ring_s << "prefix_hash:" << tx_prefix_hash << ENDL << "in_ephemeral_key: " << in_contexts[i].in_ephemeral.sec << ENDL << "real_output: " << src_entr.real_output << ENDL; i++; } MCINFO("construct_tx", "transaction_created: " << get_transaction_hash(tx) << ENDL << obj_to_json_str(tx) << ENDL << ss_ring_s.str()); } else { size_t n_total_outs = sources[0].outputs.size(); // only for non-simple rct // the non-simple version is slightly smaller, but assumes all real inputs // are on the same index, so can only be used if there just one ring. bool use_simple_rct = sources.size() > 1; if (!use_simple_rct) { // non simple ringct requires all real inputs to be at the same index for all inputs for(const tx_source_entry& src_entr: sources) { if(src_entr.real_output != sources.begin()->real_output) { LOG_ERROR("All inputs must have the same index for non-simple ringct"); return false; } } // enforce same mixin for all outputs for (size_t i = 1; i < sources.size(); ++i) { if (n_total_outs != sources[i].outputs.size()) { LOG_ERROR("Non-simple ringct transaction has varying mixin"); return false; } } } uint64_t amount_in = 0, amount_out = 0; rct::ctkeyV inSk; // mixRing indexing is done the other way round for simple rct::ctkeyM mixRing(use_simple_rct ? sources.size() : n_total_outs); rct::keyV destinations; std::vector<uint64_t> inamounts, outamounts; std::vector<unsigned int> index; for (size_t i = 0; i < sources.size(); ++i) { rct::ctkey ctkey; amount_in += sources[i].amount; inamounts.push_back(sources[i].amount); index.push_back(sources[i].real_output); // inSk: (secret key, mask) ctkey.dest = rct::sk2rct(in_contexts[i].in_ephemeral.sec); ctkey.mask = sources[i].mask; inSk.push_back(ctkey); // inPk: (public key, commitment) // will be done when filling in mixRing } for (size_t i = 0; i < tx.vout.size(); ++i) { destinations.push_back(rct::pk2rct(boost::get<txout_to_key>(tx.vout[i].target).key)); outamounts.push_back(tx.vout[i].amount); amount_out += tx.vout[i].amount; } if (use_simple_rct) { // mixRing indexing is done the other way round for simple for (size_t i = 0; i < sources.size(); ++i) { mixRing[i].resize(sources[i].outputs.size()); for (size_t n = 0; n < sources[i].outputs.size(); ++n) { mixRing[i][n] = sources[i].outputs[n].second; } } } else { for (size_t i = 0; i < n_total_outs; ++i) // same index assumption { mixRing[i].resize(sources.size()); for (size_t n = 0; n < sources.size(); ++n) { mixRing[i][n] = sources[n].outputs[i].second; } } } // fee if (!use_simple_rct && amount_in > amount_out) outamounts.push_back(amount_in - amount_out); // zero out all amounts to mask rct outputs, real amounts are now encrypted for (size_t i = 0; i < tx.vin.size(); ++i) { if (sources[i].rct) boost::get<txin_to_key>(tx.vin[i]).amount = 0; } for (size_t i = 0; i < tx.vout.size(); ++i) tx.vout[i].amount = 0; crypto::hash tx_prefix_hash; get_transaction_prefix_hash(tx, tx_prefix_hash); rct::ctkeyV outSk; if (use_simple_rct) tx.rct_signatures = rct::genRctSimple(rct::hash2rct(tx_prefix_hash), inSk, destinations, inamounts, outamounts, amount_in - amount_out, mixRing, amount_keys, index, outSk); else tx.rct_signatures = rct::genRct(rct::hash2rct(tx_prefix_hash), inSk, destinations, outamounts, mixRing, amount_keys, sources[0].real_output, outSk); // same index assumption CHECK_AND_ASSERT_MES(tx.vout.size() == outSk.size(), false, "outSk size does not match vout"); MCINFO("construct_tx", "transaction_created: " << get_transaction_hash(tx) << ENDL << obj_to_json_str(tx) << ENDL); } tx.invalidate_hashes(); return true; }
bool load_txt_records_from_dns(std::vector<std::string> &good_records, const std::vector<std::string> &dns_urls) { // Prevent infinite recursion when distributing if (dns_urls.empty()) return false; std::vector<std::vector<std::string> > records; records.resize(dns_urls.size()); std::random_device rd; std::mt19937 gen(rd()); std::uniform_int_distribution<int> dis(0, dns_urls.size() - 1); size_t first_index = dis(gen); // send all requests in parallel std::vector<boost::thread> threads(dns_urls.size()); std::deque<bool> avail(dns_urls.size(), false), valid(dns_urls.size(), false); for (size_t n = 0; n < dns_urls.size(); ++n) { threads[n] = boost::thread([n, dns_urls, &records, &avail, &valid](){ records[n] = tools::DNSResolver::instance().get_txt_record(dns_urls[n], avail[n], valid[n]); }); } for (size_t n = 0; n < dns_urls.size(); ++n) threads[n].join(); size_t cur_index = first_index; do { const std::string &url = dns_urls[cur_index]; if (!avail[cur_index]) { records[cur_index].clear(); LOG_PRINT_L2("DNSSEC not available for checkpoint update at URL: " << url << ", skipping."); } if (!valid[cur_index]) { records[cur_index].clear(); LOG_PRINT_L2("DNSSEC validation failed for checkpoint update at URL: " << url << ", skipping."); } cur_index++; if (cur_index == dns_urls.size()) { cur_index = 0; } } while (cur_index != first_index); size_t num_valid_records = 0; for( const auto& record_set : records) { if (record_set.size() != 0) { num_valid_records++; } } if (num_valid_records < 2) { LOG_PRINT_L0("WARNING: no two valid MoneroPulse DNS checkpoint records were received"); return false; } int good_records_index = -1; for (size_t i = 0; i < records.size() - 1; ++i) { if (records[i].size() == 0) continue; for (size_t j = i + 1; j < records.size(); ++j) { if (dns_records_match(records[i], records[j])) { good_records_index = i; break; } } if (good_records_index >= 0) break; } if (good_records_index < 0) { LOG_PRINT_L0("WARNING: no two MoneroPulse DNS checkpoint records matched"); return false; } good_records = records[good_records_index]; return true; }
//--------------------------------------------------------------------------------- bool tx_memory_pool::add_tx(const transaction &tx, const crypto::hash &id, tx_verification_context& tvc, bool kept_by_block, std::string alias) { size_t blob_size = get_object_blobsize(tx); //#9Protection from big transaction flood if (!kept_by_block && blob_size > currency::get_max_transaction_blob_size(m_blockchain.get_current_blockchain_height())) { LOG_PRINT_L0("transaction is too big (" << blob_size << ")bytes for current transaction flow, tx_id: " << id); tvc.m_verifivation_failed = true; return false; } if (!check_inputs_types_supported(tx)) { tvc.m_verifivation_failed = true; return false; } uint64_t inputs_amount = 0; if (!get_inputs_money_amount(tx, inputs_amount)) { tvc.m_verifivation_failed = true; return false; } uint64_t outputs_amount = get_outs_money_amount(tx); if (outputs_amount >= inputs_amount) { LOG_PRINT_L0("transaction use more money then it has: use " << outputs_amount << ", have " << inputs_amount); tvc.m_verifivation_failed = true; return false; } //check key images for transaction if it is not kept by blockhave_tx_keyimges_as_spent if (!kept_by_block) { if (have_tx_keyimges_as_spent(tx)) { LOG_ERROR("Transaction with id= " << id << " used already spent key images"); tvc.m_verifivation_failed = true; return false; } //transaction spam protection, soft rule if (inputs_amount - outputs_amount < TX_POOL_MINIMUM_FEE) { LOG_ERROR("Transaction with id= " << id << " has too small fee: " << inputs_amount - outputs_amount << ", expected fee: " << DEFAULT_FEE); tvc.m_verifivation_failed = true; return false; } } crypto::hash max_used_block_id = null_hash; uint64_t max_used_block_height = 0; bool ch_inp_res = m_blockchain.check_tx_inputs(tx, max_used_block_height, max_used_block_id); CRITICAL_REGION_LOCAL(m_transactions_lock); if (!ch_inp_res) { if (kept_by_block) { //if there is a same alias on the block, then delete the tx with the same alias in the pool crypto::hash hash; if (alias.size() && (hash = find_alias(alias)) != null_hash) { transaction tx = AUTO_VAL_INIT(tx); size_t size = 0; uint64_t fee = 0; take_tx(hash, tx, size, fee); LOG_PRINT_L2("Found alias " << alias << " in block, delete pool tx with the same alias: " << id); } //anyway add this transaction to pool, because it related to block auto txd_p = m_transactions.insert(transactions_container::value_type(id, tx_details())); if (!txd_p.second) { return false; } //CHECK_AND_ASSERT_MES(txd_p.second, false, "transaction already exists at inserting in memory pool"); txd_p.first->second.blob_size = blob_size; txd_p.first->second.tx = tx; txd_p.first->second.fee = inputs_amount - outputs_amount; txd_p.first->second.max_used_block_id = null_hash; txd_p.first->second.max_used_block_height = 0; txd_p.first->second.kept_by_block = kept_by_block; txd_p.first->second.receive_time = time(nullptr); tvc.m_verifivation_impossible = true; tvc.m_added_to_pool = true; } else { LOG_PRINT_L0("tx used wrong inputs, rejected"); tvc.m_verifivation_failed = true; return false; } } else { //check alias repeat or not if (!add_alias_tx_pair(alias, id)) { tvc.m_verifivation_failed = true; tvc.m_added_to_pool = false; return false; } //update transactions container auto txd_p = m_transactions.insert(transactions_container::value_type(id, tx_details())); if (!txd_p.second) { return false; } //CHECK_AND_ASSERT_MES(txd_p.second, false, "intrnal error: transaction already exists at inserting in memorypool"); txd_p.first->second.blob_size = blob_size; txd_p.first->second.tx = tx; txd_p.first->second.kept_by_block = kept_by_block; txd_p.first->second.fee = inputs_amount - outputs_amount; txd_p.first->second.max_used_block_id = max_used_block_id; txd_p.first->second.max_used_block_height = max_used_block_height; txd_p.first->second.last_failed_height = 0; txd_p.first->second.last_failed_id = null_hash; txd_p.first->second.receive_time = time(nullptr); tvc.m_added_to_pool = true; if (txd_p.first->second.fee > 0) tvc.m_should_be_relayed = true; } tvc.m_verifivation_failed = true; //update image_keys container, here should everything goes ok. BOOST_FOREACH(const auto& in, tx.vin) { CHECKED_GET_SPECIFIC_VARIANT(in, const txin_to_key, txin, false); std::unordered_set<crypto::hash>& kei_image_set = m_spent_key_images[txin.k_image]; CHECK_AND_ASSERT_MES(kept_by_block || kei_image_set.size() == 0, false, "internal error: keeped_by_block=" << kept_by_block << ", kei_image_set.size()=" << kei_image_set.size() << ENDL << "txin.k_image=" << txin.k_image << ENDL << "tx_id=" << id); auto ins_res = kei_image_set.insert(id); CHECK_AND_ASSERT_MES(ins_res.second, false, "internal error: try to insert duplicate iterator in key_image set"); } tvc.m_verifivation_failed = false; //succeed return true; }
/* Update our model of the wallet incrementally, to synchronize our model of the wallet with that of the core. Call with transaction that was added, removed or changed. */ void updateWallet(const std::string &hash, int status) { LOG_PRINT_L2("TransactionTablePriv::updateWallet : " << hash << " " << status); { LOG_PRINT_L4("LOCK2(cs_main, wallet->cs_wallet) updateWallet"); LOCK2(cs_main, wallet->cs_wallet); LOG_PRINT_L4("LOCK2(cs_main, wallet->cs_wallet) updateWallet acquired"); // Find transaction in wallet auto mi = wallet->mapWallet.find(GetCryptoHash(hash)); bool inWallet = mi != wallet->mapWallet.end(); // Find bounds of this transaction in model QList<TransactionRecord>::iterator lower = qLowerBound( cachedWallet.begin(), cachedWallet.end(), hash, TxLessThan()); QList<TransactionRecord>::iterator upper = qUpperBound( cachedWallet.begin(), cachedWallet.end(), hash, TxLessThan()); int lowerIndex = (lower - cachedWallet.begin()); int upperIndex = (upper - cachedWallet.begin()); bool inModel = (lower != upper); // Determine whether to show transaction or not bool showTransaction = (inWallet && TransactionRecord::showTransaction(mi->second)); if(status == CT_UPDATED) { if(showTransaction && !inModel) status = CT_NEW; /* Not in model, but want to show, treat as new */ if(!showTransaction && inModel) status = CT_DELETED; /* In model, but want to hide, treat as deleted */ } //qDebug() << " inWallet=" + QString::number(inWallet) + " inModel=" + QString::number(inModel) + // " Index=" + QString::number(lowerIndex) + "-" + QString::number(upperIndex) + // " showTransaction=" + QString::number(showTransaction) + " derivedStatus=" + QString::number(status); switch(status) { case CT_NEW: if(inModel) { LOG_PRINT_L1("TransactionTablePriv::updateWallet : Warning: Got CT_NEW, but transaction is already in model"); break; } if(!inWallet) { LOG_PRINT_L1("TransactionTablePriv::updateWallet : Warning: Got CT_NEW, but transaction is not in wallet"); break; } if(showTransaction) { // Added -- insert at the right position QList<TransactionRecord> toInsert = TransactionRecord::decomposeTransaction(wallet, mi->second); if(!toInsert.isEmpty()) // only if something to insert { parent->beginInsertRows(QModelIndex(), lowerIndex, lowerIndex+toInsert.size()-1); int insert_idx = lowerIndex; foreach(const TransactionRecord &rec, toInsert) { cachedWallet.insert(insert_idx, rec); insert_idx += 1; } parent->endInsertRows(); } } break; case CT_DELETED: if(!inModel) { LOG_PRINT_L1("TransactionTablePriv::updateWallet : Warning: Got CT_DELETED, but transaction is not in model"); break; } // Removed -- remove entire transaction from table parent->beginRemoveRows(QModelIndex(), lowerIndex, upperIndex-1); cachedWallet.erase(lower, upper); parent->endRemoveRows(); break; case CT_UPDATED: // Miscellaneous updates -- nothing to do, status update will take care of this, and is only computed for // visible transactions. break; }