MCPcopy Create free account
hub / github.com/ElementsProject/elements / BanMapFromJson

Function BanMapFromJson

src/net_types.cpp:58–74  ·  view source on GitHub ↗

* Convert a JSON array to a `banmap_t` object. * @param[in] bans_json JSON to convert, must be as returned by `BanMapToJson()`. * @param[out] bans Bans list to create from the JSON. * @throws std::runtime_error if the JSON does not have the expected fields or they contain * unparsable values. */

Source from the content-addressed store, hash-verified

56 * unparsable values.
57 */
58void BanMapFromJson(const UniValue& bans_json, banmap_t& bans)
59{
60 for (const auto& ban_entry_json : bans_json.getValues()) {
61 const int version{ban_entry_json[BANMAN_JSON_VERSION_KEY].get_int()};
62 if (version != CBanEntry::CURRENT_VERSION) {
63 LogPrintf("Dropping entry with unknown version (%s) from ban list\n", version);
64 continue;
65 }
66 CSubNet subnet;
67 const auto& subnet_str = ban_entry_json[BANMAN_JSON_ADDR_KEY].get_str();
68 if (!LookupSubNet(subnet_str, subnet)) {
69 LogPrintf("Dropping entry with unparseable address or subnet (%s) from ban list\n", subnet_str);
70 continue;
71 }
72 bans.insert_or_assign(subnet, CBanEntry{ban_entry_json});
73 }
74}

Callers 1

ReadMethod · 0.85

Calls 2

LookupSubNetFunction · 0.85
get_intMethod · 0.80

Tested by

no test coverage detected