30 #ifndef ELECTRONEUM_VALIDATORS_H 31 #define ELECTRONEUM_VALIDATORS_H 33 #include <boost/algorithm/hex.hpp> 90 return this->startHeight;
94 return this->endHeight;
98 this->endHeight = end_height;
102 return height >= this->startHeight && (
height <= this->endHeight || this->endHeight == 0);
114 this->domain = domain;
122 this->page_link = page_link;
126 return this->page_link;
132 v.domain = this->domain;
133 v.page_link = this->page_link;
141 vector<std::unique_ptr<Validator>> list;
144 string endpoint_addr =
"vl.electroneum.com";
145 string endpoint_port =
"80";
146 string testnet_endpoint_addr =
"vl.thesecurityteam.rocks";
147 string testnet_endpoint_port =
"80";
148 milliseconds endpoint_timeout = milliseconds(10000);
149 string serialized_v_list;
153 uint32_t timeout_grace_period = this->timeout * 0.1;
156 bool testnet =
false;
160 void add(
const string &
key,
uint64_t startHeight,
uint64_t endHeight,
string name =
"",
string domain =
"",
string page_link =
"");
161 void addOrUpdate(
const string &
key,
uint64_t startHeight,
uint64_t endHeight,
string name =
"",
string domain =
"",
string page_link =
"");
162 void update(
const string &
key,
uint64_t endHeight,
string name =
"",
string domain =
"",
string page_link =
"");
163 std::unique_ptr<Validator> find(
const string &
key);
164 bool exists(
const string &
key);
170 testnet ? this->http_client.
set_server(this->testnet_endpoint_addr, this->testnet_endpoint_port, boost::none) :
171 this->http_client.
set_server(this->endpoint_addr, this->endpoint_port, boost::none);
172 this->testnet = testnet;
173 this->m_p2p = pprotocol;
178 all_of(this->list.begin(), this->list.end(), [&
height, &keys, &convert_to_byte](std::unique_ptr<Validator> &v) {
179 if (v->isWithinRange(
height)) {
180 const string k = convert_to_byte ? unhex(v->getPublicKey()) : v->getPublicKey();
190 all_of(this->list.begin(), this->list.end(), [&
key, &result](std::unique_ptr<Validator> &v) {
191 if (v->getPublicKey() ==
key) {
207 LOG_PRINT_L1(
"Unable to get validator_list json from " << this->endpoint_addr <<
":" << this->endpoint_port);
210 this->timeout = 60*60*24;
214 MGINFO(
"Validators list loaded from JSON endpoint! Refresh in 12 hours");
220 this->timeout = 60*60*1;
221 MGINFO(
"Validators list loaded from peers! Refresh in 1 hour");
235 this->timeout = 60*60*1;
238 MGINFO(
"Validators list loaded from database! Refresh in 1 hour");
256 return this->serialized_v_list;
263 return validate_and_update(
res, saveToDB, isEmergencyUpdate);
289 #endif //ELECTRONEUM_VALIDATORS_H
virtual bool request_validators_list_to_all()=0
vector< string > getApplicablePublicKeys(uint64_t height, bool convert_to_byte=false)
bool set_server(const std::string &address, boost::optional< login > user, ssl_options_t ssl_options=ssl_support_t::e_ssl_support_autodetect)
bool isWithinRange(uint64_t height)
Validator getValidatorInfo()
void setPageLink(string page_link)
Validator getValidatorByKey(string key)
void setDomain(string domain)
bool loadValidatorsList()
uint64_t getStartHeight()
const string getPublicKey()
Validators(cryptonote::BlockchainDB &db, cryptonote::i_cryptonote_protocol *pprotocol, bool testnet)
bool load_t_from_json(t_struct &out, const std::string &json_buff)
void setEndHeight(uint64_t end_height)
list_update_outcome setValidatorsList(const string &v_list, bool saveToDB, bool isEmergencyUpdate=false)
unsigned __int64 uint64_t
string getSerializedValidatorList()
The BlockchainDB backing store interface declaration/contract.
virtual std::string get_validator_list() const =0
bool get_http_json(const boost::string_ref uri, t_response &result_struct, t_transport &transport, std::chrono::milliseconds timeout=std::chrono::seconds(15), const boost::string_ref method="GET")
void setName(string name)
bool do_call(functor_t functr)