@@ -82,6 +82,7 @@ secp256_private_key get_priv_key_from_str(const std::string& str);
82
82
fc::sha256 get_hash (const keychain_app::unit_list_t &list);
83
83
void send_response (const signature_t & signature, int id);
84
84
void send_response (bool res, int id);
85
+ void send_response (const fc::variants& res, int id);
85
86
size_t from_hex (const std::string& hex_str, unsigned char * out_data, size_t out_data_len );
86
87
std::string to_hex (const uint8_t * data, size_t length);
87
88
/* {
@@ -95,8 +96,9 @@ std::string to_hex(const uint8_t* data, size_t length);
95
96
struct json_response
96
97
{
97
98
json_response (){}
98
- json_response (const fc::variant& var, int id_):result(var), id(id_){}
99
- json_response (const char * result_, int id_):result(result_), id(id_){}
99
+ json_response (const fc::variant& var, int id_): id(id_), result(var){}
100
+ json_response (const char * result_, int id_): id(id_), result(result_){}
101
+ json_response (const fc::variants& var, int id_): id(id_), result(var){}
100
102
int id;
101
103
fc::variant result;
102
104
};
@@ -327,6 +329,43 @@ struct keychain_command<CMD_CREATE>: keychain_command_base
327
329
}
328
330
};
329
331
332
+ template <>
333
+ struct keychain_command <CMD_LIST>: keychain_command_base {
334
+ keychain_command () : keychain_command_base(CMD_REMOVE) {}
335
+
336
+ ~keychain_command () {}
337
+
338
+ using params_t = void ;
339
+
340
+ virtual void operator ()(keychain_base *keychain, const fc::variant ¶ms_variant, int id) const override
341
+ {
342
+ try {
343
+ fc::variants keyname_list;
344
+ keyname_list.reserve (128 );
345
+ auto first = bfs::directory_iterator (bfs::path (" ./" ));
346
+ std::for_each (first, bfs::directory_iterator (), [&keyname_list](bfs::directory_entry &unit){
347
+ if (!bfs::is_regular_file (unit.status ()))
348
+ return false ;
349
+ const auto &file_path = unit.path ().filename ();
350
+
351
+ auto j_keyfile = open_keyfile (file_path.c_str ());
352
+ auto keyfile = j_keyfile.as <keyfile_format::keyfile_t >();
353
+ keyname_list.push_back (fc::variant (std::move (keyfile.keyname )));
354
+ });
355
+ send_response (keyname_list, id);
356
+ }
357
+ catch (const std::exception &exc)
358
+ {
359
+ std::cout << fc::json::to_pretty_string (fc::variant (json_error (id, exc.what ()))) << std::endl;
360
+ }
361
+ catch (const fc::exception& exc)
362
+ {
363
+ std::cout << fc::json::to_pretty_string (fc::variant (json_error (0 , exc.what ()))) << std::endl;
364
+ std::cerr << fc::json::to_pretty_string (fc::variant (json_error (0 , exc.to_detail_string ().c_str ()))) << std::endl;
365
+ }
366
+ }
367
+ };
368
+
330
369
template <>
331
370
struct keychain_command <CMD_REMOVE>: keychain_command_base
332
371
{
0 commit comments