@@ -82,6 +82,7 @@ secp256_private_key get_priv_key_from_str(const std::string& str);
8282fc::sha256 get_hash (const keychain_app::unit_list_t &list);
8383void send_response (const signature_t & signature, int id);
8484void send_response (bool res, int id);
85+ void send_response (const fc::variants& res, int id);
8586size_t from_hex (const std::string& hex_str, unsigned char * out_data, size_t out_data_len );
8687std::string to_hex (const uint8_t * data, size_t length);
8788/* {
@@ -95,8 +96,9 @@ std::string to_hex(const uint8_t* data, size_t length);
9596struct json_response
9697{
9798 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){}
100102 int id;
101103 fc::variant result;
102104};
@@ -327,6 +329,43 @@ struct keychain_command<CMD_CREATE>: keychain_command_base
327329 }
328330};
329331
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+
330369template <>
331370struct keychain_command <CMD_REMOVE>: keychain_command_base
332371{
0 commit comments