diff --git a/CMakeLists.txt b/CMakeLists.txt index 0e3dfd7..e3d2537 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -173,6 +173,10 @@ set_target_properties(cryptonote_core PROPERTIES IMPORTED_LOCATION add_library(cryptonote_basic STATIC IMPORTED) set_target_properties(cryptonote_basic PROPERTIES IMPORTED_LOCATION ${MONERO_PROJECT_BUILD}/src/cryptonote_basic/libcryptonote_basic.a) + +add_library(cryptonote_format_utils_basic STATIC IMPORTED) +set_target_properties(cryptonote_format_utils_basic PROPERTIES IMPORTED_LOCATION + ${MONERO_PROJECT_BUILD}/src/cryptonote_basic/libcryptonote_format_utils_basic.a) add_library(mnemonics STATIC IMPORTED) set_target_properties(mnemonics PROPERTIES IMPORTED_LOCATION @@ -257,6 +261,7 @@ if (BUILD_LIBRARY) cryptonote_core cryptonote_basic + cryptonote_format_utils_basic mnemonics ringct ringct_basic @@ -280,7 +285,7 @@ if (BUILD_LIBRARY) endif() ######################## -# Build C++ Sample Code +# Build C++ sample Code ######################## if (BUILD_SAMPLE) @@ -301,6 +306,7 @@ if (BUILD_SAMPLE) cryptonote_core cryptonote_basic + cryptonote_format_utils_basic mnemonics ringct ringct_basic @@ -345,6 +351,7 @@ if (BUILD_SCRATCHPAD) cryptonote_core cryptonote_basic + cryptonote_format_utils_basic mnemonics ringct ringct_basic diff --git a/README.md b/README.md index 3e7e05e..28e8194 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Monero C++ Library -A C++ library for creating Monero applications using native bindings to [monero v0.17.1.9 'Oxygen Orion'](https://github.com/monero-project/monero/tree/v0.17.1.9). +A C++ library for creating Monero applications using native bindings to [monero v0.17.2.0 'Oxygen Orion'](https://github.com/monero-project/monero/tree/v0.17.2.0). * Supports fully client-side wallets by wrapping [wallet2.h](https://github.com/monero-project/monero/blob/master/src/wallet/wallet2.h). * Supports multisig, view-only, and offline wallets. @@ -20,8 +20,6 @@ A C++ library for creating Monero applications using native bindings to [monero ## Sample code -_Note: This API might change depending on feedback, such as changing structs to classes, using pure object-oriented accessors and mutators, not using boost::optional with shared_ptrs, etc. Feedback is welcome._ - ```c++ // create a wallet from a mnemonic phrase string mnemonic = "hefty value later extra artistic firm radar yodel talent future fungal nutshell because sanity awesome nail unjustly rage unafraid cedar delayed thumbs comb custom sanity"; @@ -171,7 +169,7 @@ wallet_random->close(true); ## Documentation * [API documentation](https://moneroecosystem.org/monero-cpp/annotated.html) -* [API and model overview with visual diagrams](http://moneroecosystem.org/monero-java/monero-spec.pdf) +* [API and model overview with visual diagrams](https://moneroecosystem.org/monero-java/monero-spec.pdf) * [monero-javascript documentation](https://github.com/monero-ecosystem/monero-javascript#documentation) provides additional documentation which translates to monero-cpp ## Using this library in your project diff --git a/external/monero-project b/external/monero-project index d3fd7d3..cd20d87 160000 --- a/external/monero-project +++ b/external/monero-project @@ -1 +1 @@ -Subproject commit d3fd7d37f5a06758984abc09415d1555d544df19 +Subproject commit cd20d87dba178e3b35230781f75df4998cb81562 diff --git a/src/daemon/monero_daemon_model.cpp b/src/daemon/monero_daemon_model.cpp index c416e80..47aac08 100644 --- a/src/daemon/monero_daemon_model.cpp +++ b/src/daemon/monero_daemon_model.cpp @@ -300,7 +300,7 @@ namespace monero { for (boost::property_tree::ptree::const_iterator it = node.begin(); it != node.end(); ++it) { std::string key = it->first; if (key == std::string("hash")) tx->m_hash = it->second.data(); - else if (key == std::string("version")) throw std::runtime_error("version deserializationn not implemented"); + else if (key == std::string("version")) throw std::runtime_error("version deserialization not implemented"); else if (key == std::string("isMinerTx")) tx->m_is_miner_tx = it->second.get_value(); else if (key == std::string("paymentId")) tx->m_payment_id = it->second.data(); else if (key == std::string("fee")) tx->m_fee = it->second.get_value(); @@ -321,8 +321,8 @@ namespace monero { else if (key == std::string("prunableHash")) tx->m_prunable_hash = it->second.data(); else if (key == std::string("size")) tx->m_size = it->second.get_value(); else if (key == std::string("weight")) tx->m_weight = it->second.get_value(); - else if (key == std::string("inputs")) throw std::runtime_error("inputs deserializationn not implemented"); - else if (key == std::string("outputs")) throw std::runtime_error("outputs deserializationn not implemented"); + else if (key == std::string("inputs")) throw std::runtime_error("inputs deserialization not implemented"); + else if (key == std::string("outputs")) throw std::runtime_error("outputs deserialization not implemented"); else if (key == std::string("outputIndices")) throw std::runtime_error("m_output_indices deserialization not implemented"); else if (key == std::string("metadata")) tx->m_metadata = it->second.data(); else if (key == std::string("commonTxSets")) throw std::runtime_error("commonTxSets deserialization not implemented"); @@ -379,7 +379,7 @@ namespace monero { tgt->m_outputs.push_back(output_copy); } } - if (!src->m_output_indices.empty()) tgt->m_output_indices = std::vector(src->m_output_indices); + if (!src->m_output_indices.empty()) tgt->m_output_indices = std::vector(src->m_output_indices); tgt->m_metadata = src->m_metadata; tgt->m_common_tx_sets = src->m_common_tx_sets; if (!src->m_extra.empty()) throw std::runtime_error("extra deep copy not implemented"); // TODO: implement extra diff --git a/src/daemon/monero_daemon_model.h b/src/daemon/monero_daemon_model.h index ffba465..8bbd2a5 100644 --- a/src/daemon/monero_daemon_model.h +++ b/src/daemon/monero_daemon_model.h @@ -192,7 +192,7 @@ namespace monero { boost::optional m_weight; std::vector> m_inputs; std::vector> m_outputs; - std::vector m_output_indices; + std::vector m_output_indices; boost::optional m_metadata; boost::optional m_common_tx_sets; std::vector m_extra; diff --git a/src/wallet/monero_wallet.h b/src/wallet/monero_wallet.h index 7a2882f..742e8d3 100644 --- a/src/wallet/monero_wallet.h +++ b/src/wallet/monero_wallet.h @@ -787,6 +787,34 @@ namespace monero { throw std::runtime_error("import_key_images() not supported"); } + /** + * Freeze an output. + * + * @param key_image key image of the output to freeze + */ + virtual void freeze_output(const std::string& key_image) { + throw std::runtime_error("freeze_output() not supported"); + } + + /** + * Thaw a frozen output. + * + * @param key_image key image of the output to thaw + */ + virtual void thaw_output(const std::string& key_image) { + throw std::runtime_error("thaw_output() not supported"); + } + + /** + * Check if an output is frozen. + * + * @param key_image key image of the output to check if frozen + * @return true if the output is frozen, false otherwise + */ + virtual bool is_output_frozen(const std::string& key_image) { + throw std::runtime_error("is_output_frozen() not supported"); + } + /** * Create a transaction to transfer funds from this wallet. * diff --git a/src/wallet/monero_wallet_full.cpp b/src/wallet/monero_wallet_full.cpp index 538f513..c54e819 100644 --- a/src/wallet/monero_wallet_full.cpp +++ b/src/wallet/monero_wallet_full.cpp @@ -81,6 +81,15 @@ namespace monero { // ----------------------- INTERNAL PRIVATE HELPERS ----------------------- + struct key_image_list + { + std::list key_images; + + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE(key_images) + END_KV_SERIALIZE_MAP() + }; + /** * Remove query criteria which require looking up other transfers/outputs to * fulfill query. @@ -92,6 +101,7 @@ namespace monero { query->m_is_incoming = boost::none; query->m_is_outgoing = boost::none; query->m_transfer_query = boost::none; + query->m_input_query = boost::none; query->m_output_query = boost::none; return query; } @@ -100,6 +110,7 @@ namespace monero { if (query.m_tx_query == boost::none) return false; if (query.m_tx_query.get()->m_is_incoming != boost::none) return true; // requires context of all transfers if (query.m_tx_query.get()->m_is_outgoing != boost::none) return true; + if (query.m_tx_query.get()->m_input_query != boost::none) return true; // requires context of inputs if (query.m_tx_query.get()->m_output_query != boost::none) return true; // requires context of outputs return false; } @@ -370,7 +381,7 @@ namespace monero { output->m_subaddress_index = td.m_subaddr_index.minor; output->m_is_spent = td.m_spent; output->m_is_frozen = td.m_frozen; - //output->m_stealth_public_key = epee::string_tools::pod_to_hex(td.get_public_key()); + //output->m_stealth_public_key = epee::string_tools::pod_to_hex(td.get_public_key()); // TODO (monero-wallet-rpc): provide this field if (td.m_key_image_known) { output->m_key_image = std::make_shared(); output->m_key_image.get()->m_hex = epee::string_tools::pod_to_hex(td.m_key_image); @@ -606,10 +617,10 @@ namespace monero { return amount; } //------------------------------------------------------------------------------------------------------------------------------ - template + template bool fill_response(wallet2* m_w2, std::vector &ptx_vector, bool get_tx_key, Ts& tx_key, Tu &amount, Tu &fee, Tu &weight, std::string &multisig_txset, std::string &unsigned_txset, bool do_not_relay, - Ts &tx_hash, bool get_tx_hex, Ts &tx_blob, bool get_tx_metadata, Ts &tx_metadata, epee::json_rpc::error &er) + Ts &tx_hash, bool get_tx_hex, Ts &tx_blob, bool get_tx_metadata, Ts &tx_metadata, Tk &spent_key_images, epee::json_rpc::error &er) { for (const auto & ptx : ptx_vector) { @@ -624,6 +635,17 @@ namespace monero { fill(amount, total_amount(ptx)); fill(fee, ptx.fee); fill(weight, cryptonote::get_transaction_weight(ptx.tx)); + + // add spent key images + key_image_list key_image_list; + bool all_are_txin_to_key = std::all_of(ptx.tx.vin.begin(), ptx.tx.vin.end(), [&](const cryptonote::txin_v& s_e) -> bool + { + CHECKED_GET_SPECIFIC_VARIANT(s_e, const cryptonote::txin_to_key, in, false); + key_image_list.key_images.push_back(epee::string_tools::pod_to_hex(in.k_image)); + return true; + }); + THROW_WALLET_EXCEPTION_IF(!all_are_txin_to_key, error::unexpected_txin_type, ptx.tx); + fill(spent_key_images, key_image_list); } if (m_w2->multisig()) @@ -1550,7 +1572,7 @@ namespace monero { std::vector> monero_wallet_full::get_txs(const monero_tx_query& query) const { std::vector missing_tx_hashes; - std::vector> txs = monero_wallet_full::get_txs(query, missing_tx_hashes); + std::vector> txs = get_txs(query, missing_tx_hashes); if (!missing_tx_hashes.empty()) throw std::runtime_error("Tx not found in wallet: " + missing_tx_hashes[0]); return txs; } @@ -1568,8 +1590,10 @@ namespace monero { // temporarily disable transfer and output queries in order to collect all tx context boost::optional> transfer_query = _query->m_transfer_query; + boost::optional> input_query = _query->m_input_query; boost::optional> output_query = _query->m_output_query; _query->m_transfer_query = boost::none; + _query->m_input_query = boost::none; _query->m_output_query = boost::none; // fetch all transfers that meet tx query @@ -1615,6 +1639,7 @@ namespace monero { // restore transfer and output queries _query->m_transfer_query = transfer_query; + _query->m_input_query = input_query; _query->m_output_query = output_query; // filter txs that don't meet transfer query @@ -1754,6 +1779,27 @@ namespace monero { return result; } + void monero_wallet_full::freeze_output(const std::string& key_image) { + if (key_image.empty()) throw std::runtime_error("Must specify key image to freeze"); + crypto::key_image ki; + if (!epee::string_tools::hex_to_pod(key_image, ki)) throw new std::runtime_error("failed to parse key imge"); + m_w2->freeze(ki); + } + + void monero_wallet_full::thaw_output(const std::string& key_image) { + if (key_image.empty()) throw std::runtime_error("Must specify key image to thaw"); + crypto::key_image ki; + if (!epee::string_tools::hex_to_pod(key_image, ki)) throw new std::runtime_error("failed to parse key imge"); + m_w2->thaw(ki); + } + + bool monero_wallet_full::is_output_frozen(const std::string& key_image) { + if (key_image.empty()) throw std::runtime_error("Must specify key image to check if frozen"); + crypto::key_image ki; + if (!epee::string_tools::hex_to_pod(key_image, ki)) throw new std::runtime_error("failed to parse key imge"); + return m_w2->frozen(ki); + } + std::vector> monero_wallet_full::create_txs(const monero_tx_config& config) { MTRACE("monero_wallet_full::create_txs"); //std::cout << "monero_tx_config: " << config.serialize() << std::endl; @@ -1815,7 +1861,8 @@ namespace monero { std::list tx_hashes; std::list tx_blobs; std::list tx_metadatas; - if (!fill_response(m_w2.get(), ptx_vector, get_tx_keys, tx_keys, tx_amounts, tx_fees, tx_weights, multisig_tx_hex, unsigned_tx_hex, !relay, tx_hashes, get_tx_hex, tx_blobs, get_tx_metadata, tx_metadatas, err)) { + std::list input_key_images_list; + if (!fill_response(m_w2.get(), ptx_vector, get_tx_keys, tx_keys, tx_amounts, tx_fees, tx_weights, multisig_tx_hex, unsigned_tx_hex, !relay, tx_hashes, get_tx_hex, tx_blobs, get_tx_metadata, tx_metadatas, input_key_images_list, err)) { throw std::runtime_error("need to handle error filling response!"); // TODO } @@ -1828,6 +1875,7 @@ namespace monero { auto tx_weights_iter = tx_weights.begin(); auto tx_blobs_iter = tx_blobs.begin(); auto tx_metadatas_iter = tx_metadatas.begin(); + auto input_key_images_list_iter = input_key_images_list.begin(); while (tx_fees_iter != tx_fees.end()) { // init tx with outgoing transfer from filled values @@ -1843,6 +1891,16 @@ namespace monero { tx->m_outgoing_transfer = out_transfer; out_transfer->m_amount = *tx_amounts_iter; + // init inputs with key images + std::list input_key_images = (*input_key_images_list_iter).key_images; + for (const std::string& input_key_image : input_key_images) { + std::shared_ptr input = std::make_shared(); + input->m_tx = tx; + tx->m_inputs.push_back(input); + input->m_key_image = std::make_shared(); + input->m_key_image.get()->m_hex = input_key_image; + } + // init other known fields tx->m_is_outgoing = true; tx->m_payment_id = config.m_payment_id; @@ -1869,6 +1927,7 @@ namespace monero { tx_hashes_iter++; tx_blobs_iter++; tx_metadatas_iter++; + input_key_images_list_iter++; } // build tx set @@ -2004,7 +2063,8 @@ namespace monero { std::list tx_hashes; std::list tx_blobs; std::list tx_metadatas; - if (!fill_response(m_w2.get(), ptx_vector, get_tx_keys, tx_keys, tx_amounts, tx_fees, tx_weights, multisig_tx_hex, unsigned_tx_hex, !relay, tx_hashes, get_tx_hex, tx_blobs, get_tx_metadata, tx_metadatas, err)) { + std::list input_key_images_list; + if (!fill_response(m_w2.get(), ptx_vector, get_tx_keys, tx_keys, tx_amounts, tx_fees, tx_weights, multisig_tx_hex, unsigned_tx_hex, !relay, tx_hashes, get_tx_hex, tx_blobs, get_tx_metadata, tx_metadatas, input_key_images_list, err)) { throw std::runtime_error("need to handle error filling response!"); // TODO } @@ -2017,6 +2077,7 @@ namespace monero { auto tx_weights_iter = tx_weights.begin(); auto tx_blobs_iter = tx_blobs.begin(); auto tx_metadatas_iter = tx_metadatas.begin(); + auto input_key_images_list_iter = input_key_images_list.begin(); while (tx_fees_iter != tx_fees.end()) { // init tx with outgoing transfer from filled values @@ -2036,6 +2097,16 @@ namespace monero { std::shared_ptr destination = std::make_shared(destinations[0]->m_address.get(), out_transfer->m_amount.get()); out_transfer->m_destinations.push_back(destination); + // init inputs with key images + std::list input_key_images = (*input_key_images_list_iter).key_images; + for (const std::string& input_key_image : input_key_images) { + std::shared_ptr input = std::make_shared(); + input->m_tx = tx; + tx->m_inputs.push_back(input); + input->m_key_image = std::make_shared(); + input->m_key_image.get()->m_hex = input_key_image; + } + // init other known fields tx->m_payment_id = config.m_payment_id; tx->m_is_confirmed = false; @@ -2059,6 +2130,7 @@ namespace monero { tx_hashes_iter++; tx_blobs_iter++; tx_metadatas_iter++; + input_key_images_list_iter++; } // link tx std::set and return @@ -2127,7 +2199,8 @@ namespace monero { std::list tx_hashes; std::list tx_blobs; std::list tx_metadatas; - if (!fill_response(m_w2.get(), ptx_vector, get_tx_keys, tx_keys, tx_amounts, tx_fees, tx_weights, multisig_tx_hex, unsigned_tx_hex, !relay, tx_hashes, get_tx_hex, tx_blobs, get_tx_metadata, tx_metadatas, err)) { + std::list input_key_images_list; + if (!fill_response(m_w2.get(), ptx_vector, get_tx_keys, tx_keys, tx_amounts, tx_fees, tx_weights, multisig_tx_hex, unsigned_tx_hex, !relay, tx_hashes, get_tx_hex, tx_blobs, get_tx_metadata, tx_metadatas, input_key_images_list, err)) { throw std::runtime_error("need to handle error filling response!"); // TODO: return err message } @@ -2140,6 +2213,7 @@ namespace monero { auto tx_weights_iter = tx_weights.begin(); auto tx_blobs_iter = tx_blobs.begin(); auto tx_metadatas_iter = tx_metadatas.begin(); + auto input_key_images_list_iter = input_key_images_list.begin(); while (tx_fees_iter != tx_fees.end()) { // init tx with outgoing transfer from filled values @@ -2156,6 +2230,16 @@ namespace monero { tx->m_outgoing_transfer = out_transfer; out_transfer->m_amount = *tx_amounts_iter; + // init inputs with key images + std::list input_key_images = (*input_key_images_list_iter).key_images; + for (const std::string& input_key_image : input_key_images) { + std::shared_ptr input = std::make_shared(); + input->m_tx = tx; + tx->m_inputs.push_back(input); + input->m_key_image = std::make_shared(); + input->m_key_image.get()->m_hex = input_key_image; + } + // init other known fields tx->m_payment_id = config.m_payment_id; tx->m_is_confirmed = false; @@ -2182,6 +2266,7 @@ namespace monero { tx_hashes_iter++; tx_blobs_iter++; tx_metadatas_iter++; + input_key_images_list_iter++; } // validate one transaction @@ -2220,8 +2305,9 @@ namespace monero { std::list tx_hashes; std::list tx_blobs; std::list tx_metadatas; + std::list input_key_images_list; epee::json_rpc::error er; - if (!fill_response(m_w2.get(), ptx_vector, get_tx_keys, tx_keys, tx_amounts, tx_fees, tx_weights, multisig_tx_hex, unsigned_tx_hex, !relay, tx_hashes, get_tx_hex, tx_blobs, get_tx_metadata, tx_metadatas, er)) { + if (!fill_response(m_w2.get(), ptx_vector, get_tx_keys, tx_keys, tx_amounts, tx_fees, tx_weights, multisig_tx_hex, unsigned_tx_hex, !relay, tx_hashes, get_tx_hex, tx_blobs, get_tx_metadata, tx_metadatas, input_key_images_list, er)) { throw std::runtime_error("need to handle error filling response!"); // TODO: return err message } @@ -2234,6 +2320,7 @@ namespace monero { auto tx_weights_iter = tx_weights.begin(); auto tx_blobs_iter = tx_blobs.begin(); auto tx_metadatas_iter = tx_metadatas.begin(); + auto input_key_images_list_iter = input_key_images_list.begin(); while (tx_fees_iter != tx_fees.end()) { // init tx with outgoing transfer from filled values @@ -2250,6 +2337,16 @@ namespace monero { tx->m_outgoing_transfer = out_transfer; out_transfer->m_amount = *tx_amounts_iter; + // init inputs with key images + std::list input_key_images = (*input_key_images_list_iter).key_images; + for (const std::string& input_key_image : input_key_images) { + std::shared_ptr input = std::make_shared(); + input->m_tx = tx; + tx->m_inputs.push_back(input); + input->m_key_image = std::make_shared(); + input->m_key_image.get()->m_hex = input_key_image; + } + // init other known fields tx->m_is_confirmed = false; tx->m_is_miner_tx = false; @@ -2271,13 +2368,11 @@ namespace monero { tx_hashes_iter++; tx_blobs_iter++; tx_metadatas_iter++; + input_key_images_list_iter++; } - // throw exception if no dust to sweep (dust only exists pre-rct) - if (txs.empty() && multisig_tx_hex.empty() && unsigned_tx_hex.empty()) throw std::runtime_error("No dust to sweep"); - // link tx set - std::shared_ptr tx_set; + std::shared_ptr tx_set = std::make_shared(); tx_set->m_txs = txs; for (int i = 0; i < txs.size(); i++) txs[i]->m_tx_set = tx_set; if (!multisig_tx_hex.empty()) tx_set->m_multisig_tx_hex = multisig_tx_hex; @@ -3333,7 +3428,7 @@ namespace monero { std::list> payments; m_w2->get_unconfirmed_payments(payments, account_index, subaddress_indices); for (std::list>::const_iterator i = payments.begin(); i != payments.end(); ++i) { - if (!tx_query->m_hashes.empty() && std::find(tx_query->m_hashes.begin(), tx_query->m_hashes.end(), epee::string_tools::pod_to_hex(i->second.m_pd.m_tx_hash)) == tx_query->m_hashes.end()); // skip if hash filtered + if (!tx_query->m_hashes.empty() && std::find(tx_query->m_hashes.begin(), tx_query->m_hashes.end(), epee::string_tools::pod_to_hex(i->second.m_pd.m_tx_hash)) == tx_query->m_hashes.end()) continue; // skip if hash filtered std::shared_ptr tx = build_tx_with_incoming_transfer_unconfirmed(*m_w2, height, i->first, i->second); merge_tx(tx, tx_map, block_map); } diff --git a/src/wallet/monero_wallet_full.h b/src/wallet/monero_wallet_full.h index 0550727..7565bc8 100644 --- a/src/wallet/monero_wallet_full.h +++ b/src/wallet/monero_wallet_full.h @@ -228,6 +228,9 @@ namespace monero { int import_outputs(const std::string& outputs_hex) override; std::vector> export_key_images(bool all = false) const override; std::shared_ptr import_key_images(const std::vector>& key_images) override; + void freeze_output(const std::string& key_image) override; + void thaw_output(const std::string& key_image) override; + bool is_output_frozen(const std::string& key_image) override; std::vector> create_txs(const monero_tx_config& config) override; std::vector> sweep_unlocked(const monero_tx_config& config) override; std::shared_ptr sweep_output(const monero_tx_config& config) override; diff --git a/src/wallet/monero_wallet_model.cpp b/src/wallet/monero_wallet_model.cpp index 207379d..5dc32e1 100644 --- a/src/wallet/monero_wallet_model.cpp +++ b/src/wallet/monero_wallet_model.cpp @@ -398,6 +398,11 @@ namespace monero { monero_transfer_query::from_property_tree(it->second, tx_query->m_transfer_query.get()); tx_query->m_transfer_query.get()->m_tx_query = tx_query; } + else if (key == std::string("inputQuery")) { + tx_query->m_input_query = std::make_shared(); + monero_output_query::from_property_tree(it->second, tx_query->m_input_query.get()); + tx_query->m_input_query.get()->m_tx_query = tx_query; + } else if (key == std::string("outputQuery")) { tx_query->m_output_query = std::make_shared(); monero_output_query::from_property_tree(it->second, tx_query->m_output_query.get()); @@ -452,6 +457,10 @@ namespace monero { tgt->m_transfer_query = src->m_transfer_query.get()->copy(src->m_transfer_query.get(), std::make_shared()); tgt->m_transfer_query.get()->m_tx_query = tgt; } + if (src->m_input_query != boost::none) { + tgt->m_input_query = src->m_input_query.get()->copy(src->m_input_query.get(), std::make_shared()); + tgt->m_input_query.get()->m_tx_query = tgt; + } if (src->m_output_query != boost::none) { tgt->m_output_query = src->m_output_query.get()->copy(src->m_output_query.get(), std::make_shared()); tgt->m_output_query.get()->m_tx_query = tgt; @@ -510,6 +519,20 @@ namespace monero { if (!match_found) return false; } + // at least one input must meet input query if defined + if (m_input_query != boost::none) { + if (tx->m_inputs.empty()) return false; + bool match_found = false; + for (const std::shared_ptr& input : tx->m_inputs) { + std::shared_ptr vin_wallet = std::static_pointer_cast(input); + if (m_input_query.get()->meets_criteria(vin_wallet.get(), false)) { + match_found = true; + break; + } + } + if (!match_found) return false; + } + // at least one output must meet output query if defined if (m_output_query != boost::none) { if (tx->m_outputs.empty()) return false; @@ -1052,10 +1075,12 @@ namespace monero { // get tx query std::shared_ptr tx_query = std::static_pointer_cast(block->m_txs[0]); + // get / create input query + std::shared_ptr input_query = tx_query->m_input_query == boost::none ? std::make_shared() : *tx_query->m_input_query; + input_query->m_tx_query = tx_query; + // get / create output query std::shared_ptr output_query = tx_query->m_output_query == boost::none ? std::make_shared() : *tx_query->m_output_query; - - // set output query's tx query output_query->m_tx_query = tx_query; // return deserialized query @@ -1093,6 +1118,7 @@ namespace monero { if (m_subaddress_index != boost::none && (output->m_subaddress_index == boost::none || *m_subaddress_index != *output->m_subaddress_index)) return false; if (m_amount != boost::none && (output->m_amount == boost::none || *m_amount != *output->m_amount)) return false; if (m_is_spent != boost::none && (output->m_is_spent == boost::none || *m_is_spent != *output->m_is_spent)) return false; + if (m_is_frozen != boost::none && (output->m_is_frozen == boost::none || *m_is_frozen != *output->m_is_frozen)) return false; // filter on output key image if (m_key_image != boost::none) { diff --git a/src/wallet/monero_wallet_model.h b/src/wallet/monero_wallet_model.h index 34a4ea4..3c6469e 100644 --- a/src/wallet/monero_wallet_model.h +++ b/src/wallet/monero_wallet_model.h @@ -286,6 +286,7 @@ namespace monero { boost::optional m_max_height; boost::optional m_include_outputs; boost::optional> m_transfer_query; + boost::optional> m_input_query; boost::optional> m_output_query; rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const;