Update pricing record serialization for Zephyr version v2.0.0
This commit is contained in:
committed by
MoneroOcean
parent
d58b8a8f8d
commit
79e5c63a7d
@@ -1082,10 +1082,24 @@ namespace cryptonote
|
||||
} else if (blob_type == BLOB_TYPE_CRYPTONOTE_SALVIUM) {
|
||||
if (major_version >= 2) FIELD(salvium_pricing_record)
|
||||
} else if (blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR) {
|
||||
if (major_version >= 4)
|
||||
if (major_version >= 6)
|
||||
{
|
||||
FIELD_N("pricing_record", zephyr_pricing_record)
|
||||
}
|
||||
else if (major_version >= 4)
|
||||
{
|
||||
zephyr_oracle::pricing_record_v3 pr_v3;
|
||||
if (!typename Archive<W>::is_saving())
|
||||
{
|
||||
FIELD(pr_v3)
|
||||
pr_v3.write_to_pr(zephyr_pricing_record);
|
||||
}
|
||||
else
|
||||
{
|
||||
pr_v3.read_from_pr(zephyr_pricing_record);
|
||||
FIELD(pr_v3)
|
||||
}
|
||||
}
|
||||
else if (major_version >= 3)
|
||||
{
|
||||
zephyr_oracle::pricing_record_v2 pr_v2;
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
template <template <bool> class Archive>
|
||||
bool do_serialize(Archive<false> &ar, zephyr_oracle::pricing_record &pr, uint8_t version)
|
||||
{
|
||||
if (version >= 4)
|
||||
if (version >= 6)
|
||||
{
|
||||
// very basic sanity check
|
||||
if (ar.remaining_bytes() < sizeof(zephyr_oracle::pricing_record)) {
|
||||
@@ -51,6 +51,21 @@ bool do_serialize(Archive<false> &ar, zephyr_oracle::pricing_record &pr, uint8_t
|
||||
if (!ar.good())
|
||||
return false;
|
||||
}
|
||||
else if (version >= 4)
|
||||
{
|
||||
// very basic sanity check
|
||||
if (ar.remaining_bytes() < sizeof(zephyr_oracle::pricing_record_v3)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
zephyr_oracle::pricing_record_v3 pr_v3;
|
||||
ar.serialize_blob(&pr_v3, sizeof(zephyr_oracle::pricing_record_v3), "");
|
||||
if (!ar.good())
|
||||
return false;
|
||||
|
||||
if (!pr_v3.write_to_pr(pr))
|
||||
return false;
|
||||
}
|
||||
else if (version >= 3)
|
||||
{
|
||||
// very basic sanity check
|
||||
@@ -91,10 +106,17 @@ bool do_serialize(Archive<true> &ar, zephyr_oracle::pricing_record &pr, uint8_t
|
||||
{
|
||||
ar.begin_string();
|
||||
|
||||
if (version >= 4)
|
||||
if (version >= 6)
|
||||
{
|
||||
ar.serialize_blob(&pr, sizeof(zephyr_oracle::pricing_record), "");
|
||||
}
|
||||
else if (version >= 4)
|
||||
{
|
||||
zephyr_oracle::pricing_record_v3 pr_v3;
|
||||
if (!pr_v3.read_from_pr(pr))
|
||||
return false;
|
||||
ar.serialize_blob(&pr_v3, sizeof(zephyr_oracle::pricing_record_v3), "");
|
||||
}
|
||||
else if (version >= 3)
|
||||
{
|
||||
zephyr_oracle::pricing_record_v2 pr_v2;
|
||||
@@ -172,6 +194,35 @@ bool do_serialize(Archive<true> &ar, zephyr_oracle::pricing_record_v2 &pr, uint8
|
||||
return true;
|
||||
}
|
||||
|
||||
// read
|
||||
template <template <bool> class Archive>
|
||||
bool do_serialize(Archive<false> &ar, zephyr_oracle::pricing_record_v3 &pr, uint8_t version)
|
||||
{
|
||||
// very basic sanity check
|
||||
if (ar.remaining_bytes() < sizeof(zephyr_oracle::pricing_record_v3)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ar.serialize_blob(&pr, sizeof(zephyr_oracle::pricing_record_v3), "");
|
||||
if (!ar.good())
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// write
|
||||
template <template <bool> class Archive>
|
||||
bool do_serialize(Archive<true> &ar, zephyr_oracle::pricing_record_v3 &pr, uint8_t version)
|
||||
{
|
||||
ar.begin_string();
|
||||
ar.serialize_blob(&pr, sizeof(zephyr_oracle::pricing_record_v3), "");
|
||||
if (!ar.good())
|
||||
return false;
|
||||
ar.end_string();
|
||||
return true;
|
||||
}
|
||||
|
||||
BLOB_SERIALIZER(zephyr_oracle::pricing_record);
|
||||
BLOB_SERIALIZER(zephyr_oracle::pricing_record_v1);
|
||||
BLOB_SERIALIZER(zephyr_oracle::pricing_record_v2);
|
||||
BLOB_SERIALIZER(zephyr_oracle::pricing_record_v3);
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
|
||||
namespace zephyr_oracle {
|
||||
|
||||
const std::vector<std::string> ASSET_TYPES = {"ZEPH", "ZEPHUSD", "ZEPHRSV"};
|
||||
const std::vector<std::string> ASSET_TYPES = {"ZEPH", "ZEPHUSD", "ZEPHRSV", "ZYIELD"};
|
||||
|
||||
class asset_type_counts
|
||||
{
|
||||
@@ -42,11 +42,13 @@ namespace zephyr_oracle {
|
||||
uint64_t ZEPH;
|
||||
uint64_t ZEPHUSD;
|
||||
uint64_t ZEPHRSV;
|
||||
uint64_t ZYIELD;
|
||||
|
||||
asset_type_counts() noexcept
|
||||
: ZEPH(0)
|
||||
, ZEPHUSD(0)
|
||||
, ZEPHRSV(0)
|
||||
, ZYIELD(0)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -58,6 +60,8 @@ namespace zephyr_oracle {
|
||||
return ZEPHUSD;
|
||||
} else if (asset_type == "ZEPHRSV") {
|
||||
return ZEPHRSV;
|
||||
} else if (asset_type == "ZYIELD") {
|
||||
return ZYIELD;
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -71,6 +75,8 @@ namespace zephyr_oracle {
|
||||
ZEPHUSD += val;
|
||||
} else if (asset_type == "ZEPHRSV") {
|
||||
ZEPHRSV += val;
|
||||
} else if (asset_type == "ZYIELD") {
|
||||
ZYIELD += val;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -48,6 +48,7 @@ namespace zephyr_oracle
|
||||
uint64_t reserve_ma;
|
||||
uint64_t reserve_ratio;
|
||||
uint64_t reserve_ratio_ma;
|
||||
uint64_t yield_price;
|
||||
uint64_t timestamp;
|
||||
std::string signature;
|
||||
|
||||
@@ -61,6 +62,7 @@ namespace zephyr_oracle
|
||||
KV_SERIALIZE(reserve_ratio)
|
||||
KV_SERIALIZE(reserve_ratio_ma)
|
||||
KV_SERIALIZE(timestamp)
|
||||
KV_SERIALIZE(yield_price)
|
||||
KV_SERIALIZE(signature)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
@@ -75,6 +77,7 @@ namespace zephyr_oracle
|
||||
, reserve_ma(0)
|
||||
, reserve_ratio(0)
|
||||
, reserve_ratio_ma(0)
|
||||
, yield_price(0)
|
||||
, timestamp(0)
|
||||
{
|
||||
std::memset(signature, 0, sizeof(signature));
|
||||
@@ -94,6 +97,7 @@ namespace zephyr_oracle
|
||||
reserve_ma = in.reserve_ma;
|
||||
reserve_ratio = in.reserve_ratio;
|
||||
reserve_ratio_ma = in.reserve_ratio_ma;
|
||||
yield_price = in.yield_price;
|
||||
timestamp = in.timestamp;
|
||||
for (unsigned int i = 0; i < in.signature.length(); i += 2) {
|
||||
std::string byteString = in.signature.substr(i, 2);
|
||||
@@ -114,7 +118,7 @@ namespace zephyr_oracle
|
||||
ss << std::hex << std::setw(2) << std::setfill('0') << (0xff & signature[i]);
|
||||
sig_hex += ss.str();
|
||||
}
|
||||
const pr_serialized out{spot,moving_average,stable,stable_ma,reserve,reserve_ma,reserve_ratio,reserve_ratio_ma,timestamp,sig_hex};
|
||||
const pr_serialized out{spot,moving_average,stable,stable_ma,reserve,reserve_ma,reserve_ratio,reserve_ratio_ma,yield_price,timestamp,sig_hex};
|
||||
return out.store(dest, hparent);
|
||||
}
|
||||
|
||||
@@ -127,6 +131,7 @@ namespace zephyr_oracle
|
||||
, reserve_ma(orig.reserve_ma)
|
||||
, reserve_ratio(orig.reserve_ratio)
|
||||
, reserve_ratio_ma(orig.reserve_ratio_ma)
|
||||
, yield_price(orig.yield_price)
|
||||
, timestamp(orig.timestamp)
|
||||
{
|
||||
std::memcpy(signature, orig.signature, sizeof(signature));
|
||||
@@ -142,6 +147,7 @@ namespace zephyr_oracle
|
||||
reserve_ma = orig.reserve_ma;
|
||||
reserve_ratio = orig.reserve_ratio;
|
||||
reserve_ratio_ma = orig.reserve_ratio_ma;
|
||||
yield_price = orig.yield_price;
|
||||
timestamp = orig.timestamp;
|
||||
::memcpy(signature, orig.signature, sizeof(signature));
|
||||
return *this;
|
||||
@@ -157,6 +163,7 @@ namespace zephyr_oracle
|
||||
(reserve_ma == other.reserve_ma) &&
|
||||
(reserve_ratio == other.reserve_ratio) &&
|
||||
(reserve_ratio_ma == other.reserve_ratio_ma) &&
|
||||
(yield_price == other.yield_price) &&
|
||||
(timestamp == other.timestamp) &&
|
||||
!::memcmp(signature, other.signature, sizeof(signature)));
|
||||
}
|
||||
@@ -233,8 +240,10 @@ namespace zephyr_oracle
|
||||
return missing_rates;
|
||||
} else if (hf_version <= 4) {
|
||||
return missing_rates || (reserve_ratio == 0);
|
||||
} else if (hf_version == 5) {
|
||||
return missing_rates || (reserve_ratio == 0) || (reserve_ratio_ma == 0);
|
||||
}
|
||||
return missing_rates || (reserve_ratio == 0) || (reserve_ratio_ma == 0);
|
||||
return missing_rates || (reserve_ratio == 0) || (reserve_ratio_ma == 0) || (yield_price == 0);
|
||||
}
|
||||
|
||||
bool pricing_record::has_essential_rates(const uint8_t hf_version) const noexcept
|
||||
|
||||
@@ -73,6 +73,18 @@ namespace zephyr_oracle
|
||||
uint64_t timestamp;
|
||||
unsigned char signature[64];
|
||||
};
|
||||
POD_CLASS pricing_record_pre_v3 {
|
||||
uint64_t spot;
|
||||
uint64_t moving_average;
|
||||
uint64_t stable;
|
||||
uint64_t stable_ma;
|
||||
uint64_t reserve;
|
||||
uint64_t reserve_ma;
|
||||
uint64_t reserve_ratio;
|
||||
uint64_t reserve_ratio_ma;
|
||||
uint64_t timestamp;
|
||||
unsigned char signature[64];
|
||||
};
|
||||
#pragma pack(pop)
|
||||
class pricing_record
|
||||
{
|
||||
@@ -88,6 +100,7 @@ namespace zephyr_oracle
|
||||
uint64_t reserve_ma;
|
||||
uint64_t reserve_ratio;
|
||||
uint64_t reserve_ratio_ma;
|
||||
uint64_t yield_price;
|
||||
uint64_t timestamp;
|
||||
unsigned char signature[64];
|
||||
|
||||
@@ -192,4 +205,51 @@ namespace zephyr_oracle
|
||||
};
|
||||
};
|
||||
|
||||
class pricing_record_v3
|
||||
{
|
||||
|
||||
public:
|
||||
uint64_t spot;
|
||||
uint64_t moving_average;
|
||||
uint64_t stable;
|
||||
uint64_t stable_ma;
|
||||
uint64_t reserve;
|
||||
uint64_t reserve_ma;
|
||||
uint64_t reserve_ratio;
|
||||
uint64_t reserve_ratio_ma;
|
||||
uint64_t timestamp;
|
||||
unsigned char signature[64];
|
||||
|
||||
bool write_to_pr(oracle::pricing_record &pr)
|
||||
{
|
||||
pr.spot = spot;
|
||||
pr.moving_average = moving_average;
|
||||
pr.stable = stable;
|
||||
pr.stable_ma = stable_ma;
|
||||
pr.reserve = reserve;
|
||||
pr.reserve_ma = reserve_ma;
|
||||
pr.reserve_ratio = reserve_ratio;
|
||||
pr.reserve_ratio_ma = reserve_ratio_ma;
|
||||
pr.yield_price = 0;
|
||||
pr.timestamp = timestamp;
|
||||
std::memcpy(pr.signature, signature, sizeof(pr.signature));
|
||||
return true;
|
||||
};
|
||||
|
||||
bool read_from_pr(oracle::pricing_record &pr)
|
||||
{
|
||||
spot = pr.spot;
|
||||
moving_average = pr.moving_average;
|
||||
stable = pr.stable;
|
||||
stable_ma = pr.stable_ma;
|
||||
reserve = pr.reserve;
|
||||
reserve_ma = pr.reserve_ma;
|
||||
reserve_ratio = pr.reserve_ratio;
|
||||
reserve_ratio_ma = pr.reserve_ratio_ma;
|
||||
timestamp = pr.timestamp;
|
||||
std::memcpy(signature, pr.signature, sizeof(signature));
|
||||
return true;
|
||||
};
|
||||
};
|
||||
|
||||
} // oracle
|
||||
|
||||
Reference in New Issue
Block a user