mirror of
https://github.com/EvernodeXRPL/hpcore.git
synced 2026-04-29 15:37:59 +00:00
Introduced UNL update control message. (#169)
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
#include "../../pchheader.hpp"
|
||||
#include "../../util/util.hpp"
|
||||
#include "../../crypto.hpp"
|
||||
#include "../controlmsg_common.hpp"
|
||||
#include "controlmsg_json.hpp"
|
||||
|
||||
@@ -32,14 +34,14 @@ namespace msg::controlmsg::json
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
LOG_DEBUG << "User json message parsing failed.";
|
||||
LOG_ERROR << "Control json message parsing failed. " << e.what();
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Check existence of msg type field.
|
||||
if (!d.contains(msg::controlmsg::FLD_TYPE) || !d[msg::controlmsg::FLD_TYPE].is<std::string>())
|
||||
{
|
||||
LOG_DEBUG << "User json message 'type' missing or invalid.";
|
||||
LOG_ERROR << "Control json message 'type' missing or invalid.";
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -55,4 +57,40 @@ namespace msg::controlmsg::json
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts unl additions and removals from the json document.
|
||||
* Format:
|
||||
* {
|
||||
* "type": "unl_changeset",
|
||||
* "add": ["pk1","pk2",...]
|
||||
* "remove": ["pk1","pk2",...]
|
||||
* }
|
||||
*/
|
||||
int extract_unl_changeset(std::vector<std::string> &additions, std::vector<std::string> &removals, const jsoncons::json &d)
|
||||
{
|
||||
extract_string_array(additions, d, FLD_ADD);
|
||||
extract_string_array(removals, d, FLD_REMOVE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void extract_string_array(std::vector<std::string> &vec, const jsoncons::json &d, const char *field_name)
|
||||
{
|
||||
if (!d.contains(field_name) || !d[field_name].is_array())
|
||||
return;
|
||||
|
||||
for (const auto &v : d[field_name].array_range())
|
||||
{
|
||||
std::string hex_pubkey = "ed" + v.as<std::string>();
|
||||
std::string bin_pubkey;
|
||||
bin_pubkey.resize(crypto::PFXD_PUBKEY_BYTES);
|
||||
if (util::hex2bin(
|
||||
reinterpret_cast<unsigned char *>(bin_pubkey.data()),
|
||||
bin_pubkey.length(),
|
||||
hex_pubkey) != -1)
|
||||
{
|
||||
vec.push_back(bin_pubkey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace msg::controlmsg::json
|
||||
Reference in New Issue
Block a user