ZEPH support
This commit is contained in:
@@ -33,5 +33,5 @@ enum BLOB_TYPE {
|
||||
BLOB_TYPE_CRYPTONOTE_TUBE = 10, // TUBE
|
||||
BLOB_TYPE_CRYPTONOTE_XHV = 11, // Haven
|
||||
BLOB_TYPE_CRYPTONOTE_XTA = 12, // ITALO
|
||||
BLOB_TYPE_CRYPTONOTE_ZEPH = 13, // ZEPH
|
||||
BLOB_TYPE_CRYPTONOTE_ZEPHYR = 13, // ZEPHYR
|
||||
};
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
#include "serialization/binary_archive.h"
|
||||
#include "serialization/crypto.h"
|
||||
#include "serialization/pricing_record.h"
|
||||
#include "serialization/pricing_record_zeph.h"
|
||||
#include "serialization/zephyr_pricing_record.h"
|
||||
#include "serialization/keyvalue_serialization.h" // eepe named serialization
|
||||
#include "string_tools.h"
|
||||
#include "cryptonote_config.h"
|
||||
@@ -27,7 +27,7 @@
|
||||
#include "ringct/rctTypes.h"
|
||||
#include "cryptonote_protocol/blobdatatype.h"
|
||||
#include "offshore/pricing_record.h"
|
||||
#include "oracle/pricing_record.h"
|
||||
#include "zephyr_oracle/pricing_record.h"
|
||||
|
||||
|
||||
namespace cryptonote
|
||||
@@ -109,6 +109,22 @@ namespace cryptonote
|
||||
END_SERIALIZE()
|
||||
};
|
||||
|
||||
// ZEPHYR
|
||||
struct txout_zephyr_tagged_key
|
||||
{
|
||||
txout_zephyr_tagged_key() { }
|
||||
txout_zephyr_tagged_key(const crypto::public_key &_key, const std::string &_asset_type, const crypto::view_tag &_view_tag) : key(_key), asset_type(_asset_type), view_tag(_view_tag) { }
|
||||
crypto::public_key key;
|
||||
std::string asset_type;
|
||||
crypto::view_tag view_tag; // optimization to reduce scanning time
|
||||
|
||||
BEGIN_SERIALIZE_OBJECT()
|
||||
FIELD(key)
|
||||
FIELD(asset_type)
|
||||
FIELD(view_tag)
|
||||
END_SERIALIZE()
|
||||
};
|
||||
|
||||
/* inputs */
|
||||
|
||||
struct txin_gen
|
||||
@@ -216,30 +232,14 @@ namespace cryptonote
|
||||
FIELD(k_image)
|
||||
END_SERIALIZE()
|
||||
};
|
||||
|
||||
struct txout_zephyr_tagged_key
|
||||
{
|
||||
txout_zephyr_tagged_key() { }
|
||||
txout_zephyr_tagged_key(const crypto::public_key &_key, const std::string &_asset_type, const crypto::view_tag &_view_tag) : key(_key), asset_type(_asset_type), view_tag(_view_tag) { }
|
||||
crypto::public_key key;
|
||||
std::string asset_type;
|
||||
crypto::view_tag view_tag; // optimization to reduce scanning time
|
||||
|
||||
BEGIN_SERIALIZE_OBJECT()
|
||||
FIELD(key)
|
||||
FIELD(asset_type)
|
||||
FIELD(view_tag)
|
||||
END_SERIALIZE()
|
||||
};
|
||||
|
||||
typedef boost::variant<txin_gen, txin_to_script, txin_to_scripthash, txin_to_key, txin_offshore, txin_onshore, txin_xasset> txin_v;
|
||||
|
||||
typedef boost::variant<txin_gen, txin_to_script, txin_to_scripthash, txin_zephyr_key> txin_zeph_v;
|
||||
typedef boost::variant<txout_to_script, txout_to_scripthash, txout_zephyr_tagged_key> txout_zeph_target_v;
|
||||
typedef boost::variant<txin_gen, txin_to_script, txin_to_scripthash, txin_to_key, txin_offshore, txin_onshore, txin_xasset, txin_zephyr_key> txin_v;
|
||||
|
||||
typedef boost::variant<txout_to_script, txout_to_scripthash, txout_to_key, txout_to_tagged_key> txout_target_v;
|
||||
typedef boost::variant<txout_to_script, txout_to_scripthash, txout_to_key, txout_offshore, txout_xasset> txout_xhv_target_v;
|
||||
|
||||
typedef boost::variant<txout_to_script, txout_to_scripthash, txout_zephyr_tagged_key> txout_stablero_target_v;
|
||||
|
||||
struct tx_out
|
||||
{
|
||||
uint64_t amount;
|
||||
@@ -262,10 +262,10 @@ namespace cryptonote
|
||||
END_SERIALIZE()
|
||||
};
|
||||
|
||||
struct tx_out_zeph
|
||||
struct tx_out_zephyr
|
||||
{
|
||||
uint64_t amount;
|
||||
txout_zeph_target_v target;
|
||||
txout_stablero_target_v target;
|
||||
|
||||
BEGIN_SERIALIZE_OBJECT()
|
||||
VARINT_FIELD(amount)
|
||||
@@ -293,10 +293,9 @@ namespace cryptonote
|
||||
uint64_t unlock_time; //number of block (or time), used as a limitation like: spend this tx not early then block/time
|
||||
|
||||
std::vector<txin_v> vin;
|
||||
std::vector<txin_zeph_v> vin_zeph;
|
||||
std::vector<tx_out> vout;
|
||||
std::vector<tx_out_xhv> vout_xhv;
|
||||
std::vector<tx_out_zeph> vout_zeph;
|
||||
std::vector<tx_out_zephyr> vout_zephyr;
|
||||
//extra
|
||||
std::vector<uint8_t> extra;
|
||||
// Block height to use PR from
|
||||
@@ -335,14 +334,12 @@ namespace cryptonote
|
||||
}
|
||||
if (blob_type != BLOB_TYPE_CRYPTONOTE_XHV || version < POU_TRANSACTION_VERSION)
|
||||
VARINT_FIELD(unlock_time)
|
||||
if (blob_type == BLOB_TYPE_CRYPTONOTE_ZEPH)
|
||||
FIELD(vin_zeph)
|
||||
else
|
||||
FIELD(vin)
|
||||
if (blob_type == BLOB_TYPE_CRYPTONOTE_XHV)
|
||||
FIELD(vin)
|
||||
|
||||
if (blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR)
|
||||
FIELD(vout_zephyr)
|
||||
else if (blob_type == BLOB_TYPE_CRYPTONOTE_XHV)
|
||||
FIELD(vout_xhv)
|
||||
else if (blob_type == BLOB_TYPE_CRYPTONOTE_ZEPH)
|
||||
FIELD(vout_zeph)
|
||||
else
|
||||
FIELD(vout)
|
||||
|
||||
@@ -356,6 +353,11 @@ namespace cryptonote
|
||||
VARINT_FIELD(type)
|
||||
if (static_cast<uint16_t>(type) >= loki_type_count) return false;
|
||||
}
|
||||
if (blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR) {
|
||||
VARINT_FIELD(pricing_record_height)
|
||||
VARINT_FIELD(amount_burnt)
|
||||
VARINT_FIELD(amount_minted)
|
||||
}
|
||||
if (blob_type == BLOB_TYPE_CRYPTONOTE_XHV && version >= OFFSHORE_TRANSACTION_VERSION) {
|
||||
VARINT_FIELD(pricing_record_height)
|
||||
if (version < 5)
|
||||
@@ -377,10 +379,6 @@ namespace cryptonote
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else if (blob_type == BLOB_TYPE_CRYPTONOTE_ZEPH) {
|
||||
VARINT_FIELD(pricing_record_height)
|
||||
VARINT_FIELD(amount_burnt)
|
||||
VARINT_FIELD(amount_minted)
|
||||
}
|
||||
END_SERIALIZE()
|
||||
|
||||
@@ -439,29 +437,22 @@ namespace cryptonote
|
||||
if (!vin.empty())
|
||||
{
|
||||
ar.begin_object();
|
||||
bool r;
|
||||
if (blob_type == BLOB_TYPE_CRYPTONOTE_XHV)
|
||||
r = rct_signatures.serialize_rctsig_base(ar, vin.size(), vout_xhv.size());
|
||||
else if (blob_type == BLOB_TYPE_CRYPTONOTE_XHV)
|
||||
r = rct_signatures.serialize_rctsig_base(ar, vin_zeph.size(), vout_zeph.size());
|
||||
else
|
||||
r = rct_signatures.serialize_rctsig_base(ar, vin.size(), vout.size());
|
||||
bool r = rct_signatures.serialize_rctsig_base(ar, vin.size(), blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR ? vout_zephyr.size() : blob_type != BLOB_TYPE_CRYPTONOTE_XHV ? vout.size() : vout_xhv.size());
|
||||
if (!r || !ar.stream().good()) return false;
|
||||
ar.end_object();
|
||||
if (rct_signatures.type != rct::RCTTypeNull)
|
||||
{
|
||||
ar.tag("rctsig_prunable");
|
||||
ar.begin_object();
|
||||
if (blob_type == BLOB_TYPE_CRYPTONOTE_XHV) {
|
||||
if (blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR) {
|
||||
r = rct_signatures.p.serialize_rctsig_prunable(ar, rct_signatures.type, vin.size(), vout_zephyr.size(),
|
||||
vin[0].type() == typeid(txin_zephyr_key) ? boost::get<txin_zephyr_key>(vin[0]).key_offsets.size() - 1 : 0);
|
||||
} else if (blob_type == BLOB_TYPE_CRYPTONOTE_XHV) {
|
||||
r = rct_signatures.p.serialize_rctsig_prunable(ar, rct_signatures.type, vin.size(), vout_xhv.size(),
|
||||
vin.size() > 0 && vin[0].type() == typeid(txin_to_key) ? boost::get<txin_to_key>(vin[0]).key_offsets.size() - 1 :
|
||||
vin.size() > 0 && vin[0].type() == typeid(txin_offshore) ? boost::get<txin_offshore>(vin[0]).key_offsets.size() - 1 :
|
||||
vin.size() > 0 && vin[0].type() == typeid(txin_onshore) ? boost::get<txin_onshore>(vin[0]).key_offsets.size() - 1 :
|
||||
vin.size() > 0 && vin[0].type() == typeid(txin_xasset) ? boost::get<txin_xasset>(vin[0]).key_offsets.size() - 1 :
|
||||
0);
|
||||
} else if (blob_type == BLOB_TYPE_CRYPTONOTE_ZEPH) {
|
||||
r = rct_signatures.p.serialize_rctsig_prunable(ar, rct_signatures.type, vin_zeph.size(), vout_zeph.size(),
|
||||
vin_zeph.size() > 0 && vin_zeph[0].type() == typeid(txin_zephyr_key) ? boost::get<txin_zephyr_key>(vin_zeph[0]).key_offsets.size() - 1 : 0);
|
||||
vin.size() > 0 && vin[0].type() == typeid(txin_xasset) ? boost::get<txin_xasset>(vin[0]).key_offsets.size() - 1 : 0);
|
||||
} else {
|
||||
r = rct_signatures.p.serialize_rctsig_prunable(ar, rct_signatures.type, vin.size(), vout.size(),
|
||||
vin[0].type() == typeid(txin_to_key) ? boost::get<txin_to_key>(vin[0]).key_offsets.size() - 1 : 0);
|
||||
@@ -495,10 +486,9 @@ namespace cryptonote
|
||||
version = 0;
|
||||
unlock_time = 0;
|
||||
vin.clear();
|
||||
vin_zeph.clear();
|
||||
vout.clear();
|
||||
vout_xhv.clear();
|
||||
vout_zeph.clear();
|
||||
vout_zephyr.clear();
|
||||
extra.clear();
|
||||
signatures.clear();
|
||||
pricing_record_height = 0;
|
||||
@@ -642,7 +632,7 @@ namespace cryptonote
|
||||
uint64_t nonce;
|
||||
uint64_t nonce8;
|
||||
offshore::pricing_record pricing_record;
|
||||
oracle::pricing_record pricing_record_zeph;
|
||||
zephyr_oracle::pricing_record zephyr_pricing_record;
|
||||
crypto::cycle cycle;
|
||||
crypto::cycle40 cycle40;
|
||||
crypto::cycle48 cycle48;
|
||||
@@ -654,7 +644,7 @@ namespace cryptonote
|
||||
FIELD(prev_id)
|
||||
if (blob_type == BLOB_TYPE_CRYPTONOTE_CUCKOO || blob_type == BLOB_TYPE_CRYPTONOTE_TUBE || blob_type == BLOB_TYPE_CRYPTONOTE_XTA) FIELD(nonce8)
|
||||
if (blob_type != BLOB_TYPE_FORKNOTE2) {
|
||||
if (blob_type == BLOB_TYPE_AEON || blob_type == BLOB_TYPE_CRYPTONOTE_ZEPH) {
|
||||
if (blob_type == BLOB_TYPE_AEON) {
|
||||
FIELD(nonce)
|
||||
} else {
|
||||
uint32_t nonce32;
|
||||
@@ -667,7 +657,7 @@ namespace cryptonote
|
||||
if (blob_type == BLOB_TYPE_CRYPTONOTE_TUBE) FIELD(cycle40)
|
||||
if (blob_type == BLOB_TYPE_CRYPTONOTE_XTA) FIELD(cycle48)
|
||||
if (blob_type == BLOB_TYPE_CRYPTONOTE_XHV) FIELD(pricing_record)
|
||||
if (blob_type == BLOB_TYPE_CRYPTONOTE_ZEPH) FIELD(pricing_record_zeph)
|
||||
if (blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR) FIELD_N("pricing_record", zephyr_pricing_record)
|
||||
|
||||
END_SERIALIZE()
|
||||
};
|
||||
@@ -737,12 +727,6 @@ namespace cryptonote
|
||||
KV_SERIALIZE(payment_id)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
|
||||
struct keypair
|
||||
{
|
||||
crypto::public_key pub;
|
||||
crypto::secret_key sec;
|
||||
};
|
||||
//---------------------------------------------------------------
|
||||
|
||||
}
|
||||
|
||||
@@ -185,17 +185,17 @@ namespace cryptonote
|
||||
{
|
||||
BOOST_FOREACH(const auto& in, tx.vin)
|
||||
{
|
||||
if (tx.blob_type == BLOB_TYPE_CRYPTONOTE_XHV) {
|
||||
CHECK_AND_ASSERT_MES(in.type() == typeid(txin_to_key) || in.type() == typeid(txin_offshore) || in.type() == typeid(txin_onshore) || in.type() == typeid(txin_xasset), false, "wrong variant type: "
|
||||
if (tx.blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR) {
|
||||
CHECK_AND_ASSERT_MES(in.type() == typeid(txin_zephyr_key), false, "wrong variant type: "
|
||||
<< in.type().name() << ", expected " << typeid(txin_zephyr_key).name()
|
||||
<< ", in transaction id=" << get_transaction_hash(tx));
|
||||
} else if (tx.blob_type == BLOB_TYPE_CRYPTONOTE_XHV) {
|
||||
CHECK_AND_ASSERT_MES(in.type() == typeid(txin_to_key) || in.type() == typeid(txin_offshore) || in.type() == typeid(txin_onshore) || in.type() == typeid(txin_xasset), false, "wrong variant type: "
|
||||
<< in.type().name() << ", expected " << typeid(txin_to_key).name()
|
||||
<< "or " << typeid(txin_offshore).name()
|
||||
<< "or " << typeid(txin_onshore).name()
|
||||
<< "or " << typeid(txin_xasset).name()
|
||||
<< ", in transaction id=" << get_transaction_hash(tx));
|
||||
} else if (tx.blob_type == BLOB_TYPE_CRYPTONOTE_ZEPH) {
|
||||
CHECK_AND_ASSERT_MES(in.type() == typeid(txin_zephyr_key), false, "wrong variant type: "
|
||||
<< in.type().name() << ", expected " << typeid(txin_zephyr_key).name()
|
||||
<< ", in transaction id=" << get_transaction_hash(tx));
|
||||
<< ", in transaction id=" << get_transaction_hash(tx));
|
||||
} else {
|
||||
CHECK_AND_ASSERT_MES(in.type() == typeid(txin_to_key), false, "wrong variant type: "
|
||||
<< in.type().name() << ", expected " << typeid(txin_to_key).name()
|
||||
@@ -263,7 +263,7 @@ namespace cryptonote
|
||||
std::stringstream ss;
|
||||
binary_archive<true> ba(ss);
|
||||
const size_t inputs = t.vin.size();
|
||||
const size_t outputs = t.blob_type != BLOB_TYPE_CRYPTONOTE_XHV ? t.vout.size() : t.vout_xhv.size();
|
||||
const size_t outputs = t.blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR ? t.vout_zephyr.size() : t.blob_type != BLOB_TYPE_CRYPTONOTE_XHV ? t.vout.size() : t.vout_xhv.size();
|
||||
bool r = tt.rct_signatures.serialize_rctsig_base(ba, inputs, outputs);
|
||||
CHECK_AND_ASSERT_MES(r, false, "Failed to serialize rct signatures base");
|
||||
cryptonote::get_blob_hash(ss.str(), hashes[1]);
|
||||
@@ -279,17 +279,17 @@ namespace cryptonote
|
||||
std::stringstream ss;
|
||||
binary_archive<true> ba(ss);
|
||||
const size_t inputs = t.vin.size();
|
||||
const size_t outputs = t.blob_type != BLOB_TYPE_CRYPTONOTE_XHV ? t.vout.size() : t.vout_xhv.size();
|
||||
const size_t outputs = t.blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR ? t.vout_zephyr.size() : t.blob_type != BLOB_TYPE_CRYPTONOTE_XHV ? t.vout.size() : t.vout_xhv.size();
|
||||
size_t mixin;
|
||||
if (t.blob_type == BLOB_TYPE_CRYPTONOTE_XHV) {
|
||||
if (t.blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR) {
|
||||
mixin = t.vin.empty() ? 0 : t.vin[0].type() == typeid(txin_zephyr_key) ? boost::get<txin_zephyr_key>(t.vin[0]).key_offsets.size() - 1 : 0;
|
||||
} else if (t.blob_type == BLOB_TYPE_CRYPTONOTE_XHV) {
|
||||
mixin = t.vin.empty() ? 0 :
|
||||
t.vin[0].type() == typeid(txin_to_key) ? boost::get<txin_to_key>(t.vin[0]).key_offsets.size() - 1 :
|
||||
t.vin[0].type() == typeid(txin_offshore) ? boost::get<txin_offshore>(t.vin[0]).key_offsets.size() - 1 :
|
||||
t.vin[0].type() == typeid(txin_onshore) ? boost::get<txin_onshore>(t.vin[0]).key_offsets.size() - 1 :
|
||||
t.vin[0].type() == typeid(txin_xasset) ? boost::get<txin_xasset>(t.vin[0]).key_offsets.size() - 1 :
|
||||
0;
|
||||
} else if (t.blob_type == BLOB_TYPE_CRYPTONOTE_ZEPH) {
|
||||
mixin = t.vin_zeph.empty() ? 0 : t.vin_zeph[0].type() == typeid(txin_to_key) ? boost::get<txin_zephyr_key>(t.vin_zeph[0]).key_offsets.size() - 1 : 0;
|
||||
t.vin[0].type() == typeid(txin_to_key) ? boost::get<txin_to_key>(t.vin[0]).key_offsets.size() - 1 :
|
||||
t.vin[0].type() == typeid(txin_offshore) ? boost::get<txin_offshore>(t.vin[0]).key_offsets.size() - 1 :
|
||||
t.vin[0].type() == typeid(txin_onshore) ? boost::get<txin_onshore>(t.vin[0]).key_offsets.size() - 1 :
|
||||
t.vin[0].type() == typeid(txin_xasset) ? boost::get<txin_xasset>(t.vin[0]).key_offsets.size() - 1 :
|
||||
0;
|
||||
} else {
|
||||
mixin = t.vin.empty() ? 0 : t.vin[0].type() == typeid(txin_to_key) ? boost::get<txin_to_key>(t.vin[0]).key_offsets.size() - 1 : 0;
|
||||
}
|
||||
|
||||
@@ -1,123 +0,0 @@
|
||||
// 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 "pricing_record.h"
|
||||
|
||||
#include "serialization/keyvalue_serialization.h"
|
||||
#include "storages/portable_storage.h"
|
||||
|
||||
#include "string_tools.h"
|
||||
|
||||
#define COIN ((uint64_t)1000000000000) // pow(10, 12)
|
||||
|
||||
namespace oracle
|
||||
{
|
||||
|
||||
namespace
|
||||
{
|
||||
struct pr_serialized
|
||||
{
|
||||
uint64_t zEPHUSD;
|
||||
uint64_t zEPHRSV;
|
||||
uint64_t timestamp;
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(zEPHUSD)
|
||||
KV_SERIALIZE(zEPHRSV)
|
||||
KV_SERIALIZE(timestamp)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
}
|
||||
|
||||
pricing_record::pricing_record() noexcept
|
||||
: zEPHUSD(0)
|
||||
, zEPHRSV(0)
|
||||
, timestamp(0) {}
|
||||
|
||||
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
|
||||
zEPHUSD = in.zEPHUSD;
|
||||
zEPHRSV = in.zEPHRSV;
|
||||
timestamp = in.timestamp;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Report error here?
|
||||
return false;
|
||||
}
|
||||
|
||||
bool pricing_record::store(epee::serialization::portable_storage& dest, epee::serialization::section* hparent) const
|
||||
{
|
||||
const pr_serialized out{zEPHUSD,zEPHRSV,timestamp};
|
||||
return out.store(dest, hparent);
|
||||
}
|
||||
|
||||
pricing_record::pricing_record(const pricing_record& orig) noexcept
|
||||
: zEPHUSD(orig.zEPHUSD)
|
||||
, zEPHRSV(orig.zEPHRSV)
|
||||
, timestamp(orig.timestamp) {}
|
||||
|
||||
pricing_record& pricing_record::operator=(const pricing_record& orig) noexcept
|
||||
{
|
||||
zEPHUSD = orig.zEPHUSD;
|
||||
zEPHRSV = orig.zEPHRSV;
|
||||
timestamp = orig.timestamp;
|
||||
return *this;
|
||||
}
|
||||
|
||||
uint64_t pricing_record::operator[](const std::string& asset_type) const
|
||||
{
|
||||
if (asset_type == "ZEPH") {
|
||||
return zEPHUSD; // ZEPH spot price
|
||||
} else if (asset_type == "ZEPHUSD") {
|
||||
return COIN; // 1
|
||||
} else if (asset_type == "ZEPHRSV") {
|
||||
return zEPHRSV; // ZEPHRSV spot price
|
||||
} else {
|
||||
CHECK_AND_ASSERT_THROW_MES(false, "Asset type doesn't exist in pricing record!");
|
||||
}
|
||||
}
|
||||
|
||||
bool pricing_record::equal(const pricing_record& other) const noexcept
|
||||
{
|
||||
return ((zEPHUSD == other.zEPHUSD) &&
|
||||
(zEPHRSV == other.zEPHRSV) &&
|
||||
(timestamp == other.timestamp));
|
||||
}
|
||||
|
||||
bool pricing_record::empty() const noexcept
|
||||
{
|
||||
const pricing_record empty_pr = oracle::pricing_record();
|
||||
return (*this).equal(empty_pr);
|
||||
}
|
||||
}
|
||||
@@ -1,94 +0,0 @@
|
||||
// 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 "cryptonote_config.h"
|
||||
#include "crypto/hash.h"
|
||||
|
||||
namespace epee
|
||||
{
|
||||
namespace serialization
|
||||
{
|
||||
class portable_storage;
|
||||
struct section;
|
||||
}
|
||||
}
|
||||
|
||||
namespace oracle
|
||||
{
|
||||
class pricing_record
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
// Fields
|
||||
uint64_t zEPHUSD;
|
||||
uint64_t zEPHRSV;
|
||||
uint64_t timestamp;
|
||||
// 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() = default;
|
||||
bool equal(const pricing_record& other) const noexcept;
|
||||
bool empty() const noexcept;
|
||||
|
||||
pricing_record& operator=(const pricing_record& orig) noexcept;
|
||||
uint64_t operator[](const std::string& asset_type) const;
|
||||
};
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
} // oracle
|
||||
Reference in New Issue
Block a user