From c323f61adfe1e096dac339b42b04fbd6368f012e Mon Sep 17 00:00:00 2001 From: moneroexamples Date: Mon, 25 Apr 2016 03:18:56 +0000 Subject: [PATCH] get_payment_id added to tools --- src/tools.cpp | 35 +++++++++++++++++++++++ src/tools.h | 6 ++++ src/tx_details.cpp | 69 ---------------------------------------------- src/tx_details.h | 6 ---- 4 files changed, 41 insertions(+), 75 deletions(-) diff --git a/src/tools.cpp b/src/tools.cpp index 6e0345b..4578536 100644 --- a/src/tools.cpp +++ b/src/tools.cpp @@ -446,6 +446,41 @@ namespace xmreg return key_images; } + bool + get_payment_id(const transaction& tx, + crypto::hash& payment_id, + crypto::hash8& payment_id8) + { + + payment_id = null_hash; + payment_id8 = null_hash8; + + std::vector tx_extra_fields; + + if(!parse_tx_extra(tx.extra, tx_extra_fields)) + { + return false; + } + + tx_extra_nonce extra_nonce; + + if (find_tx_extra_field_by_type(tx_extra_fields, extra_nonce)) + { + // first check for encripted id and then for normal one + if(get_encrypted_payment_id_from_tx_extra_nonce(extra_nonce.nonce, payment_id8)) + { + return true; + } + else if (get_payment_id_from_tx_extra_nonce(extra_nonce.nonce, payment_id)) + { + return true; + } + } + + return false; + } + + /** * Rough estimate of block height from the time provided * diff --git a/src/tools.h b/src/tools.h index 397bd63..2f06403 100644 --- a/src/tools.h +++ b/src/tools.h @@ -159,6 +159,12 @@ namespace xmreg get_key_images(const transaction& tx); + bool + get_payment_id(const transaction& tx, + crypto::hash& payment_id, + crypto::hash8& payment_id8); + + inline void enable_monero_log() { uint32_t log_level = 0; diff --git a/src/tx_details.cpp b/src/tx_details.cpp index 4ed14da..b839162 100644 --- a/src/tx_details.cpp +++ b/src/tx_details.cpp @@ -205,75 +205,6 @@ namespace xmreg } - - bool - get_payment_id(const transaction& tx, - crypto::hash& payment_id) - { - - payment_id = null_hash; - - std::vector tx_extra_fields; - - if(!parse_tx_extra(tx.extra, tx_extra_fields)) - { - return false; - } - - tx_extra_nonce extra_nonce; - - if (find_tx_extra_field_by_type(tx_extra_fields, extra_nonce)) - { - if (!get_payment_id_from_tx_extra_nonce(extra_nonce.nonce, payment_id)) - { - return false; - } - } - else - { - return false; - } - - return true; - } - - - bool - get_encrypted_payment_id(const transaction& tx, - crypto::hash8& payment_id8) - { - payment_id8 = null_hash8; - - std::vector tx_extra_fields; - - if(!parse_tx_extra(tx.extra, tx_extra_fields)) - { - return false; - } - - tx_extra_nonce extra_nonce; - - if (find_tx_extra_field_by_type(tx_extra_fields, extra_nonce)) - { - - if (!get_encrypted_payment_id_from_tx_extra_nonce(extra_nonce.nonce, payment_id8)) - { - // if (decrypt_payment_id(payment_id8, addr.m_view_public_key, ptx.tx_key)) - // { - // memcpy(payment_id8.data, payment_id8.data, 8); - // } - return false; - } - } - else - { - return false; - } - - return true; - } - - } template<> diff --git a/src/tx_details.h b/src/tx_details.h index db77038..6e7609d 100644 --- a/src/tx_details.h +++ b/src/tx_details.h @@ -52,13 +52,7 @@ namespace xmreg const secret_key& private_view_key, const public_key& public_spend_key); - bool - get_payment_id(const transaction& tx, - crypto::hash& payment_id); - bool - get_encrypted_payment_id(const transaction& tx, - crypto::hash8& payment_id); }