main.cpp 1.8 KB
Newer Older
1 2 3 4 5 6 7
/**
 *  @file
 *  @copyright defined in eos/LICENSE.txt
 */
#include <appbase/application.hpp>

#include <eosio/http_plugin/http_plugin.hpp>
C
Ciju John 已提交
8 9
#include <eosio/wallet_plugin/wallet_plugin.hpp>
#include <eosio/wallet_api_plugin/wallet_api_plugin.hpp>
10 11 12 13 14 15

#include <fc/log/logger_config.hpp>
#include <fc/exception/exception.hpp>

#include <boost/exception/diagnostic_information.hpp>

16
#include <pwd.h>
17
#include "config.hpp"
18

19 20 21
using namespace appbase;
using namespace eosio;

22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
bfs::path determine_home_directory()
{
   bfs::path home;
   struct passwd* pwd = getpwuid(getuid());
   if(pwd) {
      home = pwd->pw_dir;
   }
   else {
      home = getenv("HOME");
   }
   if(home.empty())
      home = "./";
   return home;
}

37 38 39
int main(int argc, char** argv)
{
   try {
40 41 42
      bfs::path home = determine_home_directory();
      app().set_default_data_dir(home / "eosio-wallet");
      app().set_default_config_dir(home / "eosio-wallet");
43
      http_plugin::set_defaults({
44
         .address_config_prefix = "",
45
         .default_unix_socket_path = keosd::config::key_store_executable_name + ".sock",
46
         .default_http_port = 0
47
      });
48 49 50
      app().register_plugin<wallet_api_plugin>();
      if(!app().initialize<wallet_plugin, wallet_api_plugin, http_plugin>(argc, argv))
         return -1;
51
      auto& http = app().get_plugin<http_plugin>();
A
Anton Perkov 已提交
52
      http.add_handler("/v1/keosd/stop", [](string, string, url_response_callback cb) { cb(200, "{}"); std::raise(SIGTERM); } );
53 54 55 56 57 58 59 60 61 62 63 64 65
      app().startup();
      app().exec();
   } catch (const fc::exception& e) {
      elog("${e}", ("e",e.to_detail_string()));
   } catch (const boost::exception& e) {
      elog("${e}", ("e",boost::diagnostic_information(e)));
   } catch (const std::exception& e) {
      elog("${e}", ("e",e.what()));
   } catch (...) {
      elog("unknown exception");
   }
   return 0;
}