diff --git a/contrib/epee/include/net/http_client.h b/contrib/epee/include/net/http_client.h index 76d823b9..846c5db8 100644 --- a/contrib/epee/include/net/http_client.h +++ b/contrib/epee/include/net/http_client.h @@ -1051,6 +1051,52 @@ namespace epee } }; + template + 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(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 diff --git a/contrib/epee/include/storages/http_abstract_invoke.h b/contrib/epee/include/storages/http_abstract_invoke.h index 0b6ef8e3..fc27faaa 100644 --- a/contrib/epee/include/storages/http_abstract_invoke.h +++ b/contrib/epee/include/storages/http_abstract_invoke.h @@ -34,6 +34,19 @@ namespace epee { namespace net_utils { + + template + 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 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") { diff --git a/src/currency_core/currency_basic.h b/src/currency_core/currency_basic.h index abfc69ae..59ab543a 100644 --- a/src/currency_core/currency_basic.h +++ b/src/currency_core/currency_basic.h @@ -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(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 diff --git a/src/currency_core/currency_config.h b/src/currency_core/currency_config.h index 5318bc33..77b3e342 100644 --- a/src/currency_core/currency_config.h +++ b/src/currency_core/currency_config.h @@ -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 \ No newline at end of file +#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@#@ \ No newline at end of file diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index c0365820..1faa8bb2 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -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(*it); + } + } return true; } //---------------------------------------------------------------------------------------------------- diff --git a/src/wallet/wallet_public_structs_defs.h b/src/wallet/wallet_public_structs_defs.h index f207fcd6..ad7c0e67 100644 --- a/src/wallet/wallet_public_structs_defs.h +++ b/src/wallet/wallet_public_structs_defs.h @@ -1178,6 +1178,18 @@ namespace wallet_public }; }; + struct assets_whitelist + { + std::vector 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)