diff --git a/src/primitives/orchard.h b/src/primitives/orchard.h new file mode 100644 index 000000000..7caf7af00 --- /dev/null +++ b/src/primitives/orchard.h @@ -0,0 +1,70 @@ +// Copyright (c) 2021 The Zcash Developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or https://www.opensource.org/licenses/mit-license.php . + +#ifndef ZCASH_PRIMITIVES_ORCHARD_H +#define ZCASH_PRIMITIVES_ORCHARD_H + +#include + +/** + * The Orchard component of a transaction. + */ +class OrchardBundle +{ +private: + /// An optional Orchard bundle (with `nullptr` corresponding to `None`). + /// Memory is allocated by Rust. + std::unique_ptr inner; + +public: + OrchardBundle() : inner(nullptr, orchard_bundle_free) {} + + OrchardBundle(OrchardBundle&& bundle) : inner(std::move(bundle.inner)) {} + OrchardBundle(const OrchardBundle& bundle) : + inner(orchard_bundle_clone(bundle.inner.get()), orchard_bundle_free) {} + OrchardBundle& operator=(OrchardBundle&& bundle) + { + if (this != &bundle) { + inner = std::move(bundle.inner); + } + return *this; + } + OrchardBundle& operator=(const OrchardBundle& bundle) + { + if (this != &bundle) { + inner.reset(orchard_bundle_clone(bundle.inner.get())); + } + return *this; + } + + template + void Serialize(Stream& s) const { + RustStream rs(s); + if (!orchard_bundle_serialize(inner.get(), &rs, RustStream::write_callback)) { + throw std::ios_base::failure("Failed to serialize v5 Orchard bundle"); + } + } + + template + void Unserialize(Stream& s) { + RustStream rs(s); + OrchardBundlePtr* bundle; + if (!orchard_bundle_parse(&rs, RustStream::read_callback, &bundle)) { + throw std::ios_base::failure("Failed to parse v5 Orchard bundle"); + } + inner.reset(bundle); + } + + /// Queues this bundle's signatures for validation. + /// + /// `txid` must be for the transaction this bundle is within. + void QueueSignatureValidation( + orchard::AuthValidator& batch, const uint256& txid) const + { + batch.Queue(inner.get(), txid.begin()); + } +}; + +#endif // ZCASH_PRIMITIVES_ORCHARD_H + diff --git a/src/primitives/transaction.h b/src/primitives/transaction.h index 3a80bb8ef..01149457b 100644 --- a/src/primitives/transaction.h +++ b/src/primitives/transaction.h @@ -23,7 +23,7 @@ #include "zcash/Proof.hpp" #include -#include +#include // Overwinter transaction version group id static constexpr uint32_t OVERWINTER_VERSION_GROUP_ID = 0x03C48270; @@ -326,65 +326,6 @@ public: std::vector GetV4ShieldedOutput(); }; -/** - * The Orchard component of a transaction. - */ -class OrchardBundle -{ -private: - /// An optional Orchard bundle (with `nullptr` corresponding to `None`). - /// Memory is allocated by Rust. - std::unique_ptr inner; - -public: - OrchardBundle() : inner(nullptr, orchard_bundle_free) {} - - OrchardBundle(OrchardBundle&& bundle) : inner(std::move(bundle.inner)) {} - OrchardBundle(const OrchardBundle& bundle) : - inner(orchard_bundle_clone(bundle.inner.get()), orchard_bundle_free) {} - OrchardBundle& operator=(OrchardBundle&& bundle) - { - if (this != &bundle) { - inner = std::move(bundle.inner); - } - return *this; - } - OrchardBundle& operator=(const OrchardBundle& bundle) - { - if (this != &bundle) { - inner.reset(orchard_bundle_clone(bundle.inner.get())); - } - return *this; - } - - template - void Serialize(Stream& s) const { - RustStream rs(s); - if (!orchard_bundle_serialize(inner.get(), &rs, RustStream::write_callback)) { - throw std::ios_base::failure("Failed to serialize v5 Orchard bundle"); - } - } - - template - void Unserialize(Stream& s) { - RustStream rs(s); - OrchardBundlePtr* bundle; - if (!orchard_bundle_parse(&rs, RustStream::read_callback, &bundle)) { - throw std::ios_base::failure("Failed to parse v5 Orchard bundle"); - } - inner.reset(bundle); - } - - /// Queues this bundle's signatures for validation. - /// - /// `txid` must be for the transaction this bundle is within. - void QueueSignatureValidation( - orchard::AuthValidator& batch, const uint256& txid) const - { - batch.Queue(inner.get(), txid.begin()); - } -}; - template class SproutProofSerializer {