#pragma once // Copyright (c) 2018-2019 David Burkett // Distributed under the MIT software license, see the accompanying // file LICENSE or http://www.opensource.org/licenses/mit-license.php. #include #include #include #include #include #include #include #include #include #include #include //////////////////////////////////////// // TRANSACTION BODY - Container for all inputs, outputs, and kernels in a transaction or block. //////////////////////////////////////// class TxBody : public Traits::ISerializable { public: using CPtr = std::shared_ptr; // // Constructors // TxBody(std::vector inputs, std::vector outputs, std::vector kernels) : m_inputs(std::move(inputs)), m_outputs(std::move(outputs)), m_kernels(std::move(kernels)) { } TxBody(const TxBody& other) = default; TxBody(TxBody&& other) noexcept = default; TxBody() = default; // // Destructor // virtual ~TxBody() = default; // // Operators // TxBody& operator=(const TxBody& other) = default; TxBody& operator=(TxBody&& other) noexcept = default; bool operator==(const TxBody& rhs) const noexcept { return m_inputs == rhs.m_inputs && m_outputs == rhs.m_outputs && m_kernels == rhs.m_kernels; } // // Getters // const std::vector& GetInputs() const noexcept { return m_inputs; } const std::vector& GetOutputs() const noexcept { return m_outputs; } const std::vector& GetKernels() const noexcept { return m_kernels; } std::vector GetKernelCommits() const noexcept { return Commitments::From(m_kernels); } std::vector GetInputCommits() const noexcept { return Commitments::From(m_inputs); } std::vector GetOutputCommits() const noexcept { return Commitments::From(m_outputs); } std::vector GetKernelIDs() const noexcept { return Hashes::From(m_kernels); } std::vector GetSpentIDs() const noexcept { std::vector output_ids; std::transform( m_inputs.cbegin(), m_inputs.cend(), std::back_inserter(output_ids), [](const Input& input) { return input.GetOutputID(); }); return output_ids; } std::vector GetOutputIDs() const noexcept { return Hashes::From(m_outputs); } std::vector GetStealthExcesses() const noexcept { std::vector stealth_excesses; for (const Kernel& kernel : m_kernels) { if (kernel.HasStealthExcess()) { stealth_excesses.push_back(kernel.GetStealthExcess()); } } return stealth_excesses; } std::vector GetPegIns() const noexcept; boost::optional GetPegInAmount() const noexcept; std::vector GetPegOuts() const noexcept; boost::optional GetTotalFee() const noexcept; boost::optional GetSupplyChange() const noexcept; int32_t GetLockHeight() const noexcept; // // Serialization/Deserialization // IMPL_SERIALIZABLE(TxBody, obj) { READWRITE(obj.m_inputs, obj.m_outputs, obj.m_kernels); } void Validate() const; private: // List of inputs spent by the transaction. std::vector m_inputs; // List of outputs the transaction produces. std::vector m_outputs; // List of kernels that make up this transaction. std::vector m_kernels; };