Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| dd63cb209d | |||
| 161ec204e6 | |||
| 2104ac35d5 | |||
| 30a1cf7813 | |||
| 32dfbcf8ea |
@@ -7,6 +7,7 @@
|
|||||||
"src/cryptonote_core/cryptonote_format_utils.cpp",
|
"src/cryptonote_core/cryptonote_format_utils.cpp",
|
||||||
"src/offshore/pricing_record.cpp",
|
"src/offshore/pricing_record.cpp",
|
||||||
"src/zephyr_oracle/pricing_record.cpp",
|
"src/zephyr_oracle/pricing_record.cpp",
|
||||||
|
"src/salvium_oracle/pricing_record.cpp",
|
||||||
"src/crypto/tree-hash.c",
|
"src/crypto/tree-hash.c",
|
||||||
"src/crypto/crypto.cpp",
|
"src/crypto/crypto.cpp",
|
||||||
"src/crypto/crypto-ops.c",
|
"src/crypto/crypto-ops.c",
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "cryptoforknote-util",
|
"name": "cryptoforknote-util",
|
||||||
"version": "15.5.2",
|
"version": "15.5.7",
|
||||||
"author": {
|
"author": {
|
||||||
"name": "LucasJones",
|
"name": "LucasJones",
|
||||||
"email": "lucasjonesdev@hotmail.co.uk"
|
"email": "lucasjonesdev@hotmail.co.uk"
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
#include "serialization/crypto.h"
|
#include "serialization/crypto.h"
|
||||||
#include "serialization/pricing_record.h"
|
#include "serialization/pricing_record.h"
|
||||||
#include "serialization/zephyr_pricing_record.h"
|
#include "serialization/zephyr_pricing_record.h"
|
||||||
|
#include "serialization/salvium_pricing_record.h"
|
||||||
#include "serialization/keyvalue_serialization.h" // eepe named serialization
|
#include "serialization/keyvalue_serialization.h" // eepe named serialization
|
||||||
#include "string_tools.h"
|
#include "string_tools.h"
|
||||||
#include "cryptonote_config.h"
|
#include "cryptonote_config.h"
|
||||||
@@ -28,6 +29,7 @@
|
|||||||
#include "cryptonote_protocol/blobdatatype.h"
|
#include "cryptonote_protocol/blobdatatype.h"
|
||||||
#include "offshore/pricing_record.h"
|
#include "offshore/pricing_record.h"
|
||||||
#include "zephyr_oracle/pricing_record.h"
|
#include "zephyr_oracle/pricing_record.h"
|
||||||
|
#include "salvium_oracle/pricing_record.h"
|
||||||
|
|
||||||
|
|
||||||
namespace cryptonote
|
namespace cryptonote
|
||||||
@@ -1051,6 +1053,7 @@ namespace cryptonote
|
|||||||
uint64_t nonce8;
|
uint64_t nonce8;
|
||||||
offshore::pricing_record pricing_record;
|
offshore::pricing_record pricing_record;
|
||||||
zephyr_oracle::pricing_record zephyr_pricing_record;
|
zephyr_oracle::pricing_record zephyr_pricing_record;
|
||||||
|
salvium_oracle::pricing_record salvium_pricing_record;
|
||||||
crypto::cycle cycle;
|
crypto::cycle cycle;
|
||||||
crypto::cycle40 cycle40;
|
crypto::cycle40 cycle40;
|
||||||
crypto::cycle48 cycle48;
|
crypto::cycle48 cycle48;
|
||||||
@@ -1075,8 +1078,9 @@ namespace cryptonote
|
|||||||
if (blob_type == BLOB_TYPE_CRYPTONOTE_XTNC || blob_type == BLOB_TYPE_CRYPTONOTE_CUCKOO) FIELD(cycle)
|
if (blob_type == BLOB_TYPE_CRYPTONOTE_XTNC || blob_type == BLOB_TYPE_CRYPTONOTE_CUCKOO) FIELD(cycle)
|
||||||
if (blob_type == BLOB_TYPE_CRYPTONOTE_TUBE) FIELD(cycle40)
|
if (blob_type == BLOB_TYPE_CRYPTONOTE_TUBE) FIELD(cycle40)
|
||||||
if (blob_type == BLOB_TYPE_CRYPTONOTE_XTA) FIELD(cycle48)
|
if (blob_type == BLOB_TYPE_CRYPTONOTE_XTA) FIELD(cycle48)
|
||||||
if (blob_type == BLOB_TYPE_CRYPTONOTE_XHV || blob_type == BLOB_TYPE_CRYPTONOTE_SAL) FIELD(pricing_record)
|
if (blob_type == BLOB_TYPE_CRYPTONOTE_XHV) FIELD(pricing_record)
|
||||||
if (blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR) {
|
else if (blob_type == BLOB_TYPE_CRYPTONOTE_SALVIUM) FIELD(salvium_pricing_record)
|
||||||
|
else if (blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR) {
|
||||||
if (major_version >= 4)
|
if (major_version >= 4)
|
||||||
{
|
{
|
||||||
FIELD_N("pricing_record", zephyr_pricing_record)
|
FIELD_N("pricing_record", zephyr_pricing_record)
|
||||||
|
|||||||
@@ -0,0 +1,77 @@
|
|||||||
|
// Copyright (c) 2021, Haven Protocol
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Redistribution and use in source and binary forms, with or without modification, are
|
||||||
|
// permitted provided that the following conditions are met:
|
||||||
|
//
|
||||||
|
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||||
|
// conditions and the following disclaimer.
|
||||||
|
//
|
||||||
|
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||||
|
// of conditions and the following disclaimer in the documentation and/or other
|
||||||
|
// materials provided with the distribution.
|
||||||
|
//
|
||||||
|
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
||||||
|
// used to endorse or promote products derived from this software without specific
|
||||||
|
// prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||||
|
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||||
|
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||||
|
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace salvium_oracle {
|
||||||
|
|
||||||
|
const std::vector<std::string> ASSET_TYPES = {"SAL", "VSD", "BURN"};
|
||||||
|
|
||||||
|
class asset_type_counts
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
// Fields
|
||||||
|
uint64_t SAL;
|
||||||
|
uint64_t VSD;
|
||||||
|
uint64_t BURN;
|
||||||
|
|
||||||
|
asset_type_counts() noexcept
|
||||||
|
: SAL(0)
|
||||||
|
, VSD(0)
|
||||||
|
, BURN(0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t operator[](const std::string asset_type) const noexcept
|
||||||
|
{
|
||||||
|
if (asset_type == "SAL") {
|
||||||
|
return SAL;
|
||||||
|
} else if (asset_type == "VSD") {
|
||||||
|
return VSD;
|
||||||
|
} else if (asset_type == "BURN") {
|
||||||
|
return BURN;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void add(const std::string asset_type, const uint64_t val)
|
||||||
|
{
|
||||||
|
if (asset_type == "SAL") {
|
||||||
|
SAL += val;
|
||||||
|
} else if (asset_type == "VSD") {
|
||||||
|
VSD += val;
|
||||||
|
} else if (asset_type == "BURN") {
|
||||||
|
BURN += val;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,316 @@
|
|||||||
|
// Copyright (c) 2019, Haven Protocol
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Redistribution and use in source and binary forms, with or without modification, are
|
||||||
|
// permitted provided that the following conditions are met:
|
||||||
|
//
|
||||||
|
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||||
|
// conditions and the following disclaimer.
|
||||||
|
//
|
||||||
|
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||||
|
// of conditions and the following disclaimer in the documentation and/or other
|
||||||
|
// materials provided with the distribution.
|
||||||
|
//
|
||||||
|
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
||||||
|
// used to endorse or promote products derived from this software without specific
|
||||||
|
// prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||||
|
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||||
|
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||||
|
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
//
|
||||||
|
// Portions of this code based upon code Copyright (c) 2019, The Monero Project
|
||||||
|
|
||||||
|
#include <boost/multiprecision/cpp_int.hpp>
|
||||||
|
#include "pricing_record.h"
|
||||||
|
|
||||||
|
#include "serialization/keyvalue_serialization.h"
|
||||||
|
#include "storages/portable_storage.h"
|
||||||
|
|
||||||
|
#include "string_tools.h"
|
||||||
|
namespace salvium_oracle
|
||||||
|
{
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
struct asset_data_serialized
|
||||||
|
{
|
||||||
|
std::string asset_type;
|
||||||
|
uint64_t spot_price;
|
||||||
|
uint64_t ma_price;
|
||||||
|
|
||||||
|
BEGIN_KV_SERIALIZE_MAP()
|
||||||
|
KV_SERIALIZE(asset_type)
|
||||||
|
KV_SERIALIZE(spot_price)
|
||||||
|
KV_SERIALIZE(ma_price)
|
||||||
|
END_KV_SERIALIZE_MAP()
|
||||||
|
};
|
||||||
|
|
||||||
|
struct supply_data_serialized
|
||||||
|
{
|
||||||
|
uint64_t SAL;
|
||||||
|
uint64_t VSD;
|
||||||
|
|
||||||
|
BEGIN_KV_SERIALIZE_MAP()
|
||||||
|
KV_SERIALIZE(SAL)
|
||||||
|
KV_SERIALIZE(VSD)
|
||||||
|
END_KV_SERIALIZE_MAP()
|
||||||
|
};
|
||||||
|
|
||||||
|
struct pr_serialized
|
||||||
|
{
|
||||||
|
uint64_t pr_version;
|
||||||
|
uint64_t height;
|
||||||
|
supply_data supply;
|
||||||
|
std::vector<asset_data> assets;
|
||||||
|
uint64_t timestamp;
|
||||||
|
std::string signature;
|
||||||
|
|
||||||
|
BEGIN_KV_SERIALIZE_MAP()
|
||||||
|
KV_SERIALIZE(pr_version)
|
||||||
|
KV_SERIALIZE(height)
|
||||||
|
KV_SERIALIZE(supply)
|
||||||
|
KV_SERIALIZE(assets)
|
||||||
|
KV_SERIALIZE(timestamp)
|
||||||
|
KV_SERIALIZE(signature)
|
||||||
|
END_KV_SERIALIZE_MAP()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
pricing_record::pricing_record() noexcept
|
||||||
|
: pr_version(0)
|
||||||
|
, height(0)
|
||||||
|
, supply()
|
||||||
|
, assets()
|
||||||
|
, timestamp(0)
|
||||||
|
, signature()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
pricing_record::~pricing_record() noexcept
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool supply_data::_load(epee::serialization::portable_storage& src, epee::serialization::section* hparent)
|
||||||
|
{
|
||||||
|
supply_data_serialized in{};
|
||||||
|
if (in._load(src, hparent))
|
||||||
|
{
|
||||||
|
// Copy everything into the local instance
|
||||||
|
sal = in.SAL;
|
||||||
|
vsd = in.VSD;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// Report error here?
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool supply_data::store(epee::serialization::portable_storage& dest, epee::serialization::section* hparent) const
|
||||||
|
{
|
||||||
|
const supply_data_serialized out{sal, vsd};
|
||||||
|
return out.store(dest, hparent);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool asset_data::_load(epee::serialization::portable_storage& src, epee::serialization::section* hparent)
|
||||||
|
{
|
||||||
|
asset_data_serialized in{};
|
||||||
|
if (in._load(src, hparent))
|
||||||
|
{
|
||||||
|
// Copy everything into the local instance
|
||||||
|
asset_type = in.asset_type;
|
||||||
|
spot_price = in.spot_price;
|
||||||
|
ma_price = in.ma_price;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// Report error here?
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool asset_data::store(epee::serialization::portable_storage& dest, epee::serialization::section* hparent) const
|
||||||
|
{
|
||||||
|
const asset_data_serialized out{asset_type, spot_price, ma_price};
|
||||||
|
return out.store(dest, hparent);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool pricing_record::_load(epee::serialization::portable_storage& src, epee::serialization::section* hparent)
|
||||||
|
{
|
||||||
|
pr_serialized in{};
|
||||||
|
if (in._load(src, hparent))
|
||||||
|
{
|
||||||
|
// Copy everything into the local instance
|
||||||
|
pr_version = in.pr_version;
|
||||||
|
height = in.height;
|
||||||
|
supply = in.supply;
|
||||||
|
assets = in.assets;
|
||||||
|
timestamp = in.timestamp;
|
||||||
|
|
||||||
|
// Signature arrives in HEX format, but needs to be used in BINARY format - convert it here
|
||||||
|
signature.resize(0);
|
||||||
|
assert(in.signature.size()%2 == 0);
|
||||||
|
signature.reserve(in.signature.size() >> 1);
|
||||||
|
for (unsigned int i = 0; i < in.signature.size(); i += 2) {
|
||||||
|
std::string byteString = in.signature.substr(i, 2);
|
||||||
|
signature.emplace_back((uint8_t)strtol(byteString.c_str(), NULL, 16));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Report error here?
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool pricing_record::store(epee::serialization::portable_storage& dest, epee::serialization::section* hparent) const
|
||||||
|
{
|
||||||
|
std::string sig_hex;
|
||||||
|
for (size_t i=0; i<signature.size(); ++i) {
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << std::hex << std::setw(2) << std::setfill('0') << (0xff & signature.at(i));
|
||||||
|
sig_hex += ss.str();
|
||||||
|
}
|
||||||
|
const pr_serialized out{pr_version, height, supply, assets, timestamp, sig_hex};
|
||||||
|
return out.store(dest, hparent);
|
||||||
|
}
|
||||||
|
|
||||||
|
pricing_record::pricing_record(const pricing_record& orig) noexcept
|
||||||
|
: pr_version(orig.pr_version)
|
||||||
|
, height(orig.height)
|
||||||
|
, supply(orig.supply)
|
||||||
|
, assets(orig.assets)
|
||||||
|
, timestamp(orig.timestamp)
|
||||||
|
, signature(orig.signature)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
pricing_record& pricing_record::operator=(const pricing_record& orig) noexcept
|
||||||
|
{
|
||||||
|
pr_version = orig.pr_version;
|
||||||
|
height = orig.height;
|
||||||
|
supply = orig.supply;
|
||||||
|
assets = orig.assets;
|
||||||
|
timestamp = orig.timestamp;
|
||||||
|
signature = orig.signature;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t pricing_record::operator[](const std::string& asset_type) const
|
||||||
|
{
|
||||||
|
for (const auto& asset: assets) {
|
||||||
|
if (asset.asset_type != asset_type) continue;
|
||||||
|
return asset.spot_price;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool pricing_record::equal(const pricing_record& other) const noexcept
|
||||||
|
{
|
||||||
|
return ((pr_version == other.pr_version) &&
|
||||||
|
(height == other.height) &&
|
||||||
|
(supply == other.supply) &&
|
||||||
|
(assets == other.assets) &&
|
||||||
|
(timestamp == other.timestamp) &&
|
||||||
|
(signature == other.signature));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool pricing_record::empty() const noexcept
|
||||||
|
{
|
||||||
|
const pricing_record empty_pr = salvium_oracle::pricing_record();
|
||||||
|
return (*this).equal(empty_pr);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool pricing_record::verifySignature(const std::string& public_key) const
|
||||||
|
{
|
||||||
|
CHECK_AND_ASSERT_THROW_MES(!public_key.empty(), "Pricing record verification failed. NULL public key. PK Size: " << public_key.size());
|
||||||
|
|
||||||
|
// extract the key
|
||||||
|
EVP_PKEY* pubkey;
|
||||||
|
BIO* bio = BIO_new_mem_buf(public_key.c_str(), public_key.size());
|
||||||
|
if (!bio) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
pubkey = PEM_read_bio_PUBKEY(bio, NULL, NULL, NULL);
|
||||||
|
BIO_free(bio);
|
||||||
|
CHECK_AND_ASSERT_THROW_MES(pubkey != NULL, "Pricing record verification failed. NULL public key.");
|
||||||
|
|
||||||
|
// Build the JSON string, so that we can verify the signature
|
||||||
|
std::ostringstream oss;
|
||||||
|
oss << "{\"pr_version\":" << pr_version;
|
||||||
|
oss << ",\"height\":" << height;
|
||||||
|
oss << ",\"supply\":{\"SAL\":" << supply.sal <<",\"VSD\":" << supply.vsd << "}";
|
||||||
|
oss << ",\"assets\":[";
|
||||||
|
bool first = true;
|
||||||
|
for (const auto& asset: assets) {
|
||||||
|
if (first)
|
||||||
|
first=false;
|
||||||
|
else
|
||||||
|
oss << ",";
|
||||||
|
oss << "{\"asset_type\":\"" << asset.asset_type << "\",\"spot_price\":" << asset.spot_price << ",\"ma_price\":" << asset.ma_price << "}";
|
||||||
|
}
|
||||||
|
oss << "]";
|
||||||
|
oss << ",\"timestamp\":" << timestamp;
|
||||||
|
oss << "}";
|
||||||
|
std::string message = oss.str();
|
||||||
|
|
||||||
|
// Create a verify digest from the message
|
||||||
|
EVP_MD_CTX *ctx = EVP_MD_CTX_create();
|
||||||
|
int ret = 0;
|
||||||
|
if (ctx) {
|
||||||
|
ret = EVP_DigestVerifyInit(ctx, NULL, EVP_sha256(), NULL, pubkey);
|
||||||
|
if (ret == 1) {
|
||||||
|
ret = EVP_DigestVerifyUpdate(ctx, message.data(), message.length());
|
||||||
|
if (ret == 1) {
|
||||||
|
ret = EVP_DigestVerifyFinal(ctx, (const unsigned char *)signature.data(), signature.size());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cleanup the context we created
|
||||||
|
EVP_MD_CTX_destroy(ctx);
|
||||||
|
// Cleanup the openssl stuff
|
||||||
|
EVP_PKEY_free(pubkey);
|
||||||
|
|
||||||
|
if (ret == 1)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// Get the errors from OpenSSL
|
||||||
|
ERR_print_errors_fp (stderr);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// overload for pr validation for block
|
||||||
|
bool pricing_record::valid(cryptonote::network_type nettype, uint32_t hf_version, uint64_t bl_timestamp, uint64_t last_bl_timestamp) const
|
||||||
|
{
|
||||||
|
if (hf_version < HF_VERSION_SLIPPAGE_YIELD) {
|
||||||
|
if (!this->empty())
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this->empty())
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (!verifySignature(get_config(nettype).ORACLE_PUBLIC_KEY)) {
|
||||||
|
LOG_ERROR("Invalid pricing record signature.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// validate the timestmap
|
||||||
|
if (this->timestamp > bl_timestamp + PRICING_RECORD_VALID_TIME_DIFF_FROM_BLOCK) {
|
||||||
|
LOG_ERROR("Pricing record timestamp is too far in the future.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this->timestamp <= last_bl_timestamp) {
|
||||||
|
LOG_ERROR("Pricing record timestamp: " << this->timestamp << ", block timestamp: " << bl_timestamp);
|
||||||
|
LOG_ERROR("Pricing record timestamp is too old.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,160 @@
|
|||||||
|
// Copyright (c) 2019, Haven Protocol
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Redistribution and use in source and binary forms, with or without modification, are
|
||||||
|
// permitted provided that the following conditions are met:
|
||||||
|
//
|
||||||
|
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||||
|
// conditions and the following disclaimer.
|
||||||
|
//
|
||||||
|
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||||
|
// of conditions and the following disclaimer in the documentation and/or other
|
||||||
|
// materials provided with the distribution.
|
||||||
|
//
|
||||||
|
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
||||||
|
// used to endorse or promote products derived from this software without specific
|
||||||
|
// prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||||
|
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||||
|
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||||
|
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
//
|
||||||
|
// Portions of this code based upon code Copyright (c) 2019, The Monero Project
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "common/pod-class.h"
|
||||||
|
|
||||||
|
#include <openssl/bio.h>
|
||||||
|
#include <openssl/crypto.h>
|
||||||
|
#include <openssl/ecdsa.h>
|
||||||
|
#include <openssl/err.h>
|
||||||
|
#include <openssl/evp.h>
|
||||||
|
#include <openssl/pem.h>
|
||||||
|
#include <openssl/rsa.h>
|
||||||
|
#include <openssl/ssl.h>
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <string>
|
||||||
|
#include <cstring>
|
||||||
|
#include "serialization/containers.h"
|
||||||
|
|
||||||
|
#include "cryptonote_config.h"
|
||||||
|
#include "crypto/hash.h"
|
||||||
|
|
||||||
|
namespace epee
|
||||||
|
{
|
||||||
|
namespace serialization
|
||||||
|
{
|
||||||
|
class portable_storage;
|
||||||
|
struct section;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace salvium_oracle
|
||||||
|
{
|
||||||
|
#pragma pack(push, 1)
|
||||||
|
POD_CLASS pricing_record_pre {
|
||||||
|
uint64_t pr_version;
|
||||||
|
uint64_t price;
|
||||||
|
uint64_t timestamp;
|
||||||
|
};
|
||||||
|
#pragma pack(pop)
|
||||||
|
|
||||||
|
struct supply_data {
|
||||||
|
uint64_t sal;
|
||||||
|
uint64_t vsd;
|
||||||
|
|
||||||
|
//! Load from epee p2p format
|
||||||
|
bool _load(epee::serialization::portable_storage& src, epee::serialization::section* hparent);
|
||||||
|
//! Store in epee p2p format
|
||||||
|
bool store(epee::serialization::portable_storage& dest, epee::serialization::section* hparent) const;
|
||||||
|
|
||||||
|
BEGIN_SERIALIZE_OBJECT()
|
||||||
|
VARINT_FIELD(sal)
|
||||||
|
VARINT_FIELD(vsd)
|
||||||
|
END_SERIALIZE()
|
||||||
|
};
|
||||||
|
|
||||||
|
inline bool operator==(const supply_data& a, const supply_data& b) noexcept
|
||||||
|
{
|
||||||
|
return (a.sal == b.sal &&
|
||||||
|
a.vsd == b.vsd);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct asset_data {
|
||||||
|
std::string asset_type;
|
||||||
|
uint64_t spot_price;
|
||||||
|
uint64_t ma_price;
|
||||||
|
|
||||||
|
//! Load from epee p2p format
|
||||||
|
bool _load(epee::serialization::portable_storage& src, epee::serialization::section* hparent);
|
||||||
|
//! Store in epee p2p format
|
||||||
|
bool store(epee::serialization::portable_storage& dest, epee::serialization::section* hparent) const;
|
||||||
|
|
||||||
|
BEGIN_SERIALIZE_OBJECT()
|
||||||
|
FIELD(asset_type)
|
||||||
|
VARINT_FIELD(spot_price)
|
||||||
|
VARINT_FIELD(ma_price)
|
||||||
|
END_SERIALIZE()
|
||||||
|
};
|
||||||
|
|
||||||
|
inline bool operator==(const asset_data& a, const asset_data& b) noexcept
|
||||||
|
{
|
||||||
|
return (a.asset_type == b.asset_type &&
|
||||||
|
a.spot_price == b.spot_price &&
|
||||||
|
a.ma_price == b.ma_price);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct pricing_record
|
||||||
|
{
|
||||||
|
// Fields
|
||||||
|
uint64_t pr_version;
|
||||||
|
uint64_t height;
|
||||||
|
supply_data supply;
|
||||||
|
std::vector<asset_data> assets;
|
||||||
|
uint64_t timestamp;
|
||||||
|
std::vector<uint8_t> signature;
|
||||||
|
|
||||||
|
// Default c'tor
|
||||||
|
pricing_record() noexcept;
|
||||||
|
//! Load from epee p2p format
|
||||||
|
bool _load(epee::serialization::portable_storage& src, epee::serialization::section* hparent);
|
||||||
|
//! Store in epee p2p format
|
||||||
|
bool store(epee::serialization::portable_storage& dest, epee::serialization::section* hparent) const;
|
||||||
|
pricing_record(const pricing_record& orig) noexcept;
|
||||||
|
~pricing_record() noexcept;
|
||||||
|
bool equal(const pricing_record& other) const noexcept;
|
||||||
|
bool empty() const noexcept;
|
||||||
|
bool verifySignature(const std::string& public_key) const;
|
||||||
|
bool valid(cryptonote::network_type nettype, uint32_t hf_version, uint64_t bl_timestamp, uint64_t last_bl_timestamp) const;
|
||||||
|
|
||||||
|
pricing_record& operator=(const pricing_record& orig) noexcept;
|
||||||
|
uint64_t operator[](const std::string& asset_type) const;
|
||||||
|
|
||||||
|
BEGIN_SERIALIZE_OBJECT()
|
||||||
|
VARINT_FIELD(pr_version)
|
||||||
|
VARINT_FIELD(height)
|
||||||
|
FIELD(supply)
|
||||||
|
FIELD(assets)
|
||||||
|
VARINT_FIELD(timestamp)
|
||||||
|
FIELD(signature)
|
||||||
|
END_SERIALIZE()
|
||||||
|
};
|
||||||
|
|
||||||
|
inline bool operator==(const pricing_record& a, const pricing_record& b) noexcept
|
||||||
|
{
|
||||||
|
return a.equal(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool operator!=(const pricing_record& a, const pricing_record& b) noexcept
|
||||||
|
{
|
||||||
|
return !a.equal(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // salvium_oracle
|
||||||
@@ -0,0 +1,114 @@
|
|||||||
|
// Copyright (c) 2014-2022, The Monero Project
|
||||||
|
//
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Redistribution and use in source and binary forms, with or without modification, are
|
||||||
|
// permitted provided that the following conditions are met:
|
||||||
|
//
|
||||||
|
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||||
|
// conditions and the following disclaimer.
|
||||||
|
//
|
||||||
|
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||||
|
// of conditions and the following disclaimer in the documentation and/or other
|
||||||
|
// materials provided with the distribution.
|
||||||
|
//
|
||||||
|
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
||||||
|
// used to endorse or promote products derived from this software without specific
|
||||||
|
// prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||||
|
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||||
|
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||||
|
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
//
|
||||||
|
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
|
||||||
|
|
||||||
|
namespace serialization
|
||||||
|
{
|
||||||
|
namespace detail
|
||||||
|
{
|
||||||
|
template<typename T>
|
||||||
|
inline constexpr bool use_container_varint() noexcept
|
||||||
|
{
|
||||||
|
return std::is_integral<T>::value && std::is_unsigned<T>::value && sizeof(T) > 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Archive, class T>
|
||||||
|
typename std::enable_if<!use_container_varint<T>(), bool>::type
|
||||||
|
serialize_container_element(Archive& ar, T& e)
|
||||||
|
{
|
||||||
|
return do_serialize(ar, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Archive, typename T>
|
||||||
|
typename std::enable_if<use_container_varint<T>(), bool>::type
|
||||||
|
serialize_container_element(Archive& ar, T& e)
|
||||||
|
{
|
||||||
|
static constexpr const bool previously_varint = std::is_same<uint64_t, T>() || std::is_same<uint32_t, T>();
|
||||||
|
|
||||||
|
if (!previously_varint && ar.varint_bug_backward_compatibility_enabled() && !typename Archive::is_saving())
|
||||||
|
return do_serialize(ar, e);
|
||||||
|
ar.serialize_varint(e);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename C>
|
||||||
|
void do_reserve(C &c, size_t N) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <template <bool> class Archive, typename C>
|
||||||
|
bool do_serialize_container(Archive<false> &ar, C &v)
|
||||||
|
{
|
||||||
|
size_t cnt;
|
||||||
|
ar.begin_array(cnt);
|
||||||
|
if (!ar.good())
|
||||||
|
return false;
|
||||||
|
v.clear();
|
||||||
|
|
||||||
|
// very basic sanity check
|
||||||
|
if (ar.remaining_bytes() < cnt) {
|
||||||
|
ar.set_fail();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
::serialization::detail::do_reserve(v, cnt);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < cnt; i++) {
|
||||||
|
if (i > 0)
|
||||||
|
ar.delimit_array();
|
||||||
|
typename C::value_type e;
|
||||||
|
if (!::serialization::detail::serialize_container_element(ar, e))
|
||||||
|
return false;
|
||||||
|
::serialization::detail::do_add(v, std::move(e));
|
||||||
|
if (!ar.good())
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
ar.end_array();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <template <bool> class Archive, typename C>
|
||||||
|
bool do_serialize_container(Archive<true> &ar, C &v)
|
||||||
|
{
|
||||||
|
size_t cnt = v.size();
|
||||||
|
ar.begin_array(cnt);
|
||||||
|
for (auto i = v.begin(); i != v.end(); ++i)
|
||||||
|
{
|
||||||
|
if (!ar.good())
|
||||||
|
return false;
|
||||||
|
if (i != v.begin())
|
||||||
|
ar.delimit_array();
|
||||||
|
if(!::serialization::detail::serialize_container_element(ar, (typename C::value_type&)*i))
|
||||||
|
return false;
|
||||||
|
if (!ar.good())
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
ar.end_array();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
@@ -0,0 +1,128 @@
|
|||||||
|
// Copyright (c) 2014-2022, The Monero Project
|
||||||
|
//
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Redistribution and use in source and binary forms, with or without modification, are
|
||||||
|
// permitted provided that the following conditions are met:
|
||||||
|
//
|
||||||
|
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||||
|
// conditions and the following disclaimer.
|
||||||
|
//
|
||||||
|
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||||
|
// of conditions and the following disclaimer in the documentation and/or other
|
||||||
|
// materials provided with the distribution.
|
||||||
|
//
|
||||||
|
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
||||||
|
// used to endorse or promote products derived from this software without specific
|
||||||
|
// prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||||
|
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||||
|
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||||
|
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
//
|
||||||
|
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <deque>
|
||||||
|
#include <unordered_map>
|
||||||
|
#include <map>
|
||||||
|
#include <unordered_set>
|
||||||
|
#include <set>
|
||||||
|
#include "serialization.h"
|
||||||
|
|
||||||
|
template <template <bool> class Archive, class T> bool do_serialize(Archive<false> &ar, std::vector<T> &v);
|
||||||
|
template <template <bool> class Archive, class T> bool do_serialize(Archive<true> &ar, std::vector<T> &v);
|
||||||
|
|
||||||
|
template <template <bool> class Archive, class T> bool do_serialize(Archive<false> &ar, std::deque<T> &v);
|
||||||
|
template <template <bool> class Archive, class T> bool do_serialize(Archive<true> &ar, std::deque<T> &v);
|
||||||
|
|
||||||
|
template<typename K, typename V>
|
||||||
|
class serializable_unordered_map: public std::unordered_map<K, V>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef typename std::pair<K, V> value_type;
|
||||||
|
typename std::unordered_map<K, V> &parent() { return *this; }
|
||||||
|
};
|
||||||
|
|
||||||
|
template <template <bool> class Archive, typename K, typename V> bool do_serialize(Archive<false> &ar, serializable_unordered_map<K, V> &v);
|
||||||
|
template <template <bool> class Archive, typename K, typename V> bool do_serialize(Archive<true> &ar, serializable_unordered_map<K, V> &v);
|
||||||
|
|
||||||
|
template<typename K, typename V>
|
||||||
|
class serializable_map: public std::map<K, V>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef typename std::pair<K, V> value_type;
|
||||||
|
typename std::map<K, V> &parent() { return *this; }
|
||||||
|
};
|
||||||
|
|
||||||
|
template <template <bool> class Archive, typename K, typename V> bool do_serialize(Archive<false> &ar, serializable_map<K, V> &v);
|
||||||
|
template <template <bool> class Archive, typename K, typename V> bool do_serialize(Archive<true> &ar, serializable_map<K, V> &v);
|
||||||
|
|
||||||
|
template<typename K, typename V>
|
||||||
|
class serializable_unordered_multimap: public std::unordered_multimap<K, V>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef typename std::pair<K, V> value_type;
|
||||||
|
typename std::unordered_multimap<K, V> &parent() { return *this; }
|
||||||
|
};
|
||||||
|
|
||||||
|
template <template <bool> class Archive, typename K, typename V> bool do_serialize(Archive<false> &ar, serializable_unordered_multimap<K, V> &v);
|
||||||
|
template <template <bool> class Archive, typename K, typename V> bool do_serialize(Archive<true> &ar, serializable_unordered_multimap<K, V> &v);
|
||||||
|
|
||||||
|
template <template <bool> class Archive, class T> bool do_serialize(Archive<false> &ar, std::unordered_set<T> &v);
|
||||||
|
template <template <bool> class Archive, class T> bool do_serialize(Archive<true> &ar, std::unordered_set<T> &v);
|
||||||
|
|
||||||
|
template <template <bool> class Archive, class T> bool do_serialize(Archive<false> &ar, std::set<T> &v);
|
||||||
|
template <template <bool> class Archive, class T> bool do_serialize(Archive<true> &ar, std::set<T> &v);
|
||||||
|
|
||||||
|
namespace serialization
|
||||||
|
{
|
||||||
|
namespace detail
|
||||||
|
{
|
||||||
|
template <typename T> void do_reserve(std::vector<T> &c, size_t N) { c.reserve(N); }
|
||||||
|
template <typename T> void do_add(std::vector<T> &c, T &&e) { c.emplace_back(std::forward<T>(e)); }
|
||||||
|
|
||||||
|
template <typename T> void do_add(std::deque<T> &c, T &&e) { c.emplace_back(std::forward<T>(e)); }
|
||||||
|
|
||||||
|
template <typename K, typename V> void do_add(serializable_unordered_map<K, V> &c, std::pair<K, V> &&e) { c.insert(std::forward<std::pair<K, V>>(e)); }
|
||||||
|
|
||||||
|
template <typename K, typename V> void do_add(serializable_map<K, V> &c, std::pair<K, V> &&e) { c.insert(std::forward<std::pair<K, V>>(e)); }
|
||||||
|
|
||||||
|
template <typename K, typename V> void do_add(serializable_unordered_multimap<K, V> &c, std::pair<K, V> &&e) { c.insert(std::forward<std::pair<K, V>>(e)); }
|
||||||
|
|
||||||
|
template <typename T> void do_add(std::unordered_set<T> &c, T &&e) { c.insert(std::forward<T>(e)); }
|
||||||
|
|
||||||
|
template <typename T> void do_add(std::set<T> &c, T &&e) { c.insert(std::forward<T>(e)); }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#include "container.h"
|
||||||
|
|
||||||
|
template <template <bool> class Archive, class T> bool do_serialize(Archive<false> &ar, std::vector<T> &v) { return do_serialize_container(ar, v); }
|
||||||
|
template <template <bool> class Archive, class T> bool do_serialize(Archive<true> &ar, std::vector<T> &v) { return do_serialize_container(ar, v); }
|
||||||
|
|
||||||
|
template <template <bool> class Archive, class T> bool do_serialize(Archive<false> &ar, std::deque<T> &v) { return do_serialize_container(ar, v); }
|
||||||
|
template <template <bool> class Archive, class T> bool do_serialize(Archive<true> &ar, std::deque<T> &v) { return do_serialize_container(ar, v); }
|
||||||
|
|
||||||
|
template <template <bool> class Archive, typename K, typename V> bool do_serialize(Archive<false> &ar, serializable_unordered_map<K, V> &v) { return do_serialize_container(ar, v); }
|
||||||
|
template <template <bool> class Archive, typename K, typename V> bool do_serialize(Archive<true> &ar, serializable_unordered_map<K, V> &v) { return do_serialize_container(ar, v); }
|
||||||
|
|
||||||
|
template <template <bool> class Archive, typename K, typename V> bool do_serialize(Archive<false> &ar, serializable_map<K, V> &v) { return do_serialize_container(ar, v); }
|
||||||
|
template <template <bool> class Archive, typename K, typename V> bool do_serialize(Archive<true> &ar, serializable_map<K, V> &v) { return do_serialize_container(ar, v); }
|
||||||
|
|
||||||
|
template <template <bool> class Archive, typename K, typename V> bool do_serialize(Archive<false> &ar, serializable_unordered_multimap<K, V> &v) { return do_serialize_container(ar, v); }
|
||||||
|
template <template <bool> class Archive, typename K, typename V> bool do_serialize(Archive<true> &ar, serializable_unordered_multimap<K, V> &v) { return do_serialize_container(ar, v); }
|
||||||
|
|
||||||
|
template <template <bool> class Archive, class T> bool do_serialize(Archive<false> &ar, std::unordered_set<T> &v) { return do_serialize_container(ar, v); }
|
||||||
|
template <template <bool> class Archive, class T> bool do_serialize(Archive<true> &ar, std::unordered_set<T> &v) { return do_serialize_container(ar, v); }
|
||||||
|
|
||||||
|
template <template <bool> class Archive, class T> bool do_serialize(Archive<false> &ar, std::set<T> &v) { return do_serialize_container(ar, v); }
|
||||||
|
template <template <bool> class Archive, class T> bool do_serialize(Archive<true> &ar, std::set<T> &v) { return do_serialize_container(ar, v); }
|
||||||
@@ -0,0 +1,168 @@
|
|||||||
|
// Copyright (c) 2019, Haven Protocol
|
||||||
|
//
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Redistribution and use in source and binary forms, with or without modification, are
|
||||||
|
// permitted provided that the following conditions are met:
|
||||||
|
//
|
||||||
|
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||||
|
// conditions and the following disclaimer.
|
||||||
|
//
|
||||||
|
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||||
|
// of conditions and the following disclaimer in the documentation and/or other
|
||||||
|
// materials provided with the distribution.
|
||||||
|
//
|
||||||
|
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
||||||
|
// used to endorse or promote products derived from this software without specific
|
||||||
|
// prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||||
|
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||||
|
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||||
|
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
//
|
||||||
|
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "serialization.h"
|
||||||
|
#include "salvium_oracle/pricing_record.h"
|
||||||
|
#include "cryptonote_config.h"
|
||||||
|
|
||||||
|
// read
|
||||||
|
template <template <bool> class Archive>
|
||||||
|
bool do_serialize(Archive<false> &ar, salvium_oracle::supply_data &sd, uint8_t version)
|
||||||
|
{
|
||||||
|
ar.serialize_varint(sd.sal);
|
||||||
|
if (!ar.good())
|
||||||
|
return false;
|
||||||
|
ar.serialize_varint(sd.vsd);
|
||||||
|
if (!ar.good())
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// write
|
||||||
|
template <template <bool> class Archive>
|
||||||
|
bool do_serialize(Archive<true> &ar, salvium_oracle::supply_data &sd, uint8_t version)
|
||||||
|
{
|
||||||
|
if (!ar.good())
|
||||||
|
return false;
|
||||||
|
ar.serialize_varint(sd.sal);
|
||||||
|
ar.serialize_varint(sd.vsd);
|
||||||
|
if (!ar.good())
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// read
|
||||||
|
template <template <bool> class Archive>
|
||||||
|
bool do_serialize(Archive<false> &ar, salvium_oracle::asset_data &ad, uint8_t version)
|
||||||
|
{
|
||||||
|
ar.serialize_string(ad.asset_type);
|
||||||
|
if (!ar.good())
|
||||||
|
return false;
|
||||||
|
ar.serialize_varint(ad.spot_price);
|
||||||
|
if (!ar.good())
|
||||||
|
return false;
|
||||||
|
ar.serialize_varint(ad.ma_price);
|
||||||
|
if (!ar.good())
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// write
|
||||||
|
template <template <bool> class Archive>
|
||||||
|
bool do_serialize(Archive<true> &ar, salvium_oracle::asset_data &ad, uint8_t version)
|
||||||
|
{
|
||||||
|
if (!ar.good())
|
||||||
|
return false;
|
||||||
|
ar.serialize_string(ad.asset_type);
|
||||||
|
if (!ar.good())
|
||||||
|
return false;
|
||||||
|
ar.serialize_varint(ad.spot_price);
|
||||||
|
if (!ar.good())
|
||||||
|
return false;
|
||||||
|
ar.serialize_varint(ad.ma_price);
|
||||||
|
if (!ar.good())
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// read
|
||||||
|
template <template <bool> class Archive>
|
||||||
|
bool do_serialize(Archive<false> &ar, salvium_oracle::pricing_record &pr, uint8_t version)
|
||||||
|
{
|
||||||
|
// very basic sanity checks
|
||||||
|
if (!ar.good())
|
||||||
|
return false;
|
||||||
|
ar.serialize_varint(pr.pr_version);
|
||||||
|
if (!ar.good())
|
||||||
|
return false;
|
||||||
|
ar.serialize_varint(pr.height);
|
||||||
|
if (!ar.good())
|
||||||
|
return false;
|
||||||
|
if (!do_serialize(ar, pr.supply, version))
|
||||||
|
return false;
|
||||||
|
/*
|
||||||
|
// The next line should never do anything, but better safe than sorry
|
||||||
|
pr.asset_data.empty();
|
||||||
|
size_t asset_count;
|
||||||
|
ar.begin_array(asset_count);
|
||||||
|
if (!ar.good())
|
||||||
|
return false;
|
||||||
|
for (size_t idx=0; idx<asset_count; idx++) {
|
||||||
|
if (idx > 0) ar.delimit_array();
|
||||||
|
asset_data ad;
|
||||||
|
if (!do_serialize(ar, ad, version))
|
||||||
|
return false;
|
||||||
|
pr.asset_data.emplace_back(ad);
|
||||||
|
}
|
||||||
|
ar.end_array();
|
||||||
|
*/
|
||||||
|
if (!do_serialize_container(ar, pr.assets))
|
||||||
|
return false;
|
||||||
|
ar.serialize_varint(pr.timestamp);
|
||||||
|
if (!ar.good())
|
||||||
|
return false;
|
||||||
|
if (!do_serialize_container(ar, pr.signature))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// write
|
||||||
|
template <template <bool> class Archive>
|
||||||
|
bool do_serialize(Archive<true> &ar, salvium_oracle::pricing_record &pr, uint8_t version)
|
||||||
|
{
|
||||||
|
// very basic sanity checks
|
||||||
|
if (!ar.good())
|
||||||
|
return false;
|
||||||
|
ar.serialize_varint(pr.pr_version);
|
||||||
|
if (!ar.good())
|
||||||
|
return false;
|
||||||
|
ar.serialize_varint(pr.height);
|
||||||
|
if (!ar.good())
|
||||||
|
return false;
|
||||||
|
if (!do_serialize(ar, pr.supply, version))
|
||||||
|
return false;
|
||||||
|
if (!do_serialize_container(ar, pr.assets))
|
||||||
|
return false;
|
||||||
|
ar.serialize_varint(pr.timestamp);
|
||||||
|
if (!ar.good())
|
||||||
|
return false;
|
||||||
|
pr.signature.empty();
|
||||||
|
if (!do_serialize_container(ar, pr.signature))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//BLOB_SERIALIZER(salvium_oracle::supply_data);
|
||||||
|
//BLOB_SERIALIZER(salvium_oracle::asset_data);
|
||||||
|
//BLOB_SERIALIZER(salvium_oracle::pricing_record);
|
||||||
Reference in New Issue
Block a user