Compare commits
19 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| aa39526fe8 | |||
| 44ee67d21f | |||
| 0f9c969b83 | |||
| ac5dcc2133 | |||
| 069c83ef32 | |||
| 655f79b0e0 | |||
| 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.1",
|
||||
"author": {
|
||||
"name": "LucasJones",
|
||||
"email": "lucasjonesdev@hotmail.co.uk"
|
||||
|
||||
@@ -447,8 +447,11 @@ namespace cryptonote
|
||||
// SALVIUM-SPECIFIC FIELDS
|
||||
// TX type
|
||||
cryptonote::salvium_transaction_type tx_type;
|
||||
// Return address
|
||||
crypto::public_key return_address;
|
||||
// Return address list (must be at least 1 and at most BULLETPROOF_MAX_OUTPUTS-1 - the "-1" is for the change output)
|
||||
std::vector<crypto::public_key> return_address_list;
|
||||
//return_address_change_mask
|
||||
std::vector<uint8_t> return_address_change_mask;
|
||||
// Return TX public key
|
||||
crypto::public_key return_pubkey;
|
||||
// Source asset type
|
||||
@@ -737,8 +740,13 @@ namespace cryptonote
|
||||
if (tx_type != cryptonote::salvium_transaction_type::PROTOCOL) {
|
||||
VARINT_FIELD(amount_burnt)
|
||||
if (tx_type != cryptonote::salvium_transaction_type::MINER) {
|
||||
FIELD(return_address)
|
||||
FIELD(return_pubkey)
|
||||
if (type == cryptonote::salvium_transaction_type::TRANSFER && version >= TRANSACTION_VERSION_N_OUTS) {
|
||||
FIELD(return_address_list)
|
||||
FIELD(return_address_change_mask)
|
||||
} else {
|
||||
FIELD(return_address)
|
||||
FIELD(return_pubkey)
|
||||
}
|
||||
FIELD(source_asset_type)
|
||||
FIELD(destination_asset_type)
|
||||
VARINT_FIELD(amount_slippage_limit)
|
||||
@@ -915,6 +923,15 @@ namespace cryptonote
|
||||
amount_minted = 0;
|
||||
output_unlock_times.clear();
|
||||
collateral_indices.clear();
|
||||
// SAL
|
||||
tx_type = cryptonote::salvium_transaction_type::UNSET;
|
||||
return_address = cryptonote::null_pkey;
|
||||
return_address_list.clear();
|
||||
return_address_change_mask.clear();
|
||||
return_pubkey = cryptonote::null_pkey;
|
||||
source_asset_type.clear();
|
||||
destination_asset_type.clear();
|
||||
amount_slippage_limit = 0;
|
||||
}
|
||||
|
||||
inline
|
||||
@@ -1080,12 +1097,26 @@ namespace cryptonote
|
||||
if (blob_type == BLOB_TYPE_CRYPTONOTE_XHV) {
|
||||
FIELD(pricing_record)
|
||||
} else if (blob_type == BLOB_TYPE_CRYPTONOTE_SALVIUM) {
|
||||
if (major_version >= 2) FIELD(salvium_pricing_record)
|
||||
if (major_version >= 255) 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;
|
||||
|
||||
@@ -288,7 +288,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));
|
||||
blob.append(tools::get_varint_data(b.tx_hashes.size() + (b.major_version >= HF_VERSION_ENABLE_N_OUTS ? 2 : 1)));
|
||||
} else {
|
||||
blob.append(tools::get_varint_data(b.tx_hashes.size()+1));
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
#define HF_VERSION_XASSET_FEES_V2 17
|
||||
#define HF_VERSION_HAVEN2 18
|
||||
#define HF_VERSION_USE_COLLATERAL 20
|
||||
#define HF_VERSION_ENABLE_N_OUTS 2
|
||||
#define TRANSACTION_VERSION_N_OUTS 3
|
||||
|
||||
// UNLOCK TIMES
|
||||
#define TX_V6_OFFSHORE_UNLOCK_BLOCKS 21*720 // 21 day unlock time
|
||||
|
||||
@@ -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
|
||||
|
||||
+3
-3
@@ -2,14 +2,14 @@
|
||||
let u = require('../build/Release/cryptoforknote');
|
||||
|
||||
const b = Buffer.from(
|
||||
'010194a5ebb406f613c4e7514facf3e5b9923c885357b53f2b02f8e17f9721371296b99113035f00000000020001ffcb6d018f9ffec12d03125e128c041c8a2d41fab9ebe2a7a4b10afbef4e134ec7ba3151c8c730a644310353414c3c7334015f99bdbbe70161dafb2da2fd9a4285da893a7519cff350981a959f525c43e5c60211000000000000000000000000000000000001e3c7bfb00b00020001ffcb6d0023016b6961b458286074406192961c1f0e5236455f45fcd6c175c7142d6353a481d60400020000'
|
||||
'0202fdaca8b906b1670506d0dc45b11cbc87f9ceedfd0cbfa56c14da72ccc27c45105391d2340300000000020001ffbabe0501a1ca9fab2a035c20fce0617f61abf3872058e15b90650b2ac812bf344766f56ee54b680f571e0353414c3c863401618163d383093580900f735ea9ad5d3d0029dd94c2f2a35db88ec37dc32e863302110000bcdd9d15420000000000000000000001c8f2e7ca0a00020001ffbabe05002301bb1086494863ac8de0987e09f7193ac85a356f8abf8725202cbf4dea8b2611f20400020000'
|
||||
, 'hex');
|
||||
const b2 = u.convert_blob(b, 15);
|
||||
const h1 = b2.toString('hex');
|
||||
|
||||
if (h1 === '010194a5ebb406f613c4e7514facf3e5b9923c885357b53f2b02f8e17f9721371296b99113035f00000000ac81ca3e7bc9369e63563923187d2cfdb42eac839c7fe24e6d5d0080c96d758f02') {
|
||||
if (h1 === '0202fdaca8b906b1670506d0dc45b11cbc87f9ceedfd0cbfa56c14da72ccc27c45105391d2340300000000604ec6923c81b6477bb224a9c53158cea5c5aee36100aad59c498d3dab92750402') {
|
||||
console.log('PASSED');
|
||||
} else {
|
||||
console.log('FAILED: ' + h1);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user