mirror of
https://git.wownero.com/wownero/onion-wownero-blockchain-explorer.git
synced 2024-08-15 00:33:12 +00:00
searching for encrypted payment id added
This commit is contained in:
parent
74881fac62
commit
08df36899f
3 changed files with 134 additions and 20 deletions
116
src/mylmdb.h
116
src/mylmdb.h
|
@ -22,7 +22,7 @@ namespace xmreg
|
|||
|
||||
|
||||
static const uint64_t DEFAULT_MAPSIZE = 20UL * 1024UL * 1024UL * 1024UL; /* 10 GiB */
|
||||
static const uint64_t DEFAULT_NO_DBs = 5;
|
||||
static const uint64_t DEFAULT_NO_DBs = 10;
|
||||
|
||||
|
||||
string m_db_path;
|
||||
|
@ -124,14 +124,16 @@ namespace xmreg
|
|||
= xmreg::get_ouputs(tx);
|
||||
|
||||
lmdb::txn wtxn {nullptr};
|
||||
lmdb::dbi wdbi {0};
|
||||
lmdb::dbi wdbi1 {0};
|
||||
lmdb::dbi wdbi2 {0};
|
||||
|
||||
unsigned int flags = MDB_CREATE | MDB_DUPSORT | MDB_DUPFIXED;
|
||||
|
||||
try
|
||||
{
|
||||
wtxn = lmdb::txn::begin(m_env);
|
||||
wdbi = lmdb::dbi::open(wtxn, "output_public_keys", flags);
|
||||
wdbi1 = lmdb::dbi::open(wtxn, "output_public_keys", flags);
|
||||
wdbi2 = lmdb::dbi::open(wtxn, "output_amounts", flags);
|
||||
}
|
||||
catch (lmdb::error& e )
|
||||
{
|
||||
|
@ -139,14 +141,18 @@ namespace xmreg
|
|||
return false;
|
||||
}
|
||||
|
||||
for (const pair<cryptonote::txout_to_key, uint64_t>& output: outputs)
|
||||
for (pair<cryptonote::txout_to_key, uint64_t>& output: outputs)
|
||||
{
|
||||
string public_key_str = pod_to_hex(output.first.key);
|
||||
|
||||
lmdb::val public_key_val {public_key_str};
|
||||
lmdb::val tx_hash_val {tx_hash_str};
|
||||
|
||||
wdbi.put(wtxn, public_key_val, tx_hash_val);
|
||||
lmdb::val amount_val {static_cast<void*>(&output.second),
|
||||
sizeof(output.second)};
|
||||
|
||||
wdbi1.put(wtxn, public_key_val, tx_hash_val);
|
||||
wdbi2.put(wtxn, public_key_val, amount_val);
|
||||
}
|
||||
|
||||
try
|
||||
|
@ -242,11 +248,57 @@ namespace xmreg
|
|||
return true;
|
||||
}
|
||||
|
||||
vector<string>
|
||||
search(const string& key, const string& db_name = "key_images")
|
||||
bool
|
||||
write_encrypted_payment_id(const transaction& tx)
|
||||
{
|
||||
vector<string> out;
|
||||
crypto::hash tx_hash = get_transaction_hash(tx);
|
||||
|
||||
string tx_hash_str = pod_to_hex(tx_hash);
|
||||
|
||||
crypto::hash payment_id;
|
||||
crypto::hash8 payment_id8;
|
||||
|
||||
get_payment_id(tx, payment_id, payment_id8);
|
||||
|
||||
if (payment_id8 == null_hash8)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
unsigned int flags = MDB_CREATE | MDB_DUPSORT | MDB_DUPFIXED;
|
||||
|
||||
string payment_id_str = pod_to_hex(payment_id8);
|
||||
|
||||
try
|
||||
{
|
||||
lmdb::txn wtxn = lmdb::txn::begin(m_env);
|
||||
lmdb::dbi wdbi = lmdb::dbi::open(wtxn, "encrypted_payments_id", flags);
|
||||
|
||||
//cout << "Saving encrypted payiment_id: " << payment_id_str << endl;
|
||||
//string wait_for_enter;
|
||||
//cin >> wait_for_enter;
|
||||
|
||||
lmdb::val payment_id_val {payment_id_str};
|
||||
lmdb::val tx_hash_val {tx_hash_str};
|
||||
|
||||
wdbi.put(wtxn, payment_id_val, tx_hash_val);
|
||||
|
||||
wtxn.commit();
|
||||
}
|
||||
catch (lmdb::error& e)
|
||||
{
|
||||
cerr << e.what() << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
search(const string& key,
|
||||
vector<string>& found_tx_hashes,
|
||||
const string& db_name = "key_images")
|
||||
{
|
||||
unsigned int flags = MDB_DUPSORT | MDB_DUPFIXED;
|
||||
|
||||
try
|
||||
|
@ -263,15 +315,19 @@ namespace xmreg
|
|||
if (cr.get(key_to_find, tx_hash_val, MDB_SET))
|
||||
{
|
||||
//cout << key_val_to_str(key_to_find, tx_hash_val) << endl;
|
||||
out.push_back(string(tx_hash_val.data(), tx_hash_val.size()));
|
||||
found_tx_hashes.push_back(string(tx_hash_val.data(), tx_hash_val.size()));
|
||||
|
||||
// process other values for the same key
|
||||
while (cr.get(key_to_find, tx_hash_val, MDB_NEXT_DUP))
|
||||
{
|
||||
//cout << key_val_to_str(key_to_find, tx_hash_val) << endl;
|
||||
out.push_back(string(tx_hash_val.data(), tx_hash_val.size()));
|
||||
found_tx_hashes.push_back(string(tx_hash_val.data(), tx_hash_val.size()));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
cr.close();
|
||||
rtxn.abort();
|
||||
|
@ -280,10 +336,46 @@ namespace xmreg
|
|||
catch (lmdb::error& e)
|
||||
{
|
||||
cerr << e.what() << endl;
|
||||
return out;
|
||||
return false;
|
||||
}
|
||||
|
||||
return out;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
get_output_amount(const string& key,
|
||||
uint64_t& amount,
|
||||
const string& db_name = "output_amounts")
|
||||
{
|
||||
|
||||
unsigned int flags = 0;
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
lmdb::txn rtxn = lmdb::txn::begin(m_env, nullptr, MDB_RDONLY);
|
||||
lmdb::dbi rdbi = lmdb::dbi::open(rtxn, db_name.c_str(), flags);
|
||||
|
||||
lmdb::val key_to_find{key};
|
||||
lmdb::val amount_val;
|
||||
|
||||
if(!rdbi.get(rtxn, key_to_find, amount_val))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
amount = *(amount_val.data<uint64_t>());
|
||||
|
||||
rtxn.abort();
|
||||
|
||||
}
|
||||
catch (lmdb::error& e)
|
||||
{
|
||||
cerr << e.what() << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
19
src/page.h
19
src/page.h
|
@ -939,22 +939,30 @@ namespace xmreg {
|
|||
result_html = default_txt;
|
||||
|
||||
// now search my own custom lmdb database
|
||||
// with key_images, public_keys etc.
|
||||
// with key_images, public_keys, payments_id etc.
|
||||
|
||||
vector<pair<string, vector<string>>> all_possible_tx_hashes;
|
||||
|
||||
xmreg::MyLMDB mylmdb {"/home/mwo/.bitmonero/lmdb2"};
|
||||
|
||||
vector<string> tx_hashes = mylmdb.search(search_text, "key_images");
|
||||
vector<string> tx_hashes;
|
||||
mylmdb.search(search_text, tx_hashes, "key_images");
|
||||
all_possible_tx_hashes.push_back(make_pair("key_images", tx_hashes));
|
||||
|
||||
tx_hashes = mylmdb.search(search_text, "tx_public_keys");
|
||||
tx_hashes.clear();
|
||||
mylmdb.search(search_text, tx_hashes, "tx_public_keys");
|
||||
all_possible_tx_hashes.push_back(make_pair("tx_public_keys", tx_hashes));
|
||||
|
||||
tx_hashes = mylmdb.search(search_text, "payments_id");
|
||||
tx_hashes.clear();
|
||||
mylmdb.search(search_text, tx_hashes, "payments_id");
|
||||
all_possible_tx_hashes.push_back(make_pair("payments_id", tx_hashes));
|
||||
|
||||
tx_hashes = mylmdb.search(search_text, "output_public_keys");
|
||||
tx_hashes.clear();
|
||||
mylmdb.search(search_text, tx_hashes, "encrypted_payments_id");
|
||||
all_possible_tx_hashes.push_back(make_pair("encrypted_payments_id", tx_hashes));
|
||||
|
||||
tx_hashes.clear();
|
||||
mylmdb.search(search_text, tx_hashes, "output_public_keys");
|
||||
all_possible_tx_hashes.push_back(make_pair("output_public_keys", tx_hashes));
|
||||
|
||||
result_html = show_search_results(search_text, all_possible_tx_hashes);
|
||||
|
@ -974,7 +982,6 @@ namespace xmreg {
|
|||
{"no_results" , true},
|
||||
};
|
||||
|
||||
|
||||
for (const pair<string, vector<string>>& found_txs: all_possible_tx_hashes)
|
||||
{
|
||||
|
||||
|
|
|
@ -56,6 +56,21 @@
|
|||
|
||||
{{/has_payments_id}}
|
||||
|
||||
</div>
|
||||
|
||||
{{#has_encrypted_payments_id}}
|
||||
|
||||
<h3>The search term matches encrypted payment id found in the following transaction(s)</h3>
|
||||
|
||||
<table class="center" style="width:80%">
|
||||
{{>tx_table_head}}
|
||||
{{#encrypted_payments_id}}
|
||||
{{>tx_table_row}}
|
||||
{{/encrypted_payments_id}}
|
||||
</table>
|
||||
|
||||
{{/has_encrypted_payments_id}}
|
||||
|
||||
</div>
|
||||
|
||||
<div>
|
||||
|
|
Loading…
Reference in a new issue