mirror of
https://github.com/wownero/wownero-cpp.git
synced 2026-10-21 09:08:43 +02:00
get txs with output query
This commit is contained in:
@@ -1399,14 +1399,17 @@ namespace monero {
|
||||
shared_ptr<monero_tx_query> query_ptr = make_shared<monero_tx_query>(query); // convert to shared pointer for copy
|
||||
shared_ptr<monero_tx_query> _query = query_ptr->copy(query_ptr, make_shared<monero_tx_query>()); // deep copy
|
||||
if (_query->m_transfer_query == boost::none) _query->m_transfer_query = make_shared<monero_transfer_query>();
|
||||
shared_ptr<monero_transfer_query> transfer_query = _query->m_transfer_query.get();
|
||||
if (_query->m_output_query == boost::none) _query->m_output_query = make_shared<monero_output_query>();
|
||||
|
||||
// print query
|
||||
if (_query->m_block != boost::none) MTRACE("Tx query's rooted at [block]: " << _query->m_block.get()->serialize());
|
||||
else MTRACE("Tx _query: " << _query->serialize());
|
||||
|
||||
// temporarily disable transfer query
|
||||
|
||||
// temporarily disable transfer and output queries in order to collect all tx information
|
||||
shared_ptr<monero_transfer_query> transfer_query = _query->m_transfer_query.get();
|
||||
shared_ptr<monero_output_query> output_query = _query->m_output_query.get();
|
||||
_query->m_transfer_query = boost::none;
|
||||
_query->m_output_query = boost::none;
|
||||
|
||||
// fetch all transfers that meet tx query
|
||||
monero_transfer_query temp_transfer_query;
|
||||
@@ -1449,8 +1452,11 @@ namespace monero {
|
||||
}
|
||||
}
|
||||
|
||||
// filter txs that don't meet transfer query // TODO: port this updated version to js
|
||||
// restore transfer and output queries
|
||||
_query->m_transfer_query = transfer_query;
|
||||
_query->m_output_query = output_query;
|
||||
|
||||
// filter txs that don't meet transfer query
|
||||
vector<shared_ptr<monero_tx_wallet>> queried_txs;
|
||||
vector<shared_ptr<monero_tx_wallet>>::iterator tx_iter = txs.begin();
|
||||
while (tx_iter != txs.end()) {
|
||||
|
||||
@@ -244,10 +244,10 @@ namespace monero {
|
||||
// at least one transfer must meet transfer query if defined
|
||||
if (m_transfer_query != boost::none) {
|
||||
bool matchFound = false;
|
||||
if (tx->m_outgoing_transfer != boost::none && (*m_transfer_query)->meets_criteria((*tx->m_outgoing_transfer).get())) matchFound = true;
|
||||
if (tx->m_outgoing_transfer != boost::none && m_transfer_query.get()->meets_criteria(tx->m_outgoing_transfer.get().get())) matchFound = true;
|
||||
else if (!tx->m_incoming_transfers.empty()) {
|
||||
for (const shared_ptr<monero_incoming_transfer>& incomingTransfer : tx->m_incoming_transfers) {
|
||||
if ((*m_transfer_query)->meets_criteria(incomingTransfer.get())) {
|
||||
for (const shared_ptr<monero_incoming_transfer>& incoming_transfer : tx->m_incoming_transfers) {
|
||||
if (m_transfer_query.get()->meets_criteria(incoming_transfer.get())) {
|
||||
matchFound = true;
|
||||
break;
|
||||
}
|
||||
@@ -256,6 +256,20 @@ namespace monero {
|
||||
if (!matchFound) return false;
|
||||
}
|
||||
|
||||
// at least one output must meet output query if defined
|
||||
if (m_output_query != boost::none && !m_output_query.get()->is_default()) {
|
||||
if (tx->m_vouts.empty()) return false;
|
||||
bool matchFound = false;
|
||||
for (const shared_ptr<monero_output>& vout : tx->m_vouts) {
|
||||
shared_ptr<monero_output_wallet> vout_wallet = static_pointer_cast<monero_output_wallet>(vout);
|
||||
if (m_output_query.get()->meets_criteria(vout_wallet.get())) {
|
||||
matchFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!matchFound) return false;
|
||||
}
|
||||
|
||||
// filter on having a payment id
|
||||
if (m_has_payment_id != boost::none) {
|
||||
if (*m_has_payment_id && tx->m_payment_id == boost::none) return false;
|
||||
@@ -581,6 +595,12 @@ namespace monero {
|
||||
|
||||
// ------------------------ MONERO OUTPUT REQUEST ---------------------------
|
||||
|
||||
// initialize static empty output for is_default() check
|
||||
const unique_ptr<monero_output_wallet> monero_output_query::M_EMPTY_OUTPUT = unique_ptr<monero_output_wallet>(new monero_output_wallet());
|
||||
bool monero_output_query::is_default() const {
|
||||
return meets_criteria(monero_output_query::M_EMPTY_OUTPUT.get());
|
||||
}
|
||||
|
||||
shared_ptr<monero_output_query> monero_output_query::copy(const shared_ptr<monero_output>& src, const shared_ptr<monero_output>& tgt) const {
|
||||
return monero_output_query::copy(static_pointer_cast<monero_output_query>(src), static_pointer_cast<monero_output_query>(tgt));
|
||||
};
|
||||
@@ -610,11 +630,11 @@ namespace monero {
|
||||
bool monero_output_query::meets_criteria(monero_output_wallet* output) const {
|
||||
|
||||
// filter on output
|
||||
if (m_account_index != boost::none && *m_account_index != *output->m_account_index) return false;
|
||||
if (m_subaddress_index != boost::none && *m_subaddress_index != *output->m_subaddress_index) return false;
|
||||
if (m_amount != boost::none && *m_amount != *output->m_amount) return false;
|
||||
if (m_is_spent != boost::none && *m_is_spent != *output->m_is_spent) return false;
|
||||
if (m_is_unlocked != boost::none && *m_is_unlocked != *output->m_is_unlocked) return false;
|
||||
if (m_account_index != boost::none && (output->m_account_index == boost::none || *m_account_index != *output->m_account_index)) return false;
|
||||
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_unlocked != boost::none && (output->m_is_unlocked == boost::none || *m_is_unlocked != *output->m_is_unlocked)) return false;
|
||||
|
||||
// filter on output key image
|
||||
if (m_key_image != boost::none) {
|
||||
|
||||
@@ -242,13 +242,16 @@ namespace monero {
|
||||
boost::optional<shared_ptr<monero_tx_query>> m_tx_query;
|
||||
|
||||
// TODO: necessary to override all super classes?
|
||||
bool is_default() const;
|
||||
shared_ptr<monero_output_query> copy(const shared_ptr<monero_output>& src, const shared_ptr<monero_output>& tgt) const;
|
||||
shared_ptr<monero_output_query> copy(const shared_ptr<monero_output_wallet>& src, const shared_ptr<monero_output_wallet>& tgt) const;
|
||||
shared_ptr<monero_output_query> copy(const shared_ptr<monero_output_query>& src, const shared_ptr<monero_output_query>& tgt) const;
|
||||
boost::property_tree::ptree to_property_tree() const;
|
||||
bool meets_criteria(monero_output_wallet* output) const;
|
||||
};
|
||||
|
||||
private:
|
||||
static const unique_ptr<monero_output_wallet> M_EMPTY_OUTPUT;
|
||||
};
|
||||
|
||||
/**
|
||||
* Models a Monero transaction in the context of a wallet.
|
||||
|
||||
Reference in New Issue
Block a user