SKALE-3023 add all keys info method

parent f5925b11
......@@ -27,6 +27,7 @@
#include <iostream>
#include "leveldb/db.h"
#include <jsonrpccpp/client.h>
#include "sgxwallet_common.h"
#include "SGXException.h"
......@@ -167,10 +168,32 @@ void LevelDB::writeDataUnique(const string & name, const string &value) {
}
stringstream LevelDB::getAllKeys() {
stringstream result;
leveldb::Iterator *it = db->NewIterator(readOptions);
uint64_t counter = 0;
for (it->SeekToFirst(); it->Valid(); it->Next()) {
++counter;
string key = it->key().ToString();
string value;
if (it->value().ToString()[0] == '{') {
// new style keys
Json::Value key_data;
Json::Reader reader;
reader.parse(it->value().ToString().c_str(), key_data);
value = " VALUE: " + key_data["value"].asString() + ", TIMESTAMP: " + key_data["timestamp"].asString();
} else {
// old style keys
value = " VALUE: " + it->value().ToString();
}
result << "KEY: " << key << ',' << value << '\n';
}
result << "TOTAL NUMBER OF KEYS: " << counter << '\n';
return result;
}
pair<string, uint64_t> LevelDB::getLastCreatedKey() {
pair<string, uint64_t> LevelDB::getLatestCreatedKey() {
}
......
......@@ -72,7 +72,7 @@ public:
stringstream getAllKeys();
pair<string, uint64_t> getLastCreatedKey();
pair<string, uint64_t> getLatestCreatedKey();
void writeString(const string &key1, const string &value1);
......
......@@ -60,7 +60,7 @@ Json::Value SGXInfoServer::getLastCreatedKey() {
Json::Value result;
try {
pair<string, uint64_t> key = LevelDB::getLevelDb()->getLastCreatedKey();
pair<string, uint64_t> key = LevelDB::getLevelDb()->getLatestCreatedKey();
result["keyName"] = key.first;
result["creationTime"] = key.second;
} HANDLE_SGX_EXCEPTION(result)
......
File deleted
......@@ -93,9 +93,13 @@ int main(int argc, char *argv[]) {
if (argc == 1) {
std::cout << "You may use following flags:" << std::endl;
std::cout << " -p print all unsigned csr hashes " << std::endl;
std::cout << " -p print all unsigned csr hashes " << std::endl;
std::cout << " -s [hash] sign csr by hash" << std::endl;
std::cout << " -r [hash] reject csr by hash" << std::endl;
std::cout << " -a print all keys" << std::endl;
std::cout << " -l print latest created key" << std::endl;
std::cout << " -c print server's config" << std::endl;
std::cout << " -i [name] check if key with such name presents in database" << std::endl;
exit(0);
}
std::string hash;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment