bool rai_daemon::daemon_config::deserialize_json (bool & upgraded_a, boost::property_tree::ptree & tree_a) { auto error (false); try { if (!tree_a.empty ()) { auto version_l (tree_a.get_optional <std::string> ("version")); if (!version_l) { tree_a.put ("version", "1"); version_l = "1"; } upgraded_a |= upgrade_json (std::stoull (version_l.get ()), tree_a); rpc_enable = tree_a.get <bool> ("rpc_enable"); auto rpc_l (tree_a.get_child ("rpc")); error |= rpc.deserialize_json (rpc_l); auto & node_l (tree_a.get_child ("node")); error |= node.deserialize_json (upgraded_a, node_l); opencl_enable = tree_a.get <bool> ("opencl_enable"); auto & opencl_l (tree_a.get_child ("opencl")); error |= opencl.deserialize_json (opencl_l); } else { upgraded_a = true; serialize_json (tree_a); } } catch (std::runtime_error const &) { error = true; } return error; }
nano::error nano::rpc_config::deserialize_json (bool & upgraded_a, nano::jsonconfig & json) { if (!json.empty ()) { auto version_l (json.get_optional<unsigned> ("version")); if (!version_l) { version_l = 1; json.put ("version", *version_l); json.put ("max_request_size", max_request_size); json.erase ("frontier_request_limit"); json.erase ("chain_request_limit"); nano::jsonconfig rpc_process_l; rpc_process_l.put ("io_threads", rpc_process.io_threads); rpc_process_l.put ("ipc_port", rpc_process.ipc_port); rpc_process_l.put ("num_ipc_connections", rpc_process.num_ipc_connections); json.put_child ("process", rpc_process_l); upgraded_a = true; } auto rpc_secure_l (json.get_optional_child ("secure")); if (rpc_secure_l) { secure.deserialize_json (*rpc_secure_l); } json.get_required<boost::asio::ip::address_v6> ("address", address); json.get_optional<uint16_t> ("port", port); json.get_optional<bool> ("enable_control", enable_control); json.get_optional<uint8_t> ("max_json_depth", max_json_depth); json.get_optional<uint64_t> ("max_request_size", max_request_size); auto rpc_process_l (json.get_optional_child ("process")); if (rpc_process_l) { rpc_process_l->get_optional<unsigned> ("io_threads", rpc_process.io_threads); rpc_process_l->get_optional<uint16_t> ("ipc_port", rpc_process.ipc_port); rpc_process_l->get_optional<unsigned> ("num_ipc_connections", rpc_process.num_ipc_connections); } } else { upgraded_a = true; serialize_json (json); } return json.get_error (); }
bool serialize_json_stream (std::ostream & stream_a) { auto result (false); stream_a.seekp (0); try { boost::property_tree::ptree tree; serialize_json (tree); boost::property_tree::write_json (stream_a, tree); } catch (std::runtime_error const &) { result = true; } return result; }
bool deserialize_json (bool & upgraded_a, boost::property_tree::ptree & tree_a) { auto error (false); if (!tree_a.empty ()) { auto version_l (tree_a.get_optional<std::string> ("version")); if (!version_l) { tree_a.put ("version", "1"); version_l = "1"; upgraded_a = true; } upgraded_a |= upgrade_json (std::stoull (version_l.get ()), tree_a); auto wallet_l (tree_a.get<std::string> ("wallet")); auto account_l (tree_a.get<std::string> ("account")); auto & node_l (tree_a.get_child ("node")); rpc_enable = tree_a.get<bool> ("rpc_enable"); auto & rpc_l (tree_a.get_child ("rpc")); opencl_enable = tree_a.get<bool> ("opencl_enable"); auto & opencl_l (tree_a.get_child ("opencl")); try { error |= wallet.decode_hex (wallet_l); error |= account.decode_account (account_l); error |= node.deserialize_json (upgraded_a, node_l); error |= rpc.deserialize_json (rpc_l); error |= opencl.deserialize_json (opencl_l); if (wallet.is_zero ()) { rai::random_pool.GenerateBlock (wallet.bytes.data (), wallet.bytes.size ()); upgraded_a = true; } } catch (std::logic_error const &) { error = true; } } else { serialize_json (tree_a); upgraded_a = true; } return error; }