Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
configuration_utils.cpp
Go to the documentation of this file.
3#include <regex>
4#include <fc/io/json.hpp>
5
6
8 using namespace sysio;
9
10 chain::abi_def abi_def_from_file(const std::string& file_name, const fc::path& data_dir )
11 {
12 fc::variant abi_variant;
13 auto abi_path = fc::path(file_name);
14 if (abi_path.is_relative()) {
15 abi_path = data_dir / abi_path;
16 }
17
18 SYS_ASSERT(fc::exists(abi_path) && !fc::is_directory(abi_path), chain::plugin_config_exception, "${path} does not exist or is not a file", ("path", abi_path.generic_string()));
19 try {
20 abi_variant = fc::json::from_file(abi_path);
21 } SYS_RETHROW_EXCEPTIONS(chain::json_parse_exception, "Fail to parse JSON from file: ${file}", ("file", abi_path.generic_string()));
22
23 chain::abi_def result;
24 fc::from_variant(abi_variant, result);
25 return result;
26 }
27
28 std::pair<std::string, std::string> parse_kv_pairs( const std::string& input ) {
29 SYS_ASSERT(!input.empty(), chain::plugin_config_exception, "Key-Value Pair is Empty");
30 auto delim = input.find("=");
31 SYS_ASSERT(delim != std::string::npos, chain::plugin_config_exception, "Missing \"=\"");
32 SYS_ASSERT(delim != 0, chain::plugin_config_exception, "Missing Key");
33 SYS_ASSERT(delim + 1 != input.size(), chain::plugin_config_exception, "Missing Value");
34 return std::make_pair(input.substr(0, delim), input.substr(delim + 1));
35 }
36
37}
#define SYS_ASSERT(expr, exc_type, FORMAT,...)
Definition exceptions.hpp:7
#define SYS_RETHROW_EXCEPTIONS(exception_type, FORMAT,...)
static variant from_file(const fc::path &p, const parse_type ptype=parse_type::legacy_parser, const uint32_t max_depth=DEFAULT_MAX_RECURSION_DEPTH)
Definition json.cpp:797
wraps boost::filesystem::path to provide platform independent path manipulation.
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object's.
Definition variant.hpp:191
bool exists(const path &p)
bool is_directory(const path &p)
void from_variant(const fc::variant &v, sysio::chain::chain_id_type &cid)
std::pair< std::string, std::string > parse_kv_pairs(const std::string &input)
chain::abi_def abi_def_from_file(const std::string &file_name, const fc::path &data_dir)