basic output for searching from lmdb2 added

This commit is contained in:
moneroexamples 2016-04-29 06:49:10 +08:00
parent bbab4afc7e
commit fb66d89f2a
2 changed files with 72 additions and 13 deletions

View File

@ -21,7 +21,7 @@ namespace xmreg
{
static const uint64_t DEFAULT_MAPSIZE = 10UL * 1024UL * 1024UL * 1024UL; /* 10 GiB */
static const uint64_t DEFAULT_MAPSIZE = 20UL * 1024UL * 1024UL * 1024UL; /* 10 GiB */
static const uint64_t DEFAULT_NO_DBs = 5;
@ -114,7 +114,7 @@ namespace xmreg
}
bool
write_public_keys(const transaction& tx)
write_output_public_keys(const transaction& tx)
{
crypto::hash tx_hash = get_transaction_hash(tx);
@ -131,7 +131,7 @@ namespace xmreg
try
{
wtxn = lmdb::txn::begin(m_env);
wdbi = lmdb::dbi::open(wtxn, "public_keys", flags);
wdbi = lmdb::dbi::open(wtxn, "output_public_keys", flags);
}
catch (lmdb::error& e )
{
@ -162,6 +162,42 @@ namespace xmreg
return true;
}
bool
write_tx_public_key(const transaction& tx)
{
crypto::hash tx_hash = get_transaction_hash(tx);
string tx_hash_str = pod_to_hex(tx_hash);
unsigned int flags = MDB_CREATE | MDB_DUPSORT | MDB_DUPFIXED;
public_key pk = get_tx_pub_key_from_extra(tx);
string pk_str = pod_to_hex(pk);
try
{
lmdb::txn wtxn = lmdb::txn::begin(m_env);
lmdb::dbi wdbi = lmdb::dbi::open(wtxn, "tx_public_keys", flags);
//cout << "Saving public_key: " << pk_str << endl;
lmdb::val public_key_val {pk_str};
lmdb::val tx_hash_val {tx_hash_str};
wdbi.put(wtxn, public_key_val, tx_hash_val);
wtxn.commit();
}
catch (lmdb::error& e)
{
cerr << e.what() << endl;
return false;
}
return true;
}
bool
write_payment_id(const transaction& tx)
{
@ -190,8 +226,8 @@ namespace xmreg
//cout << "Saving payiment_id: " << payment_id_str << endl;
lmdb::val payment_id_val{payment_id_str};
lmdb::val tx_hash_val{tx_hash_str};
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);
@ -227,16 +263,13 @@ 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()));
// process other values for the same key
while (cr.get(key_to_find, tx_hash_val, MDB_NEXT_DUP)) {
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()));
}
}

View File

@ -946,8 +946,16 @@ namespace xmreg {
vector<string> tx_hashes = mylmdb.search(search_text, "key_images");
all_possible_tx_hashes.push_back(make_pair("key_images", tx_hashes));
tx_hashes = mylmdb.search(search_text, "public_keys");
all_possible_tx_hashes.push_back(make_pair("public_keys", tx_hashes));
tx_hashes = mylmdb.search(search_text, "tx_public_keys");
all_possible_tx_hashes.push_back(make_pair("tx_public_keys", tx_hashes));
tx_hashes = mylmdb.search(search_text, "payments_id");
all_possible_tx_hashes.push_back(make_pair("payments_id", tx_hashes));
tx_hashes = mylmdb.search(search_text, "output_public_keys");
all_possible_tx_hashes.push_back(make_pair("output_public_keys", tx_hashes));
result_html = show_search_results(all_possible_tx_hashes);
// if (tx_hashes.size() == 1)
// {
@ -976,6 +984,24 @@ namespace xmreg {
{"something" , "something"},
};
string out_tmp;
for (const pair<string, vector<string>>& found_txs: all_possible_tx_hashes)
{
if (!found_txs.second.empty())
{
out_tmp += found_txs.first + string("<br/>");
for (const string& tx_hash: found_txs.second)
{
out_tmp += string(" - ")
+ fmt::format("{:s}", tx_hash)
+ string("<br/>");
}
}
}
// read search_results.html
string search_results_html = xmreg::read(TMPL_SEARCH_RESULTS);
@ -983,7 +1009,7 @@ namespace xmreg {
string full_page = get_full_page(search_results_html);
// render the page
return mstch::render(full_page, context);
return out_tmp;
}