Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
sysio::trace_api::configuration_utils Namespace Reference

Functions

chain::abi_def abi_def_from_file (const std::string &file_name, const fc::path &data_dir)
 
std::pair< std::string, std::string > parse_kv_pairs (const std::string &input)
 

Function Documentation

◆ abi_def_from_file()

chain::abi_def sysio::trace_api::configuration_utils::abi_def_from_file ( const std::string & file_name,
const fc::path & data_dir )

Given a path (absolute or relative) to a file that contains a JSON-encoded ABI, return the parsed ABI

Parameters
file_name- a path to the ABI
data_dir- the base path for relative file_name values
Returns
the ABI implied
Exceptions
json_parse_exceptionif the JSON is malformed

Definition at line 10 of file configuration_utils.cpp.

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 }
#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)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ parse_kv_pairs()

std::pair< std::string, std::string > sysio::trace_api::configuration_utils::parse_kv_pairs ( const std::string & input)

Given a string in the form <key>=

where key cannot contain an = character and value can contain anything return a pair of the two independent strings

Parameters
input
Returns

Definition at line 28 of file configuration_utils.cpp.

28 {
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 }
Here is the caller graph for this function: