mirror of
https://github.com/EvernodeXRPL/hpcore.git
synced 2026-07-30 10:30:24 +00:00
Convert environment config to a key value map (#370)
This commit is contained in:
27
src/conf.cpp
27
src/conf.cpp
@@ -1031,6 +1031,23 @@ namespace conf
|
||||
return -1;
|
||||
}
|
||||
|
||||
contract.bin_path = jdoc["bin_path"].as<std::string>();
|
||||
contract.bin_args = jdoc["bin_args"].as<std::string>();
|
||||
contract.max_input_ledger_offset = jdoc["max_input_ledger_offset"].as<uint16_t>();
|
||||
|
||||
jpath = "contract.environment";
|
||||
for (const auto &obj : jdoc["environment"].object_range())
|
||||
{
|
||||
// Environment variable values should be strings.
|
||||
if (!obj.value().is_string())
|
||||
{
|
||||
std::cerr << jpath << "." << obj.key() << " environment variable should be a string.\n";
|
||||
return -1;
|
||||
}
|
||||
|
||||
contract.environment.emplace(obj.key(), obj.value().as<std::string>());
|
||||
}
|
||||
|
||||
jpath = "contract.unl";
|
||||
contract.unl.clear();
|
||||
for (auto &nodepk : jdoc["unl"].array_range())
|
||||
@@ -1050,12 +1067,6 @@ namespace conf
|
||||
return -1;
|
||||
}
|
||||
|
||||
contract.bin_path = jdoc["bin_path"].as<std::string>();
|
||||
contract.bin_args = jdoc["bin_args"].as<std::string>();
|
||||
contract.environment = jdoc["environment"].as<std::string>();
|
||||
contract.max_input_ledger_offset = jdoc["max_input_ledger_offset"].as<uint16_t>();
|
||||
|
||||
|
||||
jpath = "contract.consensus";
|
||||
contract.consensus.roundtime = jdoc["consensus"]["roundtime"].as<uint32_t>();
|
||||
if (contract.consensus.roundtime < 1 || contract.consensus.roundtime > MAX_ROUND_TIME)
|
||||
@@ -1109,8 +1120,8 @@ namespace conf
|
||||
|
||||
contract.runtime_env_args.clear();
|
||||
// Populate runtime environment args.
|
||||
if (!contract.environment.empty())
|
||||
util::split_string(contract.runtime_env_args, contract.environment, " ");
|
||||
for (const auto &[key, val] : contract.environment)
|
||||
contract.runtime_env_args.push_back(key + "=" + val);
|
||||
|
||||
contract.runtime_binexec_args.clear();
|
||||
// Populate runtime contract execution args.
|
||||
|
||||
22
src/conf.hpp
22
src/conf.hpp
@@ -125,7 +125,7 @@ namespace conf
|
||||
};
|
||||
|
||||
// Broadcasting mode of consensus and npl
|
||||
enum MODE
|
||||
enum MODE
|
||||
{
|
||||
PUBLIC,
|
||||
PRIVATE
|
||||
@@ -171,15 +171,15 @@ namespace conf
|
||||
|
||||
struct consensus_config
|
||||
{
|
||||
MODE mode; // If PUBLIC, consensus are broadcasted to non-unl nodes as well.
|
||||
std::atomic<uint32_t> roundtime = 0; // Consensus round time in ms (max: 3,600,000).
|
||||
std::atomic<uint32_t> stage_slice = 0; // Percentage slice of round time that stages 0,1,2 get (max: 33).
|
||||
MODE mode; // If PUBLIC, consensus are broadcasted to non-unl nodes as well.
|
||||
std::atomic<uint32_t> roundtime = 0; // Consensus round time in ms (max: 3,600,000).
|
||||
std::atomic<uint32_t> stage_slice = 0; // Percentage slice of round time that stages 0,1,2 get (max: 33).
|
||||
uint16_t threshold = 0;
|
||||
};
|
||||
|
||||
struct npl_config
|
||||
{
|
||||
MODE mode; // If PUBLIC, npl messages are broadcasted to non-unl nodes as well.
|
||||
MODE mode; // If PUBLIC, npl messages are broadcasted to non-unl nodes as well.
|
||||
};
|
||||
|
||||
struct contract_config
|
||||
@@ -189,12 +189,12 @@ namespace conf
|
||||
ugid run_as; // The user/groups id to execute the contract as.
|
||||
contract_log_config log; // Contract log related settings.
|
||||
|
||||
std::string version; // Contract version string.
|
||||
std::set<std::string> unl; // Unique node list (list of binary public keys).
|
||||
std::string bin_path; // Full path to the contract binary.
|
||||
std::string bin_args; // CLI arguments to pass to the contract binary.
|
||||
std::string environment; // Environment variables to be passed into contract.
|
||||
uint16_t max_input_ledger_offset; // Maximum ledger sequence number offset that can be specified in the input.
|
||||
std::string version; // Contract version string.
|
||||
std::set<std::string> unl; // Unique node list (list of binary public keys).
|
||||
std::string bin_path; // Full path to the contract binary.
|
||||
std::string bin_args; // CLI arguments to pass to the contract binary.
|
||||
std::map<std::string, std::string> environment; // Environment variables to be passed into contract.
|
||||
uint16_t max_input_ledger_offset; // Maximum ledger sequence number offset that can be specified in the input.
|
||||
consensus_config consensus;
|
||||
npl_config npl;
|
||||
round_limits_config round_limits;
|
||||
|
||||
@@ -111,7 +111,7 @@ do
|
||||
id: '3c349abe-4d70-4f50-9fa6-018f1f2530ab', \
|
||||
bin_path: '$binary', \
|
||||
bin_args: '$binargs', \
|
||||
environment: '', \
|
||||
environment: {}, \
|
||||
consensus: { \
|
||||
...require('./tmp.json').contract.consensus, \
|
||||
mode: 'public', \
|
||||
|
||||
Reference in New Issue
Block a user