From ff44cdf5783a290c811db104670ace53b8386e4a Mon Sep 17 00:00:00 2001 From: MoneroOcean Date: Tue, 14 Jul 2020 20:23:47 -0700 Subject: [PATCH] Haven offshore test support --- package.json | 2 +- src/cryptonote_config.h | 6 +- src/cryptonote_core/cryptonote_basic.h | 81 ++++++++++++++++- src/offshore/pricing_record.h | 120 +++++++++++++++++++++++++ src/serialization/pricing_record.h | 67 ++++++++++++++ 5 files changed, 269 insertions(+), 7 deletions(-) create mode 100644 src/offshore/pricing_record.h create mode 100644 src/serialization/pricing_record.h diff --git a/package.json b/package.json index 4ad1e5c..51887c7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cryptoforknote-util", - "version": "8.0.0", + "version": "8.1.0", "main": "cryptoforknote-util", "author": { "name": "LucasJones", diff --git a/src/cryptonote_config.h b/src/cryptonote_config.h index 341e526..7280727 100644 --- a/src/cryptonote_config.h +++ b/src/cryptonote_config.h @@ -1,6 +1,7 @@ #pragma once -#define CURRENT_TRANSACTION_VERSION 1 +#define CURRENT_TRANSACTION_VERSION 1 +#define OFFSHORE_TRANSACTION_VERSION 3 enum BLOB_TYPE { BLOB_TYPE_CRYPTONOTE = 0, @@ -13,5 +14,6 @@ enum BLOB_TYPE { BLOB_TYPE_AEON = 7, // Aeon BLOB_TYPE_CRYPTONOTE_CUCKOO = 8, // MoneroV / Swap BLOB_TYPE_CRYPTONOTE_XTNC = 9, // XTNC - BLOB_TYPE_CRYPTONOTE_TUBE = 10, // bittube + BLOB_TYPE_CRYPTONOTE_TUBE = 10, // TUBE + BLOB_TYPE_CRYPTONOTE_XHV = 11, // Haven }; diff --git a/src/cryptonote_core/cryptonote_basic.h b/src/cryptonote_core/cryptonote_basic.h index 4000711..399dd49 100644 --- a/src/cryptonote_core/cryptonote_basic.h +++ b/src/cryptonote_core/cryptonote_basic.h @@ -17,6 +17,7 @@ #include "serialization/json_archive.h" #include "serialization/debug_archive.h" #include "serialization/crypto.h" +#include "serialization/pricing_record.h" #include "serialization/keyvalue_serialization.h" // eepe named serialization #include "string_tools.h" #include "cryptonote_config.h" @@ -26,6 +27,7 @@ #include "tx_extra.h" #include "ringct/rctTypes.h" #include "cryptonote_protocol/blobdatatype.h" +#include "offshore/pricing_record.h" namespace cryptonote @@ -72,6 +74,13 @@ namespace cryptonote crypto::public_key key; }; + struct txout_offshore + { + txout_offshore() { } + txout_offshore(const crypto::public_key &_key) : key(_key) { } + crypto::public_key key; + }; + /* inputs */ struct txin_gen @@ -124,10 +133,35 @@ namespace cryptonote END_SERIALIZE() }; + struct txin_offshore + { + uint64_t amount; + std::vector key_offsets; + crypto::key_image k_image; - typedef boost::variant txin_v; + BEGIN_SERIALIZE_OBJECT() + VARINT_FIELD(amount) + FIELD(key_offsets) + FIELD(k_image) + END_SERIALIZE() + }; - typedef boost::variant txout_target_v; + struct txin_onshore + { + uint64_t amount; + std::vector key_offsets; + crypto::key_image k_image; + + BEGIN_SERIALIZE_OBJECT() + VARINT_FIELD(amount) + FIELD(key_offsets) + FIELD(k_image) + END_SERIALIZE() + }; + + typedef boost::variant txin_v; + + typedef boost::variant txout_target_v; //typedef std::pair out_t; struct tx_out @@ -163,6 +197,12 @@ namespace cryptonote std::vector vout; //extra std::vector extra; + // Block height to use PR from + uint64_t pricing_record_height; + // Circulating supply information + std::vector offshore_data; + uint64_t amount_burnt; + uint64_t amount_minted; // // NOTE: Loki specific @@ -203,6 +243,12 @@ namespace cryptonote VARINT_FIELD(type) if (static_cast(type) >= loki_type_count) return false; } + if (blob_type == BLOB_TYPE_CRYPTONOTE_XHV && version >= OFFSHORE_TRANSACTION_VERSION) { + VARINT_FIELD(pricing_record_height) + FIELD(offshore_data) + VARINT_FIELD(amount_burnt) + VARINT_FIELD(amount_minted) + } END_SERIALIZE() @@ -267,8 +313,16 @@ namespace cryptonote { ar.tag("rctsig_prunable"); ar.begin_object(); - r = rct_signatures.p.serialize_rctsig_prunable(ar, rct_signatures.type, vin.size(), vout.size(), - vin[0].type() == typeid(txin_to_key) ? boost::get(vin[0]).key_offsets.size() - 1 : 0); + if (blob_type != BLOB_TYPE_CRYPTONOTE_XHV) { + r = rct_signatures.p.serialize_rctsig_prunable(ar, rct_signatures.type, vin.size(), vout.size(), + vin[0].type() == typeid(txin_to_key) ? boost::get(vin[0]).key_offsets.size() - 1 : 0); + } else { + r = rct_signatures.p.serialize_rctsig_prunable(ar, rct_signatures.type, vin.size(), vout.size(), + vin.size() > 0 && vin[0].type() == typeid(txin_to_key) ? boost::get(vin[0]).key_offsets.size() - 1 : + vin.size() > 0 && vin[0].type() == typeid(txin_offshore) ? boost::get(vin[0]).key_offsets.size() - 1 : + vin.size() > 0 && vin[0].type() == typeid(txin_onshore) ? boost::get(vin[0]).key_offsets.size() - 1 : + 0); + } if (!r || !ar.stream().good()) return false; ar.end_object(); } @@ -301,6 +355,10 @@ namespace cryptonote vout.clear(); extra.clear(); signatures.clear(); + pricing_record_height = 0; + offshore_data.clear(); + amount_burnt = 0; + amount_minted = 0; } inline @@ -312,6 +370,8 @@ namespace cryptonote size_t operator()(const txin_to_script& txin) const{return 0;} size_t operator()(const txin_to_scripthash& txin) const{return 0;} size_t operator()(const txin_to_key& txin) const {return txin.key_offsets.size();} + size_t operator()(const txin_offshore& txin) const {return txin.key_offsets.size();} + size_t operator()(const txin_onshore& txin) const {return txin.key_offsets.size();} }; return boost::apply_visitor(txin_signature_size_visitor(), tx_in); @@ -329,6 +389,7 @@ namespace cryptonote uint8_t minor_version; crypto::hash prev_id; uint32_t nonce; + offshore::pricing_record pricing_record; size_t number_of_transactions; std::vector miner_tx_branch; transaction miner_tx; @@ -452,6 +513,8 @@ namespace cryptonote } 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_XHV) FIELD(pricing_record) + END_SERIALIZE() }; @@ -538,15 +601,19 @@ namespace cryptonote } BLOB_SERIALIZER(cryptonote::txout_to_key); +BLOB_SERIALIZER(cryptonote::txout_offshore); BLOB_SERIALIZER(cryptonote::txout_to_scripthash); VARIANT_TAG(binary_archive, cryptonote::txin_gen, 0xff); VARIANT_TAG(binary_archive, cryptonote::txin_to_script, 0x0); VARIANT_TAG(binary_archive, cryptonote::txin_to_scripthash, 0x1); VARIANT_TAG(binary_archive, cryptonote::txin_to_key, 0x2); +VARIANT_TAG(binary_archive, cryptonote::txin_offshore, 0x3); +VARIANT_TAG(binary_archive, cryptonote::txin_onshore, 0x4); VARIANT_TAG(binary_archive, cryptonote::txout_to_script, 0x0); VARIANT_TAG(binary_archive, cryptonote::txout_to_scripthash, 0x1); VARIANT_TAG(binary_archive, cryptonote::txout_to_key, 0x2); +VARIANT_TAG(binary_archive, cryptonote::txout_offshore, 0x3); VARIANT_TAG(binary_archive, cryptonote::transaction, 0xcc); VARIANT_TAG(binary_archive, cryptonote::block, 0xbb); @@ -554,9 +621,12 @@ VARIANT_TAG(json_archive, cryptonote::txin_gen, "gen"); VARIANT_TAG(json_archive, cryptonote::txin_to_script, "script"); VARIANT_TAG(json_archive, cryptonote::txin_to_scripthash, "scripthash"); VARIANT_TAG(json_archive, cryptonote::txin_to_key, "key"); +VARIANT_TAG(json_archive, cryptonote::txin_offshore, "offshore"); +VARIANT_TAG(json_archive, cryptonote::txin_onshore, "onshore"); VARIANT_TAG(json_archive, cryptonote::txout_to_script, "script"); VARIANT_TAG(json_archive, cryptonote::txout_to_scripthash, "scripthash"); VARIANT_TAG(json_archive, cryptonote::txout_to_key, "key"); +VARIANT_TAG(json_archive, cryptonote::txout_offshore, "offshore"); VARIANT_TAG(json_archive, cryptonote::transaction, "tx"); VARIANT_TAG(json_archive, cryptonote::block, "block"); @@ -564,8 +634,11 @@ VARIANT_TAG(debug_archive, cryptonote::txin_gen, "gen"); VARIANT_TAG(debug_archive, cryptonote::txin_to_script, "script"); VARIANT_TAG(debug_archive, cryptonote::txin_to_scripthash, "scripthash"); VARIANT_TAG(debug_archive, cryptonote::txin_to_key, "key"); +VARIANT_TAG(debug_archive, cryptonote::txin_offshore, "offshore"); +VARIANT_TAG(debug_archive, cryptonote::txin_onshore, "onshore"); VARIANT_TAG(debug_archive, cryptonote::txout_to_script, "script"); VARIANT_TAG(debug_archive, cryptonote::txout_to_scripthash, "scripthash"); VARIANT_TAG(debug_archive, cryptonote::txout_to_key, "key"); +VARIANT_TAG(debug_archive, cryptonote::txout_offshore, "offshore"); VARIANT_TAG(debug_archive, cryptonote::transaction, "tx"); VARIANT_TAG(debug_archive, cryptonote::block, "block"); diff --git a/src/offshore/pricing_record.h b/src/offshore/pricing_record.h new file mode 100644 index 0000000..c9f2b46 --- /dev/null +++ b/src/offshore/pricing_record.h @@ -0,0 +1,120 @@ +// 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 + +namespace epee +{ + namespace serialization + { + class portable_storage; + struct section; + } +} + +namespace offshore +{ + +#pragma pack(push, 1) + POD_CLASS pricing_record_old { + double xAG; + double xAU; + double xAUD; + double xBTC; + double xCAN; + double xCHF; + double xCNY; + double xEUR; + double xGBP; + double xJPY; + double xNOK; + double xNZD; + double xUSD; + double unused1; + double unused2; + double unused3; + char signature[32]; + }; +#pragma pack(pop) + + class pricing_record + { + + public: + + // Fields + uint64_t xAG; + uint64_t xAU; + uint64_t xAUD; + uint64_t xBTC; + uint64_t xCAD; + uint64_t xCHF; + uint64_t xCNY; + uint64_t xEUR; + uint64_t xGBP; + uint64_t xJPY; + uint64_t xNOK; + uint64_t xNZD; + uint64_t xUSD; + uint64_t unused1; + uint64_t unused2; + uint64_t unused3; + unsigned char signature[64]; + + // 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; + pricing_record& operator=(const pricing_record& orig) noexcept; + + bool equal(const pricing_record& other) const noexcept; + + bool verifySignature() const noexcept; + }; + + 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); + } + +} // offshore \ No newline at end of file diff --git a/src/serialization/pricing_record.h b/src/serialization/pricing_record.h new file mode 100644 index 0000000..73d2fb9 --- /dev/null +++ b/src/serialization/pricing_record.h @@ -0,0 +1,67 @@ +// 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 + +#include "serialization.h" +#include "debug_archive.h" +#include "offshore/pricing_record.h" + +/* +// read +template