forked from lthn/blockchain
fixed serialization for hex-encoded array of pod items
This commit is contained in:
parent
95368faccd
commit
2c181de6a3
4 changed files with 47 additions and 4 deletions
|
|
@ -97,6 +97,40 @@ namespace epee
|
|||
return epee::string_encoding::base64_decode(a);
|
||||
}
|
||||
|
||||
|
||||
//basic helpers for pod-to-hex serialization
|
||||
template<class t_pod_container_type>
|
||||
std::string transform_t_pod_array_to_hex_str_array(const t_pod_container_type& a)
|
||||
{
|
||||
std::string res;
|
||||
for (const auto& item : a)
|
||||
{
|
||||
res += epee::string_tools::pod_to_hex(a) + ", ";
|
||||
}
|
||||
if (a.size())
|
||||
{
|
||||
res.erase(res.size() - 2);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
template<class t_pod_container_type>
|
||||
t_pod_container_type transform_hex_str_array_to_t_pod_array(const std::string& a)
|
||||
{
|
||||
std::vector<std::string> pod_items;
|
||||
boost::split(pod_items, a, boost::is_any_of(", ][\""));
|
||||
|
||||
t_pod_container_type res;
|
||||
for (const auto& item : pod_items)
|
||||
{
|
||||
res.resize(res.size() + 1);
|
||||
t_pod_container_type::value_type& pod_val = res.back();
|
||||
|
||||
if (!epee::string_tools::hex_to_pod(item, pod_val))
|
||||
throw std::runtime_error(std::string("Unable to transform \"") + item + "\" to pod type " + typeid(t_pod_container_type::value_type).name());
|
||||
}
|
||||
return res;
|
||||
}
|
||||
//-------------------------------------------------------------------------------------------------------------------
|
||||
#pragma pack(push, 1)
|
||||
template<class first_t, class second_t>
|
||||
|
|
|
|||
|
|
@ -131,6 +131,10 @@ public: \
|
|||
static_assert(std::is_pod<decltype(this_ref.varialble)>::value, "t_type must be a POD type."); \
|
||||
KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE_N(varialble, val_name)
|
||||
|
||||
#define KV_SERIALIZE_CONTAINER_POD_AS_HEX_N(varialble, val_name) \
|
||||
KV_SERIALIZE_CUSTOM_N(varialble, std::string, epee::transform_t_pod_array_to_hex_str_array<decltype(varialble)>, epee::transform_hex_str_array_to_t_pod_array<decltype(varialble)>, val_name)
|
||||
|
||||
|
||||
#define KV_SERIALIZE_CONTAINER_POD_AS_BLOB_N(varialble, val_name) \
|
||||
epee::serialization::selector<is_store>::serialize_stl_container_pod_val_as_blob(this_ref.varialble, stg, hparent_section, val_name);
|
||||
|
||||
|
|
@ -145,6 +149,7 @@ public: \
|
|||
#define KV_SERIALIZE_VAL_POD_AS_BLOB(varialble) KV_SERIALIZE_VAL_POD_AS_BLOB_N(varialble, #varialble)
|
||||
#define KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE(varialble) KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE_N(varialble, #varialble) //skip is_pod compile time check
|
||||
#define KV_SERIALIZE_CONTAINER_POD_AS_BLOB(varialble) KV_SERIALIZE_CONTAINER_POD_AS_BLOB_N(varialble, #varialble)
|
||||
#define KV_SERIALIZE_CONTAINER_POD_AS_HEX(varialble) KV_SERIALIZE_CONTAINER_POD_AS_HEX_N(varialble, #varialble)
|
||||
#define KV_SERIALIZE_CUSTOM(varialble, stored_type, from_v_to_stored, from_stored_to_v) KV_SERIALIZE_CUSTOM_N(varialble, stored_type, from_v_to_stored, from_stored_to_v, #varialble)
|
||||
#define KV_SERIALIZE_POD_AS_HEX_STRING(varialble) KV_SERIALIZE_POD_AS_HEX_STRING_N(varialble, #varialble)
|
||||
#define KV_SERIALIZE_BLOB_AS_HEX_STRING(varialble) KV_SERIALIZE_BLOB_AS_HEX_STRING_N(varialble, #varialble)
|
||||
|
|
|
|||
|
|
@ -592,7 +592,7 @@ namespace currency
|
|||
KV_SERIALIZE(service_id)
|
||||
KV_SERIALIZE(instruction)
|
||||
KV_SERIALIZE_BLOB_AS_HEX_STRING(body)
|
||||
KV_SERIALIZE_CONTAINER_POD_AS_BLOB(security)
|
||||
KV_SERIALIZE_CONTAINER_POD_AS_HEX(security)
|
||||
KV_SERIALIZE(flags)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
|
|
|
|||
|
|
@ -38,9 +38,9 @@ void test_plain_wallet()
|
|||
std::string res = plain_wallet::init("127.0.0.1", "12111", "C:\\Users\\roky\\home\\", 0);
|
||||
|
||||
uint64_t instance_id = 0;
|
||||
res = plain_wallet::open("test_restored.zan", "111");
|
||||
//res = plain_wallet::restore("heart level clear fate sorrow childhood sent fate ceiling party third steel came ask mix neither message already almost vast date glide tumble color okay space",
|
||||
// "test_restored.zan", "111", "");
|
||||
res = plain_wallet::open("test_restored_2.zan", "111");
|
||||
//res = plain_wallet::restore("",
|
||||
// "test_restored_2.zan", "111", "");
|
||||
|
||||
|
||||
while(true)
|
||||
|
|
@ -60,6 +60,10 @@ void test_plain_wallet()
|
|||
invoke_body = "{\"method\":\"get_recent_txs_and_info\",\"params\":{\"offset\":0,\"count\":30,\"update_provision_info\":true}}";
|
||||
std::string res2 = plain_wallet::sync_call("invoke", instance_id, invoke_body);
|
||||
|
||||
invoke_body = "{\"method\":\"get_recent_txs_and_info2\",\"params\":{\"offset\":0,\"count\":30,\"update_provision_info\":true}}";
|
||||
res2 = plain_wallet::sync_call("invoke", instance_id, invoke_body);
|
||||
|
||||
|
||||
invoke_body = "{\"method\":\"getbalance\",\"params\":{}}";
|
||||
std::string res3 = plain_wallet::sync_call("invoke", instance_id, invoke_body);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue