1
0
Fork 0
forked from lthn/blockchain

added pre-loading token whitelist via ssl

This commit is contained in:
cryptozoidberg 2022-11-17 21:58:36 +01:00
parent 20bc2fdf00
commit 490b8b12f1
No known key found for this signature in database
GPG key ID: 22DEB97A54C6FDEC
6 changed files with 103 additions and 2 deletions

View file

@ -1051,6 +1051,52 @@ namespace epee
}
};
template<typename transport_t>
bool fetch_url_t(transport_t& tr, const url_content& u_c, std::string& response_body, const std::string& method = "GET", const std::string& request_body = "", unsigned int timeout = 1000)
{
fields_list additional_params;
if (!tr.is_connected() && !u_c.host.empty())
{
if (!tr.connect(u_c.host, static_cast<int>(u_c.port), timeout))
{
LOG_PRINT_L2("invoke_request: cannot connect to " << u_c.host << ":" << u_c.port);
return false;
}
}
const http_response_info* ppresponse_info = nullptr;
if (tr.invoke(u_c.uri, "GET", request_body, &ppresponse_info, additional_params) && ppresponse_info)
{
response_body = ppresponse_info->m_body;
return true;
}
return false;
}
bool fetch_url(const std::string& url, std::string& response_body, const std::string& method = "GET", const std::string& request_body = "", unsigned int timeout = 1000)
{
try
{
url_content u_c = AUTO_VAL_INIT(u_c);
bool res = epee::net_utils::parse_url(url, u_c);
CHECK_AND_ASSERT_MES(res, false, "failed to parse url: " << url);
if (u_c.schema == "https")
{
https_simple_client tr;
return fetch_url_t(tr, u_c, response_body, method, request_body, timeout);
}
else
{
http_simple_client tr;
return fetch_url_t(tr, u_c, response_body, method, request_body, timeout);
}
}
catch (...)
{
return false;
}
}
} // namespace http

View file

@ -34,6 +34,19 @@ namespace epee
{
namespace net_utils
{
template<class t_response>
bool get_http_json_t(const std::string& url, t_response& result_struct, unsigned int timeout = 5000, const std::string& method = "GET")
{
std::string body;
if (!http::fetch_url(url, body, method, "", timeout))
{
return false;
}
return serialization::load_t_from_json(result_struct, body);
}
template<class t_request, class t_response, class t_transport>
bool invoke_http_json_remote_command2(const std::string& url, t_request& out_struct, t_response& result_struct, t_transport& transport, unsigned int timeout = 5000, const std::string& method = "GET")
{

View file

@ -770,6 +770,24 @@ namespace currency
};
struct asset_descriptor_with_id: public asset_descriptor_base
{
crypto::hash asset_id = currency::null_hash;
/*
BEGIN_VERSIONED_SERIALIZE()
FIELD(*static_cast<asset_descriptor_base>(this))
FIELD(asset_id)
END_SERIALIZE()
*/
BEGIN_KV_SERIALIZE_MAP()
KV_CHAIN_BASE(asset_descriptor_base)
KV_SERIALIZE_POD_AS_HEX_STRING(asset_id)
END_KV_SERIALIZE_MAP()
};
#define ASSET_DESCRIPTOR_OPERATION_UNDEFINED 0
#define ASSET_DESCRIPTOR_OPERATION_REGISTER 1
#define ASSET_DESCRIPTOR_OPERATION_EMMIT 2

View file

@ -269,4 +269,8 @@
static_assert(CURRENCY_MINER_TX_MAX_OUTS <= CURRENCY_TX_MAX_ALLOWED_OUTS, "Miner tx must obey normal tx max outs limit");
static_assert(PREMINE_AMOUNT / WALLET_MAX_ALLOWED_OUTPUT_AMOUNT < CURRENCY_MINER_TX_MAX_OUTS, "Premine can't be divided into reasonable number of outs");
#define CURRENCY_RELAY_TXS_MAX_COUNT 5
#define CURRENCY_RELAY_TXS_MAX_COUNT 5
#define WALLET_ASSETS_WHITELIST_URL "https://zano.org/assets_whitelist.json"
#define WALLET_ASSETS_WHITELIST_VALIDATION_PUBLIC_KEY "" //TODO@#@

View file

@ -3158,7 +3158,15 @@ bool wallet2::delete_custom_asset_id(const crypto::hash& asset_id)
//----------------------------------------------------------------------------------------------------
bool wallet2::load_whitelisted_tokens_list()
{
epee::net_utils::http::https_simple_client https_client;
std::string body;
wallet_public::assets_whitelist aw = AUTO_VAL_INIT(aw);
if (epee::net_utils::get_http_json_t(WALLET_ASSETS_WHITELIST_URL, aw))
{
for (auto it = aw.assets.begin(); it != aw.assets.end(); it++)
{
m_whitelisted_assets[it->asset_id] = static_cast<currency::asset_descriptor_base>(*it);
}
}
return true;
}
//----------------------------------------------------------------------------------------------------

View file

@ -1178,6 +1178,18 @@ namespace wallet_public
};
};
struct assets_whitelist
{
std::vector<currency::asset_descriptor_with_id> assets;
crypto::signature signature = currency::null_sig;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(assets)
KV_SERIALIZE_POD_AS_HEX_STRING(signature)
END_KV_SERIALIZE_MAP()
};
inline std::string get_escrow_contract_state_name(uint32_t state)
{
switch (state)