get_payment_id added to tools

This commit is contained in:
moneroexamples 2016-04-25 03:18:56 +00:00
parent 95b7e8daf2
commit c323f61adf
4 changed files with 41 additions and 75 deletions

View file

@ -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_field> 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
*

View file

@ -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;

View file

@ -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_field> 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_field> 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<>

View file

@ -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);
}