diff --git a/CMakeLists.txt b/CMakeLists.txt index 87a46f2dd..83bd543ba 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,6 +39,8 @@ if (WITH_QRENCODE) add_definitions(-DWITH_QRENCODE) endif() +add_definitions(-DJEMALLOC) + set(LOG_LIBRARY "boost" CACHE STRING "Setting for the logging library (boost|spdlog|binlog).") @@ -95,6 +97,21 @@ if (${CURRENCY} STREQUAL "LTC") find_package(OpenSSL 1.0.1 REQUIRED) endif() +# # jemalloc +# find_package(PkgConfig REQUIRED) +# pkg_check_modules(JEMALLOC jemalloc) + +# message("-- Found jemalloc: JEMALLOC_INCLUDE_DIRS: ${JEMALLOC_INCLUDE_DIRS}") +# message("-- Found jemalloc: JEMALLOC_LIBRARY_DIRS: ${JEMALLOC_LIBRARY_DIRS}") +# message("-- Found jemalloc: JEMALLOC_CFLAGS_OTHER: ${JEMALLOC_CFLAGS_OTHER}") + +# include_directories(${JEMALLOC_INCLUDE_DIRS}) +# link_directories(${JEMALLOC_LIBRARY_DIRS}) +# add_definitions(${JEMALLOC_CFLAGS_OTHER}) + + + + include(CheckCXXCompilerFlag) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/ci_utils/cmake) @@ -268,13 +285,6 @@ set(kth_sources_just_kth src/wallet/transaction_functions.cpp ) -if (NOT ${CURRENCY} STREQUAL "BCH") - set(kth_sources_just_legacy - ${kth_sources_just_legacy} - src/chain/witness.cpp - ) -endif() - if (${CURRENCY} STREQUAL "LTC") set(kth_sources_just_kth ${kth_sources_just_kth} @@ -352,7 +362,6 @@ set(kth_headers include/kth/domain/chain/script_basis.hpp include/kth/domain/chain/transaction_basis.hpp include/kth/domain/chain/stealth.hpp - include/kth/domain/chain/witness.hpp include/kth/domain/chain/point_iterator.hpp include/kth/domain/chain/header.hpp include/kth/domain/chain/history.hpp @@ -447,6 +456,7 @@ if (${CURRENCY} STREQUAL "LTC") endif() target_link_libraries(${PROJECT_NAME} PUBLIC infrastructure::infrastructure) +target_link_libraries(${PROJECT_NAME} PUBLIC ${JEMALLOC_LIBRARIES}) if(NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten") target_link_libraries(${PROJECT_NAME} PUBLIC Boost::thread) diff --git a/conan.lock b/conan.lock index 24ce3cf6d..2875737a2 100644 --- a/conan.lock +++ b/conan.lock @@ -4,8 +4,9 @@ "zlib/1.3.1#f52e03ae3d251dec704634230cd806a2%1725632949.456", "spdlog/1.14.1#972bbf70be1da4bc57ea589af0efde03%1716966910.455", "secp256k1/0.19.0#a41750412727606c6bed7fdf3695c43f%1725622574.44", + "libiconv/1.17#73fefc1b696e069df90fd1d18aa63edd%1725635059.278", "libbacktrace/cci.20210118#a7691bfccd8caaf66309df196790a5a1%1725632951.012", - "infrastructure/0.35.0#aacb707e8eb3ddfc4fe57ca3d0a80e66%1725634936.328094", + "infrastructure/0.35.0#aacb707e8eb3ddfc4fe57ca3d0a80e66%1725628750.49", "gmp/6.3.0#df20ffb6d21c34d67704305bcd1dea9e%1716966936.742", "fmt/10.2.1#8d582aeebdf05b6f0abe2911b926c3f4%1720016029.904", "expected-lite/0.8.0#f87b3ec27a4f46894950b70f8d08af24%1717770563.402", diff --git a/conanfile.py b/conanfile.py index 89b698abc..44d368562 100644 --- a/conanfile.py +++ b/conanfile.py @@ -59,7 +59,7 @@ class KnuthDomainConan(KnuthConanFileV2): def build_requirements(self): if self.options.tests: - self.test_requires("catch2/3.6.0") + self.test_requires("catch2/3.7.1") def requirements(self): self.requires("infrastructure/0.35.0", transitive_headers=True, transitive_libs=True) diff --git a/include/kth/domain.hpp b/include/kth/domain.hpp index d293af5b4..68b08e3e3 100644 --- a/include/kth/domain.hpp +++ b/include/kth/domain.hpp @@ -29,10 +29,6 @@ #include #include -#if defined(KTH_SEGWIT_ENABLED) -#include -#endif - #include #include diff --git a/include/kth/domain/chain/block.hpp b/include/kth/domain/chain/block.hpp index 6d1fe8a5d..1557ab2c1 100644 --- a/include/kth/domain/chain/block.hpp +++ b/include/kth/domain/chain/block.hpp @@ -70,6 +70,16 @@ class KD_API block : public block_basis { block(chain::header const& header, transaction::list&& transactions); block(chain::header const& header, transaction::list const& transactions); + explicit + block(block_basis const& basis) + : block_basis(basis) + {} + + explicit + block(block_basis&& basis) + : block_basis(std::move(basis)) + {} + //Note(kth): cannot be defaulted because of the mutex data member. block(block const& x); block(block&& x) noexcept; @@ -79,25 +89,19 @@ class KD_API block : public block_basis { // Deserialization. //------------------------------------------------------------------------- - - template - bool from_data(R& source, bool witness = false) { - validation.start_deserialize = asio::steady_clock::now(); - block_basis::from_data(source, witness); - validation.end_deserialize = asio::steady_clock::now(); - return source; - } + static + expect from_data(byte_reader& reader, bool wire = true); // Serialization. //------------------------------------------------------------------------- using block_basis::to_data; - data_chunk to_data(bool witness = false) const; + data_chunk to_data() const; // Properties (size, accessors, cache). //------------------------------------------------------------------------- - size_t serialized_size(bool witness = false) const; + size_t serialized_size() const; // void set_header(chain::header const& value); void set_transactions(transaction::list const& value); @@ -132,11 +136,6 @@ class KD_API block : public block_basis { static indexes locator_heights(size_t top); -#if defined(KTH_SEGWIT_ENABLED) - /// Clear witness from all inputs (does not change default hash). - void strip_witness(); -#endif - // Validation. //------------------------------------------------------------------------- @@ -146,11 +145,6 @@ class KD_API block : public block_basis { size_t total_inputs(bool with_coinbase = true) const; -#if defined(KTH_SEGWIT_ENABLED) - size_t weight() const; - bool is_segregated() const; -#endif - code check() const; code accept(bool transactions = true) const; code accept(chain_state const& state, bool transactions = true) const; @@ -160,14 +154,8 @@ class KD_API block : public block_basis { mutable validation_t validation{}; private: - // These share a mutex as they are not expected to contend. -#if defined(KTH_SEGWIT_ENABLED) - mutable std::optional segregated_; -#endif - mutable std::optional total_inputs_; - mutable std::optional base_size_; - mutable std::optional total_size_; + mutable std::optional base_size_; // total size #if ! defined(__EMSCRIPTEN__) mutable upgrade_mutex mutex_; diff --git a/include/kth/domain/chain/block_basis.hpp b/include/kth/domain/chain/block_basis.hpp index 51d405253..59ba399c5 100644 --- a/include/kth/domain/chain/block_basis.hpp +++ b/include/kth/domain/chain/block_basis.hpp @@ -36,18 +36,6 @@ namespace kth::domain::chain { using indexes = std::vector; -#if defined(KTH_SEGWIT_ENABLED) -constexpr inline -size_t weight(size_t serialized_size_true, size_t serialized_size_false) { - // Block weight is 3 * Base size * + 1 * Total size (bip141). - return base_size_contribution * serialized_size_false + total_size_contribution * serialized_size_true; -} - -class KD_API block_basis; -void strip_witness(block_basis& blk); -bool is_segregated(block_basis const& blk); -#endif - class KD_API block_basis { public: using list = std::vector; @@ -67,45 +55,47 @@ class KD_API block_basis { // Deserialization. //------------------------------------------------------------------------- - template - bool from_data(R& source, bool witness = false) { - // validation.start_deserialize = asio::steady_clock::now(); - reset(); - - if ( ! header_.from_data(source, true)) { - return false; - } - - auto const count = source.read_size_little_endian(); - - // Guard against potential for arbitary memory allocation. - if (count > static_absolute_max_block_size()) { - source.invalidate(); - } else { - transactions_.resize(count); - } - - // Order is required, explicit loop allows early termination. - for (auto& tx : transactions_) { - if ( ! entity_from_data(tx, source, true, witness_val(witness))) { - break; - } - } - -#if defined(KTH_SEGWIT_ENABLED) - // TODO(legacy): optimize by having reader skip witness data. - if ( ! witness_val(witness)) { - strip_witness(*this); - } -#endif - - if ( ! source) { - reset(); - } - - // validation.end_deserialize = asio::steady_clock::now(); - return source; - } +// template +// bool from_data(R& source) { +// // validation.start_deserialize = asio::steady_clock::now(); +// reset(); + +// if ( ! header_.from_data(source, true)) { +// return false; +// } + +// auto const count = source.read_size_little_endian(); + +// // Guard against potential for arbitary memory allocation. +// if (count > static_absolute_max_block_size()) { +// source.invalidate(); +// } else { +// transactions_.resize(count); +// } + +// // Order is required, explicit loop allows early termination. +// for (auto& tx : transactions_) { +// if ( ! entity_from_data(tx, source, true, witness_val(witness))) { +// break; +// } +// } + +// #if defined(KTH_SEGWIT_ENABLED) +// // TODO(legacy): optimize by having reader skip witness data. +// if ( ! witness_val(witness)) { +// strip_witness(*this); +// } +// #endif + +// if ( ! source) { +// reset(); +// } + +// // validation.end_deserialize = asio::steady_clock::now(); +// return source; +// } + static + expect from_data(byte_reader& reader, bool /*wire*/); [[nodiscard]] bool is_valid() const; @@ -114,23 +104,23 @@ class KD_API block_basis { //------------------------------------------------------------------------- // [[nodiscard]] - data_chunk to_data(size_t serialized_size, bool witness = false) const; + data_chunk to_data(size_t serialized_size) const; - void to_data(data_sink& stream, bool witness = false) const; + void to_data(data_sink& stream) const; template - void to_data(W& sink, bool witness = false) const { + void to_data(W& sink) const { header_.to_data(sink, true); sink.write_size_little_endian(transactions_.size()); - auto const to = [&sink, witness](transaction const& tx) { - tx.to_data(sink, true, witness_val(witness)); + auto const to = [&sink](transaction const& tx) { + tx.to_data(sink, true); }; std::for_each(transactions_.begin(), transactions_.end(), to); } [[nodiscard]] - hash_list to_hashes(bool witness = false) const; + hash_list to_hashes() const; // Properties (size, accessors, cache). //------------------------------------------------------------------------- @@ -177,7 +167,7 @@ class KD_API block_basis { uint256_t proof() const; [[nodiscard]] - hash_digest generate_merkle_root(bool witness = false) const; + hash_digest generate_merkle_root() const; [[nodiscard]] size_t signature_operations(bool bip16, bool bip141) const; @@ -197,11 +187,6 @@ class KD_API block_basis { [[nodiscard]] bool is_valid_coinbase_script(size_t height) const; -#if defined(KTH_SEGWIT_ENABLED) - [[nodiscard]] - bool is_valid_witness_commitment() const; -#endif - [[nodiscard]] bool is_forward_reference() const; @@ -221,11 +206,7 @@ class KD_API block_basis { code check_transactions() const; [[nodiscard]] -#if defined(KTH_SEGWIT_ENABLED) - code accept(chain_state const& state, size_t serialized_size, size_t weight, bool transactions = true) const; -#else code accept(chain_state const& state, size_t serialized_size, bool transactions = true) const; -#endif [[nodiscard]] code accept_transactions(chain_state const& state) const; @@ -256,7 +237,7 @@ indexes locator_heights(size_t top); size_t total_inputs(block_basis const& blk, bool with_coinbase = true); -size_t serialized_size(block_basis const& blk, bool witness = false); +size_t serialized_size(block_basis const& blk); } // namespace kth::domain::chain diff --git a/include/kth/domain/chain/header.hpp b/include/kth/domain/chain/header.hpp index 17ab4a78e..396f9fb5d 100644 --- a/include/kth/domain/chain/header.hpp +++ b/include/kth/domain/chain/header.hpp @@ -51,6 +51,11 @@ class KD_API header : public header_basis, public hash_memoizer
{ header() = default; // header(header const& x, hash_digest const& hash); + explicit + header(header_basis const& basis) + : header_basis(basis) + {} + /// This class is copy constructible and copy assignable. // Note(kth): Cannot be defaulted because the std::mutex data member. header(header const& x); @@ -65,20 +70,23 @@ class KD_API header : public header_basis, public hash_memoizer
{ // Deserialization. //----------------------------------------------------------------------------- - template - bool from_data(R& source, bool wire = true) { - header_basis::from_data(source, wire); + // template + // bool from_data(R& source, bool wire = true) { + // header_basis::from_data(source); - if ( ! wire) { - validation.median_time_past = source.read_4_bytes_little_endian(); - } + // if ( ! wire) { + // validation.median_time_past = source.read_4_bytes_little_endian(); + // } - if ( ! source) { - reset(); - } + // if ( ! source) { + // reset(); + // } - return source; - } + // return source; + // } + + static + expect
from_data(byte_reader& reader, bool wire = true); // Serialization. //----------------------------------------------------------------------------- diff --git a/include/kth/domain/chain/header_basis.hpp b/include/kth/domain/chain/header_basis.hpp index 6258039d5..ffa9fb53c 100644 --- a/include/kth/domain/chain/header_basis.hpp +++ b/include/kth/domain/chain/header_basis.hpp @@ -24,8 +24,11 @@ #include #include -#include +// #include +#include + namespace kth::domain::chain { + class KD_API header_basis { public: using list = std::vector; @@ -52,21 +55,8 @@ class KD_API header_basis { // Deserialization. //----------------------------------------------------------------------------- - template - bool from_data(R& source, bool /*wire = true*/) { - version_ = source.read_4_bytes_little_endian(); - previous_block_hash_ = source.read_hash(); - merkle_ = source.read_hash(); - timestamp_ = source.read_4_bytes_little_endian(); - bits_ = source.read_4_bytes_little_endian(); - nonce_ = source.read_4_bytes_little_endian(); - - if ( ! source) { - reset(); - } - - return source; - } + static + kth::expect from_data(byte_reader& reader, bool /*wire*/ = true); [[nodiscard]] bool is_valid() const; @@ -99,8 +89,12 @@ class KD_API header_basis { static constexpr size_t satoshi_fixed_size() { - return sizeof(version_) + hash_size + hash_size + sizeof(timestamp_) + - sizeof(bits_) + sizeof(nonce_); + return sizeof(version_) + + hash_size + + hash_size + + sizeof(timestamp_) + + sizeof(bits_) + + sizeof(nonce_); } [[nodiscard]] @@ -158,7 +152,7 @@ class KD_API header_basis { code check(hash_digest const& hash, bool retarget = false) const; [[nodiscard]] - code accept(chain_state const& state, hash_digest const& hash) const; + code accept(::kth::domain::chain::chain_state const& state, hash_digest const& hash) const; void reset(); @@ -173,10 +167,6 @@ class KD_API header_basis { hash_digest hash(header_basis const& header); -#if defined(KTH_CURRENCY_LTC) -hash_digest litecoin_proof_of_work_hash(header_basis const& header); -#endif //KTH_CURRENCY_LTC - } // namespace kth::domain::chain #endif // KTH_DOMAIN_CHAIN_HEADER_BASIS_HPP diff --git a/include/kth/domain/chain/input.hpp b/include/kth/domain/chain/input.hpp index 9114e0698..5479c5edf 100644 --- a/include/kth/domain/chain/input.hpp +++ b/include/kth/domain/chain/input.hpp @@ -18,7 +18,6 @@ #include #include #include -#include #include #include #include @@ -44,21 +43,32 @@ class KD_API input : public input_basis { input() = default; using input_basis::input_basis; // inherit constructors from input_basis + explicit + input(input_basis const& x); + + explicit + input(input_basis&& x) noexcept; + + // Special member functions. + //------------------------------------------------------------------------- + input(input const& x); input(input&& x) noexcept; input& operator=(input&& x) noexcept; input& operator=(input const& x); + // Deserialization. + //------------------------------------------------------------------------- + + static + expect from_data(byte_reader& reader, bool wire); + + // Properties (size, accessors, cache). //------------------------------------------------------------------------- void set_script(chain::script const& value); void set_script(chain::script&& value); -#if defined(KTH_SEGWIT_ENABLED) - void set_witness(chain::witness const& value); - void set_witness(chain::witness&& value); -#endif // KTH_CURRENCY_BCH - /// The first payment address extracted (may be invalid). wallet::payment_address address() const; diff --git a/include/kth/domain/chain/input_basis.hpp b/include/kth/domain/chain/input_basis.hpp index 115432466..b5d7f6cad 100644 --- a/include/kth/domain/chain/input_basis.hpp +++ b/include/kth/domain/chain/input_basis.hpp @@ -13,7 +13,6 @@ #include #include -#include #include #include @@ -40,54 +39,41 @@ class KD_API input_basis { input_basis(output_point const& previous_output, chain::script const& script, uint32_t sequence); input_basis(output_point&& previous_output, chain::script&& script, uint32_t sequence); -#if defined(KTH_SEGWIT_ENABLED) - input_basis(output_point const& previous_output, chain::script const& script, chain::witness const& witness, uint32_t sequence); - input_basis(output_point&& previous_output, chain::script&& script, chain::witness&& witness, uint32_t sequence); -#endif - - input_basis(input_basis const& x) = default; - input_basis(input_basis&& x) = default; - input_basis& operator=(input_basis const& x) = default; - input_basis& operator=(input_basis&& x) = default; - // Operators. //------------------------------------------------------------------------- - bool operator==(input_basis const& x) const; - bool operator!=(input_basis const& x) const; + // friend + // auto operator<=>(input_basis const&, input_basis const&) = default; + + friend + bool operator==(input_basis const&, input_basis const&) = default; + + friend + bool operator!=(input_basis const&, input_basis const&) = default; // Deserialization. //------------------------------------------------------------------------- - template - bool from_data(R& source, bool wire = true, KTH_DECL_WITN_ARG) { -#if defined(KTH_SEGWIT_ENABLED) - // Always write witness to store so that we know how to read it. - witness |= !wire; -#endif + static + expect from_data(byte_reader& reader, bool wire); - reset(); + // template + // bool from_data(R& source, bool wire = true) { + // reset(); - if ( ! previous_output_.from_data(source, wire)) { - return false; - } + // if ( ! previous_output_.from_data(source, wire)) { + // return false; + // } - script_.from_data(source, true); + // script_.from_data(source, true); + // sequence_ = source.read_4_bytes_little_endian(); -#if defined(KTH_SEGWIT_ENABLED) - // Transaction from_data handles the discontiguous wire witness decoding. - if (witness_val(witness) && !wire) { - witness_.from_data(source, true); - } -#endif - sequence_ = source.read_4_bytes_little_endian(); + // if ( ! source) { + // reset(); + // } - if ( ! source) { - reset(); - } - - return source; - } + // return source; + // } [[nodiscard]] bool is_valid() const; @@ -96,38 +82,23 @@ class KD_API input_basis { //------------------------------------------------------------------------- [[nodiscard]] - data_chunk to_data(bool wire = true, bool witness = false) const; + data_chunk to_data(bool wire = true) const; - void to_data(data_sink& stream, bool wire = true, bool witness = false) const; + void to_data(data_sink& stream, bool wire = true) const; template - void to_data(W& sink, bool wire = true, KTH_DECL_WITN_ARG) const { -#if defined(KTH_SEGWIT_ENABLED) - // Always write witness to store so that we know how to read it. - witness |= !wire; -#endif - + void to_data(W& sink, bool wire = true) const { previous_output_.to_data(sink, wire); script_.to_data(sink, true); - -#if defined(KTH_SEGWIT_ENABLED) - // Transaction to_data handles the discontiguous wire witness encoding. - if (witness_val(witness) && !wire) { - witness_.to_data(sink, true); - } -#endif sink.write_4_bytes_little_endian(sequence_); } // Properties (size, accessors, cache). //------------------------------------------------------------------------- + /// This accounts for wire, but does not read or write it. [[nodiscard]] - size_t serialized_size_non_witness(bool wire) const; - - /// This accounts for wire witness, but does not read or write it. - [[nodiscard]] - size_t serialized_size(bool wire = true, bool witness = false) const; + size_t serialized_size(bool wire = true) const; output_point& previous_output(); @@ -147,26 +118,11 @@ class KD_API input_basis { void set_script(chain::script const& value); void set_script(chain::script&& value); - -#if defined(KTH_SEGWIT_ENABLED) - // [[deprecated]] // unsafe - chain::witness& witness(); - chain::witness const& witness() const; - void set_witness(chain::witness const& value); - void set_witness(chain::witness&& value); -#endif // KTH_CURRENCY_BCH - [[nodiscard]] uint32_t sequence() const; void set_sequence(uint32_t value); - // Utilities. - //------------------------------------------------------------------------- - -#if defined(KTH_SEGWIT_ENABLED) - void strip_witness(); -#endif // Validation. //------------------------------------------------------------------------- @@ -174,11 +130,6 @@ class KD_API input_basis { [[nodiscard]] bool is_final() const; -#if defined(KTH_SEGWIT_ENABLED) - [[nodiscard]] - bool is_segregated() const; -#endif - [[nodiscard]] bool is_locked(size_t block_height, uint32_t median_time_past) const; @@ -186,11 +137,8 @@ class KD_API input_basis { size_t signature_operations(bool bip16, bool bip141) const; bool extract_reserved_hash(hash_digest& out) const; - bool extract_embedded_script(chain::script& out) const; - -#if defined(KTH_SEGWIT_ENABLED) - bool extract_witness_script(chain::script& out, chain::script const& prevout) const; -#endif + // bool extract_embedded_script(chain::script& out) const; + expect extract_embedded_script() const; // protected: void reset(); @@ -198,9 +146,6 @@ class KD_API input_basis { private: output_point previous_output_; chain::script script_; -#if defined(KTH_SEGWIT_ENABLED) - chain::witness witness_; -#endif uint32_t sequence_{0}; }; diff --git a/include/kth/domain/chain/output.hpp b/include/kth/domain/chain/output.hpp index 2745b41f4..91ea7aee8 100644 --- a/include/kth/domain/chain/output.hpp +++ b/include/kth/domain/chain/output.hpp @@ -50,8 +50,12 @@ class KD_API output : public output_basis { //------------------------------------------------------------------------- output() = default; - // output(uint64_t value, chain::script const& script); - // output(uint64_t value, chain::script&& script); + + explicit + output(output_basis const& x); + + explicit + output(output_basis&& x) noexcept; using output_basis::output_basis; //inherit constructors from output_basis @@ -60,23 +64,21 @@ class KD_API output : public output_basis { output& operator=(output const& x); output& operator=(output&& x) noexcept; - // Operators. - //------------------------------------------------------------------------- - // bool operator==(output const& x) const; - // bool operator!=(output const& x) const; - // Deserialization. //------------------------------------------------------------------------- - template - bool from_data(R& source, bool wire = true, bool witness = false) { - if ( ! wire) { - validation.spender_height = source.read_4_bytes_little_endian(); - } + // template + // bool from_data(R& source, bool wire = true, bool witness = false) { + // if ( ! wire) { + // validation.spender_height = source.read_4_bytes_little_endian(); + // } - output_basis::from_data(source, wire, witness); - return source; - } + // output_basis::from_data(source, wire, witness); + // return source; + // } + + static + expect from_data(byte_reader& reader, bool wire = true); // Serialization. //------------------------------------------------------------------------- @@ -85,12 +87,12 @@ class KD_API output : public output_basis { void to_data(data_sink& stream, bool wire = true) const; template - void to_data(W& sink, bool wire = true, bool witness = false) const { + void to_data(W& sink, bool wire = true) const { if ( ! wire) { auto const height32 = *safe_unsigned(validation.spender_height); sink.write_4_bytes_little_endian(height32); } - output_basis::to_data(sink, wire, witness); + output_basis::to_data(sink, wire); } // Properties (size, accessors, cache). diff --git a/include/kth/domain/chain/output_basis.hpp b/include/kth/domain/chain/output_basis.hpp index 17ff8e032..96d8e9d2d 100644 --- a/include/kth/domain/chain/output_basis.hpp +++ b/include/kth/domain/chain/output_basis.hpp @@ -49,47 +49,56 @@ struct KD_API output_basis { // Operators. //------------------------------------------------------------------------- - // bool operator==(output_basis const& x) const; - // bool operator!=(output_basis const& x) const; + // friend + // auto operator<=>(output_basis const&, output_basis const&) = default; + + friend + bool operator==(output_basis const&, output_basis const&) = default; + friend - auto operator<=>(output_basis const&, output_basis const&) = default; + bool operator!=(output_basis const&, output_basis const&) = default; + // Deserialization. //------------------------------------------------------------------------- - template - bool from_data(R& source, bool /*wire*/ = true, bool /*witness*/ = false) { - reset(); + // template + // bool from_data(R& source, bool /*wire*/ = true, bool /*witness*/ = false) { + // reset(); - value_ = source.read_8_bytes_little_endian(); + // value_ = source.read_8_bytes_little_endian(); - auto script_size = source.read_size_little_endian(); - if ( ! source) { - reset(); - return source; - } + // auto script_size = source.read_size_little_endian(); + // if ( ! source) { + // reset(); + // return source; + // } - auto const has_token_data = source.peek_byte() == chain::encoding::PREFIX_BYTE; - if ( ! source) { - reset(); - return source; - } + // auto const has_token_data = source.peek_byte() == chain::encoding::PREFIX_BYTE; + // if ( ! source) { + // reset(); + // return source; + // } - if (has_token_data) { - source.skip(1); // skip prefix byte - chain::encoding::from_data(source, token_data_); - script_size -= chain::encoding::serialized_size(token_data_); - script_size -= 1; // prefix byte - } + // if (has_token_data) { + // source.skip(1); // skip prefix byte + // chain::encoding::from_data(source, token_data_); + // script_size -= chain::encoding::serialized_size(token_data_); + // script_size -= 1; // prefix byte + // } - script_.from_data_with_size(source, script_size); + // script_.from_data_with_size(source, script_size); - if ( ! source) { - reset(); - } + // if ( ! source) { + // reset(); + // } + + // return source; + // } + + static + expect from_data(byte_reader& reader, bool /*wire*/ = true); - return source; - } [[nodiscard]] bool is_valid() const; @@ -111,11 +120,11 @@ struct KD_API output_basis { return; } - auto const size = chain::encoding::serialized_size(token_data_) + script_.serialized_size(false) + 1; + auto const size = token::encoding::serialized_size(token_data_) + script_.serialized_size(false) + 1; sink.write_variable_little_endian(size); sink.write_byte(chain::encoding::PREFIX_BYTE); - chain::encoding::to_data(sink, token_data_.value()); + token::encoding::to_data(sink, token_data_.value()); script_.to_data(sink, false); } @@ -155,10 +164,6 @@ struct KD_API output_basis { [[nodiscard]] bool is_dust(uint64_t minimum_output_value) const; -#if defined(KTH_SEGWIT_ENABLED) - bool extract_committed_hash(hash_digest& out) const; -#endif - // protected: void reset(); diff --git a/include/kth/domain/chain/output_point.hpp b/include/kth/domain/chain/output_point.hpp index 0e58a36b8..ff735dfb3 100644 --- a/include/kth/domain/chain/output_point.hpp +++ b/include/kth/domain/chain/output_point.hpp @@ -57,12 +57,6 @@ class KD_API output_point : public point { output_point(point const& x); output_point& operator=(point const& /*x*/); - // output_point(output_point const& x) = default; - // output_point(output_point&& x) = default; - // // This class is move assignable and copy assignable. - // output_point& operator=(output_point const&) = default; - // output_point& operator=(output_point&& x) = default; - // Operators. //------------------------------------------------------------------------- @@ -75,9 +69,6 @@ class KD_API output_point : public point { friend bool operator==(output_point const& x, output_point const& y); friend bool operator!=(output_point const& x, output_point const& y); - // Deserialization. - //------------------------------------------------------------------------- - // Validation. //------------------------------------------------------------------------- diff --git a/include/kth/domain/chain/point.hpp b/include/kth/domain/chain/point.hpp index 1356c285b..498847f5d 100644 --- a/include/kth/domain/chain/point.hpp +++ b/include/kth/domain/chain/point.hpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -76,29 +77,32 @@ class KD_API point { // Deserialization. //------------------------------------------------------------------------- - template - bool from_data(R& source, bool wire = true) { - reset(); + // template + // bool from_data(R& source, bool wire = true) { + // reset(); - valid_ = true; - hash_ = source.read_hash(); + // valid_ = true; + // hash_ = source.read_hash(); - if (wire) { - index_ = source.read_4_bytes_little_endian(); - } else { - index_ = source.read_2_bytes_little_endian(); + // if (wire) { + // index_ = source.read_4_bytes_little_endian(); + // } else { + // index_ = source.read_2_bytes_little_endian(); - if (index_ == max_uint16) { - index_ = null_index; - } - } + // if (index_ == max_uint16) { + // index_ = null_index; + // } + // } - if ( ! source) { - reset(); - } + // if ( ! source) { + // reset(); + // } - return source; - } + // return source; + // } + + static + expect from_data(byte_reader& reader, bool wire = true); // constexpr [[nodiscard]] diff --git a/include/kth/domain/chain/script.hpp b/include/kth/domain/chain/script.hpp index 0852f6f1a..965e41779 100644 --- a/include/kth/domain/chain/script.hpp +++ b/include/kth/domain/chain/script.hpp @@ -37,7 +37,6 @@ namespace kth::domain::chain { class transaction; -class witness; class KD_API script : public script_basis { public: @@ -51,11 +50,26 @@ class KD_API script : public script_basis { script() = default; + explicit script(operation::list const& ops); + + explicit script(operation::list&& ops); + + explicit script(data_chunk const& encoded, bool prefix); + script(data_chunk&& encoded, bool prefix); + explicit + script(script_basis const& x); + + explicit + script(script_basis&& x) noexcept; + + // Special member functions. + //------------------------------------------------------------------------- + script(script const& x); script(script&& x) noexcept; script& operator=(script const& x); @@ -64,6 +78,12 @@ class KD_API script : public script_basis { // Deserialization. //------------------------------------------------------------------------- + static + expect