Files
hpcore/src/conf.hpp
Ravin Perera d8581f7ce9 General code optmisations and cleanup. (#15)
Updated `version_compare` based on this issue: #13 
Got rid of `replace_string_contents` helper func.
Replaced #define macros with static consts.
Moved comments from headers to source files.
2019-10-10 12:57:46 +05:30

87 lines
2.5 KiB
C++

#ifndef _HP_CONF_H_
#define _HP_CONF_H_
#include <rapidjson/document.h>
#include <vector>
using namespace std;
using namespace rapidjson;
/**
* Manages the central contract config and context structs.
* Contains functions to contract config operations such as create/rekey/load.
*/
namespace conf
{
// Holds contextual information about the currently loaded contract.
struct contract_ctx
{
string command; // The CLI command issued to launch HotPocket
string contractDir; // Contract base directory
string histDir; // Contract history dir
string stateDir; // Contract state dir
string configDir; // Contract config dir
string configFile; // Full path to the contract config file
};
// Holds all the contract config values.
struct contract_config
{
// Config elements which are initialized in memory (these are not directly loaded from the config file)
string pubkey; // Contract public key bytes
string seckey; // Contract secret key bytes
// Config elements which are loaded from the config file.
string pubkeyb64; // Contract base64 public key
string seckeyb64; // Contract base64 secret key
string binary; // Full path to the contract binary
string binargs; // CLI arguments to pass to the contract binary
string listenip; // The IPs to listen on for incoming connections
vector<string> peers; // List of peers in the format "<ip address>:<port>"
vector<string> unl; // Unique node list (list of base64 public keys)
unsigned short peerport; // Listening port for peer connections
int roundtime; // Consensus round time in ms
unsigned short pubport; // Listening port for public user connections
int pubmaxsize; // User message max size in bytes
int pubmaxcpm; // User message rate
};
// Global contract context struct exposed to the application.
// Other modeuls will access context values via this.
extern contract_ctx ctx;
// Global configuration struct exposed to the application.
// Other modeuls will access config values via this.
extern contract_config cfg;
int init();
int rekey();
int create_contract();
void set_contract_dir_paths(string basedir);
//------Internal-use functions for this namespace.
int load_config();
int save_config();
int validate_config();
int validate_contract_dir_paths();
int is_schema_valid(Document &d);
int binpair_to_b64();
int b64pair_to_bin();
} // namespace conf
#endif