SKALE-3023 fix format

parent 027d5067
...@@ -171,8 +171,8 @@ void LevelDB::writeDataUnique(const string & name, const string &value) { ...@@ -171,8 +171,8 @@ void LevelDB::writeDataUnique(const string & name, const string &value) {
writeString(key, value); writeString(key, value);
} }
stringstream LevelDB::getAllKeys() { pair<stringstream, uint64_t> LevelDB::getAllKeys() {
stringstream result; stringstream keysInfo;
leveldb::Iterator *it = db->NewIterator(readOptions); leveldb::Iterator *it = db->NewIterator(readOptions);
uint64_t counter = 0; uint64_t counter = 0;
...@@ -192,11 +192,10 @@ stringstream LevelDB::getAllKeys() { ...@@ -192,11 +192,10 @@ stringstream LevelDB::getAllKeys() {
// old style keys // old style keys
value = " VALUE: " + it->value().ToString(); value = " VALUE: " + it->value().ToString();
} }
result << "KEY: " << key << ',' << value; keysInfo << "KEY: " << key << ',' << value;
} }
result << "TOTAL NUMBER OF KEYS: " << counter;
return result; return {std::move(keysInfo), counter};
} }
pair<string, uint64_t> LevelDB::getLatestCreatedKey() { pair<string, uint64_t> LevelDB::getLatestCreatedKey() {
......
...@@ -71,7 +71,7 @@ public: ...@@ -71,7 +71,7 @@ public:
shared_ptr<string> readNewStyleValue(const string& value); shared_ptr<string> readNewStyleValue(const string& value);
stringstream getAllKeys(); pair<stringstream, uint64_t> getAllKeys();
pair<string, uint64_t> getLatestCreatedKey(); pair<string, uint64_t> getLatestCreatedKey();
......
...@@ -56,7 +56,9 @@ Json::Value SGXInfoServer::getAllKeysInfo() { ...@@ -56,7 +56,9 @@ Json::Value SGXInfoServer::getAllKeysInfo() {
Json::Value result; Json::Value result;
try { try {
result["allKeys"] = LevelDB::getLevelDb()->getAllKeys().str(); auto allKeysInfo = LevelDB::getLevelDb()->getAllKeys();
result["allKeys"] = allKeysInfo.first.str();
result["keysNumber"] = std::to_string(allKeysInfo.second);
} HANDLE_SGX_EXCEPTION(result) } HANDLE_SGX_EXCEPTION(result)
RETURN_SUCCESS(result) RETURN_SUCCESS(result)
......
...@@ -45,11 +45,20 @@ void sign_by_hash(std::string & hash, int status){ ...@@ -45,11 +45,20 @@ void sign_by_hash(std::string & hash, int status){
exit(0); exit(0);
} }
void getNumberOfKeysCreated() {
jsonrpc::HttpClient client("http://localhost:1030");
StubClient c(client, jsonrpc::JSONRPC_CLIENT_V2);
std::cout << "Info client inited" << std::endl;
std::cout << c.getAllKeysInfo()["keysNumber"].asString() << std::endl;
exit(0);
}
void getAllKeysInfo() { void getAllKeysInfo() {
jsonrpc::HttpClient client("http://localhost:1030"); jsonrpc::HttpClient client("http://localhost:1030");
StubClient c(client, jsonrpc::JSONRPC_CLIENT_V2); StubClient c(client, jsonrpc::JSONRPC_CLIENT_V2);
std::cout << "Info client inited" << std::endl; std::cout << "Info client inited" << std::endl;
std::cout << c.getAllKeysInfo()["allKeys"].asString().c_str() << std::endl; std::cout << c.getAllKeysInfo()["allKeys"].asString() << std::endl;
std::cout << "TOTAL KEYS IN DATABASE: " << c.getAllKeysInfo()["keysNumber"].asString() << std::endl;
exit(0); exit(0);
} }
...@@ -126,6 +135,7 @@ int main(int argc, char *argv[]) { ...@@ -126,6 +135,7 @@ int main(int argc, char *argv[]) {
std::cout << " -r [hash] reject 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 << " -a print all keys" << std::endl;
std::cout << " -l print latest created key" << std::endl; std::cout << " -l print latest created key" << std::endl;
std::cout << " -n print number of keys stored in database" << std::endl;
std::cout << " -c print server's config" << 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; std::cout << " -i [name] check if key with such name presents in database" << std::endl;
exit(0); exit(0);
...@@ -133,7 +143,7 @@ int main(int argc, char *argv[]) { ...@@ -133,7 +143,7 @@ int main(int argc, char *argv[]) {
std::string hash; std::string hash;
std::string key; std::string key;
while ((opt = getopt(argc, argv, "ps:r:alci:")) != -1) { while ((opt = getopt(argc, argv, "ps:r:alci:n")) != -1) {
switch (opt) { switch (opt) {
case 'p': print_hashes(); case 'p': print_hashes();
break; break;
...@@ -155,6 +165,9 @@ int main(int argc, char *argv[]) { ...@@ -155,6 +165,9 @@ int main(int argc, char *argv[]) {
case 'i': key = optarg; case 'i': key = optarg;
isKeyExists(key); isKeyExists(key);
break; break;
case 'n':
getNumberOfKeysCreated();
break;
case '?': // fprintf(stderr, "unknown flag\n"); case '?': // fprintf(stderr, "unknown flag\n");
exit(1); exit(1);
} }
......
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