Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
wallet_plugin.cpp
Go to the documentation of this file.
5#include <boost/filesystem/path.hpp>
6#include <chrono>
7
8#include <fc/io/json.hpp>
9
10namespace fc { class variant; }
11
12namespace sysio {
13
14static appbase::abstract_plugin& _wallet_plugin = app().register_plugin<wallet_plugin>();
15
17
19 return *wallet_manager_ptr;
20}
21
22void wallet_plugin::set_program_options(options_description& cli, options_description& cfg) {
23 cfg.add_options()
24 ("wallet-dir", bpo::value<boost::filesystem::path>()->default_value("."),
25 "The path of the wallet files (absolute path or relative to application data dir)")
26 ("unlock-timeout", bpo::value<int64_t>()->default_value(900),
27 "Timeout for unlocked wallet in seconds (default 900 (15 minutes)). "
28 "Wallets will automatically lock after specified number of seconds of inactivity. "
29 "Activity is defined as any wallet command e.g. list-wallets.")
30 ("yubihsm-url", bpo::value<string>()->value_name("URL"),
31 "Override default URL of http://localhost:12345 for connecting to yubihsm-connector")
32 ("yubihsm-authkey", bpo::value<uint16_t>()->value_name("key_num"),
33 "Enables YubiHSM support using given Authkey")
34 ;
35}
36
37void wallet_plugin::plugin_initialize(const variables_map& options) {
38 ilog("initializing wallet plugin");
39 try {
40 wallet_manager_ptr = std::make_unique<wallet_manager>();
41
42 if (options.count("wallet-dir")) {
43 auto dir = options.at("wallet-dir").as<boost::filesystem::path>();
44 if (dir.is_relative())
45 dir = app().data_dir() / dir;
46 if( !bfs::exists(dir) )
47 bfs::create_directories(dir);
48 wallet_manager_ptr->set_dir(dir);
49 }
50 if (options.count("unlock-timeout")) {
51 auto timeout = options.at("unlock-timeout").as<int64_t>();
52 SYS_ASSERT(timeout > 0, chain::invalid_lock_timeout_exception, "Please specify a positive timeout ${t}", ("t", timeout));
53 std::chrono::seconds t(timeout);
54 wallet_manager_ptr->set_timeout(t);
55 }
56 if (options.count("yubihsm-authkey")) {
57 uint16_t key = options.at("yubihsm-authkey").as<uint16_t>();
58 string connector_endpoint = "http://localhost:12345";
59 if(options.count("yubihsm-url"))
60 connector_endpoint = options.at("yubihsm-url").as<string>();
61 try {
62 wallet_manager_ptr->own_and_use_wallet("YubiHSM", make_unique<yubihsm_wallet>(connector_endpoint, key));
64 }
66}
67
68} // namespace sysio
#define SYS_ASSERT(expr, exc_type, FORMAT,...)
Definition exceptions.hpp:7
bfs::path data_dir() const
Get data directory.
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object's.
Definition variant.hpp:191
void plugin_initialize(const variables_map &options)
wallet_manager & get_wallet_manager()
virtual void set_program_options(options_description &cli, options_description &cfg) override
#define FC_LOG_AND_RETHROW()
#define ilog(FORMAT,...)
Definition logger.hpp:118
application & app()
namespace sysio::chain
Definition authority.cpp:3
unsigned short uint16_t
Definition stdint.h:125
signed __int64 int64_t
Definition stdint.h:135
void cli()