Far too many changes to track, but the key ones are:

1. rewrite of the Haven variation of the Pricing Record class to support:
   - versioning of the PR format
   - nested supply_data and asset_data structs
   - verification of the signature using a variable-length string (not R+S)

2. calculation of the slippage tallies for a block in add_block(), so that
   we can work out the yield that is due to be paid out for the block.

Loads of little fixes and cleanups.
This commit is contained in:
Some Random Crypto Guy
2024-01-10 23:21:56 +00:00
parent 6b791a3df2
commit 5ba22c2ec9
18 changed files with 465 additions and 236 deletions
+53 -6
View File
@@ -1104,7 +1104,7 @@ void fromJsonValue(const rapidjson::Value& val, cryptonote::rpc::error& error)
GET_FROM_JSON_OBJECT(val, error.error_str, error_str);
GET_FROM_JSON_OBJECT(val, error.message, message);
}
/*
void toJsonValue(rapidjson::Writer<epee::byte_stream>& dest, const std::pair<std::string, std::pair<uint64_t, uint64_t>>& pr_entry)
{
dest.StartObject();
@@ -1127,14 +1127,57 @@ void fromJsonValue(const rapidjson::Value& val, std::pair<std::string, std::pair
GET_FROM_JSON_OBJECT(val, pr_entry.second.first, spot);
GET_FROM_JSON_OBJECT(val, pr_entry.second.second, ma);
}
*/
void toJsonValue(rapidjson::Writer<epee::byte_stream>& dest, const oracle::supply_data& supply_data)
{
dest.StartObject();
INSERT_INTO_JSON_OBJECT(dest, fulm, supply_data.fulm);
INSERT_INTO_JSON_OBJECT(dest, fusd, supply_data.fusd);
dest.EndObject();
}
void fromJsonValue(const rapidjson::Value& val, oracle::supply_data& supply_data)
{
if (!val.IsObject())
{
throw WRONG_TYPE("json object");
}
GET_FROM_JSON_OBJECT(val, supply_data.fulm, fulm);
GET_FROM_JSON_OBJECT(val, supply_data.fusd, fusd);
}
void toJsonValue(rapidjson::Writer<epee::byte_stream>& dest, const oracle::asset_data& asset_data)
{
dest.StartObject();
INSERT_INTO_JSON_OBJECT(dest, asset_type, asset_data.asset_type);
INSERT_INTO_JSON_OBJECT(dest, spot, asset_data.spot_price);
INSERT_INTO_JSON_OBJECT(dest, ma, asset_data.ma_price);
dest.EndObject();
}
void fromJsonValue(const rapidjson::Value& val, oracle::asset_data& asset_data)
{
if (!val.IsObject())
{
throw WRONG_TYPE("json object");
}
GET_FROM_JSON_OBJECT(val, asset_data.asset_type, asset_type);
GET_FROM_JSON_OBJECT(val, asset_data.spot_price, spot);
GET_FROM_JSON_OBJECT(val, asset_data.ma_price, ma);
}
void toJsonValue(rapidjson::Writer<epee::byte_stream>& dest, const oracle::pricing_record& pricing_record)
{
dest.StartObject();
INSERT_INTO_JSON_OBJECT(dest, pr_version, pricing_record.pr_version);
INSERT_INTO_JSON_OBJECT(dest, spot, pricing_record.spot);
INSERT_INTO_JSON_OBJECT(dest, moving_average, pricing_record.moving_average);
INSERT_INTO_JSON_OBJECT(dest, assets, pricing_record.assets);
INSERT_INTO_JSON_OBJECT(dest, timestamp, pricing_record.timestamp);
INSERT_INTO_JSON_OBJECT(dest, signature, pricing_record.signature);
@@ -1149,10 +1192,14 @@ void fromJsonValue(const rapidjson::Value& val, oracle::pricing_record& pricing_
}
GET_FROM_JSON_OBJECT(val, pricing_record.pr_version, pr_version);
GET_FROM_JSON_OBJECT(val, pricing_record.spot, spot);
GET_FROM_JSON_OBJECT(val, pricing_record.moving_average, moving_average);
GET_FROM_JSON_OBJECT(val, pricing_record.assets, assets);
GET_FROM_JSON_OBJECT(val, pricing_record.timestamp, timestamp);
GET_FROM_JSON_OBJECT(val, boost::lexical_cast<std::string>(pricing_record.signature), signature);
std::string sig_hex;
std::ostringstream oss;
for (size_t i=0; i<pricing_record.signature.size(); ++i) {
oss << std::hex << std::setfill('0') << std::setw(2) << std::uppercase << (int)(pricing_record.signature[i]);
}
GET_FROM_JSON_OBJECT(val, oss.str(), signature);
}
void toJsonValue(rapidjson::Writer<epee::byte_stream>& dest, const cryptonote::rpc::BlockHeaderResponse& response)
+6 -2
View File
@@ -197,8 +197,12 @@ void fromJsonValue(const rapidjson::Value& val, long& i);
// end integers
void toJsonValue(rapidjson::Writer<epee::byte_stream>& dest, const std::pair<std::string, std::pair<uint64_t, uint64_t>>& entry);
void fromJsonValue(const rapidjson::Value& val, std::pair<std::string, std::pair<uint64_t, uint64_t>>& entry);
//void toJsonValue(rapidjson::Writer<epee::byte_stream>& dest, const std::pair<std::string, std::pair<uint64_t, uint64_t>>& entry);
//void fromJsonValue(const rapidjson::Value& val, std::pair<std::string, std::pair<uint64_t, uint64_t>>& entry);
void toJsonValue(rapidjson::Writer<epee::byte_stream>& dest, const oracle::supply_data& supply_data);
void fromJsonValue(const rapidjson::Value& val, oracle::supply_data& supply_data);
void toJsonValue(rapidjson::Writer<epee::byte_stream>& dest, const oracle::asset_data& asset_data);
void fromJsonValue(const rapidjson::Value& val, oracle::asset_data& asset_data);
void toJsonValue(rapidjson::Writer<epee::byte_stream>& dest, const oracle::pricing_record& pricing_record);
void fromJsonValue(const rapidjson::Value& val, oracle::pricing_record& pricing_record);
+50 -70
View File
@@ -37,38 +37,58 @@
#include "oracle/pricing_record.h"
#include "cryptonote_config.h"
// read
template <template <bool> class Archive>
bool do_serialize(Archive<false> &ar, oracle::supply_data &ad, uint8_t version)
{
assert(false);
return false;
}
// write
template <template <bool> class Archive>
bool do_serialize(Archive<true> &ar, oracle::supply_data &sd, uint8_t version)
{
ar.begin_string();
ar.serialize_blob(&sd, sizeof(oracle::supply_data), "");
if (!ar.good())
return false;
ar.end_string();
return true;
}
// read
template <template <bool> class Archive>
bool do_serialize(Archive<false> &ar, oracle::asset_data &ad, uint8_t version)
{
assert(false);
return false;
}
// write
template <template <bool> class Archive>
bool do_serialize(Archive<true> &ar, oracle::asset_data &ad, uint8_t version)
{
ar.begin_string();
ar.serialize_blob(&ad, sizeof(oracle::asset_data), "");
if (!ar.good())
return false;
ar.end_string();
return true;
}
// read
template <template <bool> class Archive>
bool do_serialize(Archive<false> &ar, oracle::pricing_record &pr, uint8_t version)
{
/*
if (version < HF_VERSION_SLIPPAGE_YIELD)
{
// very basic sanity check
if (ar.remaining_bytes() < sizeof(oracle::pricing_record_v1)) {
return false;
}
oracle::pricing_record_v1 pr_v1;
ar.serialize_blob(&pr_v1, sizeof(oracle::pricing_record_v1), "");
if (!ar.good())
return false;
if (!pr_v1.write_to_pr(pr))
return false;
}
else
*/
{
// very basic sanity check
if (ar.remaining_bytes() < sizeof(oracle::pricing_record)) {
return false;
}
ar.serialize_blob(&pr, sizeof(oracle::pricing_record), "");
if (!ar.good())
return false;
// very basic sanity check
if (ar.remaining_bytes() < sizeof(oracle::pricing_record)) {
return false;
}
ar.serialize_blob(&pr, sizeof(oracle::pricing_record), "");
if (!ar.good())
return false;
return true;
}
@@ -78,53 +98,13 @@ template <template <bool> class Archive>
bool do_serialize(Archive<true> &ar, oracle::pricing_record &pr, uint8_t version)
{
ar.begin_string();
/*
if (version < HF_VERSION_SLIPPAGE_YIELD)
{
oracle::pricing_record_v1 pr_v1;
if (!pr_v1.read_from_pr(pr))
return false;
ar.serialize_blob(&pr_v1, sizeof(oracle::pricing_record_v1), "");
}
else
*/
{
ar.serialize_blob(&pr, sizeof(oracle::pricing_record), "");
}
if (!ar.good())
return false;
ar.end_string();
return true;
}
// read
template <template <bool> class Archive>
bool do_serialize(Archive<false> &ar, oracle::pricing_record_v1 &pr, uint8_t version)
{
// very basic sanity check
if (ar.remaining_bytes() < sizeof(oracle::pricing_record_v1)) {
return false;
}
ar.serialize_blob(&pr, sizeof(oracle::pricing_record_v1), "");
if (!ar.good())
return false;
return true;
}
// write
template <template <bool> class Archive>
bool do_serialize(Archive<true> &ar, oracle::pricing_record_v1 &pr, uint8_t version)
{
ar.begin_string();
ar.serialize_blob(&pr, sizeof(oracle::pricing_record_v1), "");
ar.serialize_blob(&pr, sizeof(oracle::pricing_record), "");
if (!ar.good())
return false;
ar.end_string();
return true;
}
BLOB_SERIALIZER(oracle::supply_data);
BLOB_SERIALIZER(oracle::asset_data);
BLOB_SERIALIZER(oracle::pricing_record);
BLOB_SERIALIZER(oracle::pricing_record_v1);