MCPcopy Create free account
hub / github.com/bcndev/bytecoin / open_wallet_cache

Method open_wallet_cache

src/Core/WalletNodeExt.cpp:78–121  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

76}
77
78void WalletNodeExt::open_wallet_cache(const http::RequestBody &raw_request, const json_rpc::Request &raw_js_request) {
79#ifdef __EMSCRIPTEN__
80 if (!wallet) {
81 if (ext_who) {
82 http::ResponseBody last_http_response(raw_request.r);
83 last_http_response.r.headers.push_back({"Content-Type", "application/json; charset=utf-8"});
84 last_http_response.r.status = 200;
85 last_http_response.set_body(json_rpc::create_error_response_body(
86 json_rpc::Error(api::WALLET_FILE_WRITE_ERROR, "Cannot read wallet file"), raw_js_request));
87 http::Server::write(ext_who, std::move(last_http_response));
88 }
89 return;
90 }
91 std::string cache_name = wallet->get_cache_name() + Wallet::net_append(m_currency.net);
92 wallet_state_db = std::make_unique<WalletState::DB>(platform::O_OPEN_ALWAYS, cache_name, [=]() {
93 try {
94 std::cout << "on_ext_create_wallet callback" << std::endl;
95 wallet_state =
96 std::make_unique<WalletState>(*wallet, m_log.get_logger(), m_config, m_currency, *wallet_state_db);
97 m_wallet_sync =
98 std::make_unique<WalletSync>(m_log.get_logger(), *wallet_state, [this]() { advance_long_poll(); });
99 std::cout << "on_ext_create_wallet finish" << std::endl;
100 if (ext_who) {
101 api::walletd::ExtCreateWallet::Response response;
102 response.wallet_file = wallet->get_cache_name() + ".wallet.memory";
103 http::ResponseBody last_http_response(raw_request.r);
104 last_http_response.r.headers.push_back({"Content-Type", "application/json; charset=utf-8"});
105 last_http_response.r.status = 200;
106 last_http_response.set_body(json_rpc::create_response_body(response, raw_js_request));
107 http::Server::write(ext_who, std::move(last_http_response));
108 }
109 } catch (const std::exception &ex) {
110 if (ext_who) {
111 http::ResponseBody last_http_response(raw_request.r);
112 last_http_response.r.headers.push_back({"Content-Type", "application/json; charset=utf-8"});
113 last_http_response.r.status = 200;
114 last_http_response.set_body(json_rpc::create_error_response_body(
115 json_rpc::Error(json_rpc::INTERNAL_ERROR, common::what(ex)), raw_js_request));
116 http::Server::write(ext_who, std::move(last_http_response));
117 }
118 }
119 });
120#endif
121}
122
123bool WalletNodeExt::on_ext_create_wallet(http::Client *who, http::RequestBody &&raw_request,
124 json_rpc::Request &&raw_js_request, api::walletd::ExtCreateWallet::Request &&request,

Callers

nothing calls this directly

Calls 6

create_response_bodyFunction · 0.85
get_cache_nameMethod · 0.80
ErrorClass · 0.50
writeFunction · 0.50
set_bodyMethod · 0.45

Tested by

no test coverage detected