Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 01ed1460e3 | |||
| bd7fb25315 | |||
| cdf439d83f | |||
| d47d988a72 | |||
| 1c06a70b58 | |||
| 20c20f5522 | |||
| a275227d76 | |||
| ac1425cbcb | |||
| f1a39778cb | |||
| 79e5c63a7d | |||
| d58b8a8f8d | |||
| 37d2297a2b | |||
| 5afa141942 |
@@ -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
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "cryptoforknote-util",
|
||||
"version": "15.5.13",
|
||||
"version": "15.6.0",
|
||||
"author": {
|
||||
"name": "LucasJones",
|
||||
"email": "lucasjonesdev@hotmail.co.uk"
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -287,11 +287,7 @@ namespace cryptonote
|
||||
}
|
||||
crypto::hash tree_root_hash = get_tx_tree_hash(b);
|
||||
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()+2));
|
||||
} else {
|
||||
blob.append(tools::get_varint_data(b.tx_hashes.size()+1));
|
||||
}
|
||||
blob.append(tools::get_varint_data(b.tx_hashes.size()+1));
|
||||
if (b.blob_type == BLOB_TYPE_CRYPTONOTE3) {
|
||||
blob.append(reinterpret_cast<const char*>(&b.uncle), sizeof(b.uncle));
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -60,6 +61,7 @@ namespace zephyr_oracle
|
||||
KV_SERIALIZE(reserve_ma)
|
||||
KV_SERIALIZE(reserve_ratio)
|
||||
KV_SERIALIZE(reserve_ratio_ma)
|
||||
KV_SERIALIZE(yield_price)
|
||||
KV_SERIALIZE(timestamp)
|
||||
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(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
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ const b = Buffer.from(
|
||||
const b2 = u.convert_blob(b, 15);
|
||||
const h1 = b2.toString('hex');
|
||||
|
||||
if (h1 === '010194a5ebb406f613c4e7514facf3e5b9923c885357b53f2b02f8e17f9721371296b99113035f00000000ac81ca3e7bc9369e63563923187d2cfdb42eac839c7fe24e6d5d0080c96d758f02') {
|
||||
if (h1 === '010194a5ebb406f613c4e7514facf3e5b9923c885357b53f2b02f8e17f9721371296b99113035f00000000ac81ca3e7bc9369e63563923187d2cfdb42eac839c7fe24e6d5d0080c96d758f01') {
|
||||
console.log('PASSED');
|
||||
} else {
|
||||
console.log('FAILED: ' + h1);
|
||||
|
||||
Reference in New Issue
Block a user