Compare commits

...

13 Commits

Author SHA1 Message Date
MoneroOcean 01ed1460e3 ZEPH 2.0 support 2024-10-07 07:50:42 +03:00
MoneroOcean bd7fb25315 Fixed CI 2024-10-07 07:47:45 +03:00
MoneroOcean cdf439d83f Fixed CI 2024-10-07 07:42:49 +03:00
MoneroOcean d47d988a72 Fixed CI 2024-10-07 07:36:33 +03:00
MoneroOcean 1c06a70b58 Fixed merge 2024-10-07 07:33:17 +03:00
MoneroOcean 20c20f5522 Fixed CI 2024-10-07 07:28:51 +03:00
MoneroOcean a275227d76 Fixed CI 2024-10-07 07:26:39 +03:00
MoneroOcean ac1425cbcb Added CI tests 2024-10-07 07:19:59 +03:00
ZephyrProtocol f1a39778cb Fix ordering of PR fields for yield_price serialization 2024-10-07 07:12:11 +03:00
ZephyrProtocol 79e5c63a7d Update pricing record serialization for Zephyr version v2.0.0 2024-10-07 07:11:51 +03:00
MoneroOcean d58b8a8f8d Added SAL support 2024-07-20 19:17:54 +03:00
MoneroOcean 37d2297a2b Added SAL support 2024-07-20 19:12:47 +03:00
MoneroOcean 5afa141942 Added SAL support 2024-07-20 19:11:34 +03:00
9 changed files with 168 additions and 13 deletions
+19
View File
@@ -0,0 +1,19 @@
on: push
name: Test
jobs:
build_lin:
name: Ubuntu test
runs-on: ubuntu-latest
steps:
- name: Prepare Ubuntu tools
run: |
sudo apt update
sudo apt-get install -y libboost-dev libboost-system-dev libboost-date-time-dev libsodium-dev
- name: Checkout code
uses: actions/checkout@master
- name: Test
run: |
npm install
./tests/run.sh
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "cryptoforknote-util", "name": "cryptoforknote-util",
"version": "15.5.13", "version": "15.6.0",
"author": { "author": {
"name": "LucasJones", "name": "LucasJones",
"email": "lucasjonesdev@hotmail.co.uk" "email": "lucasjonesdev@hotmail.co.uk"
+15 -1
View File
@@ -1082,10 +1082,24 @@ namespace cryptonote
} else if (blob_type == BLOB_TYPE_CRYPTONOTE_SALVIUM) { } else if (blob_type == BLOB_TYPE_CRYPTONOTE_SALVIUM) {
if (major_version >= 2) FIELD(salvium_pricing_record) if (major_version >= 2) FIELD(salvium_pricing_record)
} else if (blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR) { } else if (blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR) {
if (major_version >= 4) if (major_version >= 6)
{ {
FIELD_N("pricing_record", zephyr_pricing_record) 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) else if (major_version >= 3)
{ {
zephyr_oracle::pricing_record_v2 pr_v2; zephyr_oracle::pricing_record_v2 pr_v2;
@@ -287,11 +287,7 @@ namespace cryptonote
} }
crypto::hash tree_root_hash = get_tx_tree_hash(b); crypto::hash tree_root_hash = get_tx_tree_hash(b);
blob.append(reinterpret_cast<const char*>(&tree_root_hash), sizeof(tree_root_hash)); blob.append(reinterpret_cast<const char*>(&tree_root_hash), sizeof(tree_root_hash));
if (b.blob_type == BLOB_TYPE_CRYPTONOTE_SALVIUM) { blob.append(tools::get_varint_data(b.tx_hashes.size()+1));
blob.append(tools::get_varint_data(b.tx_hashes.size()+2));
} else {
blob.append(tools::get_varint_data(b.tx_hashes.size()+1));
}
if (b.blob_type == BLOB_TYPE_CRYPTONOTE3) { if (b.blob_type == BLOB_TYPE_CRYPTONOTE3) {
blob.append(reinterpret_cast<const char*>(&b.uncle), sizeof(b.uncle)); blob.append(reinterpret_cast<const char*>(&b.uncle), sizeof(b.uncle));
} }
+53 -2
View File
@@ -40,7 +40,7 @@
template <template <bool> class Archive> template <template <bool> class Archive>
bool do_serialize(Archive<false> &ar, zephyr_oracle::pricing_record &pr, uint8_t version) bool do_serialize(Archive<false> &ar, zephyr_oracle::pricing_record &pr, uint8_t version)
{ {
if (version >= 4) if (version >= 6)
{ {
// very basic sanity check // very basic sanity check
if (ar.remaining_bytes() < sizeof(zephyr_oracle::pricing_record)) { 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()) if (!ar.good())
return false; 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) else if (version >= 3)
{ {
// very basic sanity check // very basic sanity check
@@ -91,10 +106,17 @@ bool do_serialize(Archive<true> &ar, zephyr_oracle::pricing_record &pr, uint8_t
{ {
ar.begin_string(); ar.begin_string();
if (version >= 4) if (version >= 6)
{ {
ar.serialize_blob(&pr, sizeof(zephyr_oracle::pricing_record), ""); 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) else if (version >= 3)
{ {
zephyr_oracle::pricing_record_v2 pr_v2; 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; 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);
BLOB_SERIALIZER(zephyr_oracle::pricing_record_v1); BLOB_SERIALIZER(zephyr_oracle::pricing_record_v1);
BLOB_SERIALIZER(zephyr_oracle::pricing_record_v2); BLOB_SERIALIZER(zephyr_oracle::pricing_record_v2);
BLOB_SERIALIZER(zephyr_oracle::pricing_record_v3);
+7 -1
View File
@@ -31,7 +31,7 @@
namespace zephyr_oracle { 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 class asset_type_counts
{ {
@@ -42,11 +42,13 @@ namespace zephyr_oracle {
uint64_t ZEPH; uint64_t ZEPH;
uint64_t ZEPHUSD; uint64_t ZEPHUSD;
uint64_t ZEPHRSV; uint64_t ZEPHRSV;
uint64_t ZYIELD;
asset_type_counts() noexcept asset_type_counts() noexcept
: ZEPH(0) : ZEPH(0)
, ZEPHUSD(0) , ZEPHUSD(0)
, ZEPHRSV(0) , ZEPHRSV(0)
, ZYIELD(0)
{ {
} }
@@ -58,6 +60,8 @@ namespace zephyr_oracle {
return ZEPHUSD; return ZEPHUSD;
} else if (asset_type == "ZEPHRSV") { } else if (asset_type == "ZEPHRSV") {
return ZEPHRSV; return ZEPHRSV;
} else if (asset_type == "ZYIELD") {
return ZYIELD;
} }
return 0; return 0;
@@ -71,6 +75,8 @@ namespace zephyr_oracle {
ZEPHUSD += val; ZEPHUSD += val;
} else if (asset_type == "ZEPHRSV") { } else if (asset_type == "ZEPHRSV") {
ZEPHRSV += val; ZEPHRSV += val;
} else if (asset_type == "ZYIELD") {
ZYIELD += val;
} }
} }
}; };
+11 -2
View File
@@ -48,6 +48,7 @@ namespace zephyr_oracle
uint64_t reserve_ma; uint64_t reserve_ma;
uint64_t reserve_ratio; uint64_t reserve_ratio;
uint64_t reserve_ratio_ma; uint64_t reserve_ratio_ma;
uint64_t yield_price;
uint64_t timestamp; uint64_t timestamp;
std::string signature; std::string signature;
@@ -60,6 +61,7 @@ namespace zephyr_oracle
KV_SERIALIZE(reserve_ma) KV_SERIALIZE(reserve_ma)
KV_SERIALIZE(reserve_ratio) KV_SERIALIZE(reserve_ratio)
KV_SERIALIZE(reserve_ratio_ma) KV_SERIALIZE(reserve_ratio_ma)
KV_SERIALIZE(yield_price)
KV_SERIALIZE(timestamp) KV_SERIALIZE(timestamp)
KV_SERIALIZE(signature) KV_SERIALIZE(signature)
END_KV_SERIALIZE_MAP() END_KV_SERIALIZE_MAP()
@@ -75,6 +77,7 @@ namespace zephyr_oracle
, reserve_ma(0) , reserve_ma(0)
, reserve_ratio(0) , reserve_ratio(0)
, reserve_ratio_ma(0) , reserve_ratio_ma(0)
, yield_price(0)
, timestamp(0) , timestamp(0)
{ {
std::memset(signature, 0, sizeof(signature)); std::memset(signature, 0, sizeof(signature));
@@ -94,6 +97,7 @@ namespace zephyr_oracle
reserve_ma = in.reserve_ma; reserve_ma = in.reserve_ma;
reserve_ratio = in.reserve_ratio; reserve_ratio = in.reserve_ratio;
reserve_ratio_ma = in.reserve_ratio_ma; reserve_ratio_ma = in.reserve_ratio_ma;
yield_price = in.yield_price;
timestamp = in.timestamp; timestamp = in.timestamp;
for (unsigned int i = 0; i < in.signature.length(); i += 2) { for (unsigned int i = 0; i < in.signature.length(); i += 2) {
std::string byteString = in.signature.substr(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]); ss << std::hex << std::setw(2) << std::setfill('0') << (0xff & signature[i]);
sig_hex += ss.str(); 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); return out.store(dest, hparent);
} }
@@ -127,6 +131,7 @@ namespace zephyr_oracle
, reserve_ma(orig.reserve_ma) , reserve_ma(orig.reserve_ma)
, reserve_ratio(orig.reserve_ratio) , reserve_ratio(orig.reserve_ratio)
, reserve_ratio_ma(orig.reserve_ratio_ma) , reserve_ratio_ma(orig.reserve_ratio_ma)
, yield_price(orig.yield_price)
, timestamp(orig.timestamp) , timestamp(orig.timestamp)
{ {
std::memcpy(signature, orig.signature, sizeof(signature)); std::memcpy(signature, orig.signature, sizeof(signature));
@@ -142,6 +147,7 @@ namespace zephyr_oracle
reserve_ma = orig.reserve_ma; reserve_ma = orig.reserve_ma;
reserve_ratio = orig.reserve_ratio; reserve_ratio = orig.reserve_ratio;
reserve_ratio_ma = orig.reserve_ratio_ma; reserve_ratio_ma = orig.reserve_ratio_ma;
yield_price = orig.yield_price;
timestamp = orig.timestamp; timestamp = orig.timestamp;
::memcpy(signature, orig.signature, sizeof(signature)); ::memcpy(signature, orig.signature, sizeof(signature));
return *this; return *this;
@@ -157,6 +163,7 @@ namespace zephyr_oracle
(reserve_ma == other.reserve_ma) && (reserve_ma == other.reserve_ma) &&
(reserve_ratio == other.reserve_ratio) && (reserve_ratio == other.reserve_ratio) &&
(reserve_ratio_ma == other.reserve_ratio_ma) && (reserve_ratio_ma == other.reserve_ratio_ma) &&
(yield_price == other.yield_price) &&
(timestamp == other.timestamp) && (timestamp == other.timestamp) &&
!::memcmp(signature, other.signature, sizeof(signature))); !::memcmp(signature, other.signature, sizeof(signature)));
} }
@@ -233,8 +240,10 @@ namespace zephyr_oracle
return missing_rates; return missing_rates;
} else if (hf_version <= 4) { } else if (hf_version <= 4) {
return missing_rates || (reserve_ratio == 0); 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 bool pricing_record::has_essential_rates(const uint8_t hf_version) const noexcept
+60
View File
@@ -73,6 +73,18 @@ namespace zephyr_oracle
uint64_t timestamp; uint64_t timestamp;
unsigned char signature[64]; 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) #pragma pack(pop)
class pricing_record class pricing_record
{ {
@@ -88,6 +100,7 @@ namespace zephyr_oracle
uint64_t reserve_ma; uint64_t reserve_ma;
uint64_t reserve_ratio; uint64_t reserve_ratio;
uint64_t reserve_ratio_ma; uint64_t reserve_ratio_ma;
uint64_t yield_price;
uint64_t timestamp; uint64_t timestamp;
unsigned char signature[64]; 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(zephyr_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(zephyr_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 } // oracle
+1 -1
View File
@@ -7,7 +7,7 @@ const b = Buffer.from(
const b2 = u.convert_blob(b, 15); const b2 = u.convert_blob(b, 15);
const h1 = b2.toString('hex'); const h1 = b2.toString('hex');
if (h1 === '010194a5ebb406f613c4e7514facf3e5b9923c885357b53f2b02f8e17f9721371296b99113035f00000000ac81ca3e7bc9369e63563923187d2cfdb42eac839c7fe24e6d5d0080c96d758f02') { if (h1 === '010194a5ebb406f613c4e7514facf3e5b9923c885357b53f2b02f8e17f9721371296b99113035f00000000ac81ca3e7bc9369e63563923187d2cfdb42eac839c7fe24e6d5d0080c96d758f01') {
console.log('PASSED'); console.log('PASSED');
} else { } else {
console.log('FAILED: ' + h1); console.log('FAILED: ' + h1);