From b10216a76164f5dd5804cacb61dcac853eb3a898 Mon Sep 17 00:00:00 2001 From: Zannick Date: Tue, 5 Oct 2021 11:24:47 -0700 Subject: [PATCH] Split ZerocoinSpendReceipt into a generic Receipt. --- src/Makefile.am | 4 +++- src/veil/ringct/receipt.cpp | 33 ++++++++++++++++++++++++++++++ src/veil/ringct/receipt.h | 28 +++++++++++++++++++++++++ src/veil/zerocoin/spendreceipt.cpp | 23 ++------------------- src/veil/zerocoin/spendreceipt.h | 15 +++----------- 5 files changed, 69 insertions(+), 34 deletions(-) create mode 100644 src/veil/ringct/receipt.cpp create mode 100644 src/veil/ringct/receipt.h diff --git a/src/Makefile.am b/src/Makefile.am index 1b43f73ff4..fc3f89b657 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -207,6 +207,7 @@ BITCOIN_CORE_H = \ veil/ringct/keyutil.h \ veil/ringct/outputrecord.h \ veil/ringct/rctindex.h \ + veil/ringct/receipt.h \ veil/ringct/rpcanonwallet.h \ veil/ringct/stealth.h \ veil/ringct/temprecipient.h \ @@ -350,11 +351,12 @@ libbitcoin_wallet_a_SOURCES = \ veil/zerocoin/spendreceipt.cpp \ veil/zerocoin/ztracker.cpp \ veil/zerocoin/zwallet.cpp \ - veil/ringct/temprecipient.cpp \ veil/ringct/anonwalletdb.cpp \ veil/ringct/anonwallet.cpp \ veil/ringct/outputrecord.cpp \ + veil/ringct/receipt.cpp \ veil/ringct/rpcanonwallet.cpp \ + veil/ringct/temprecipient.cpp \ $(BITCOIN_CORE_H) if TARGET_ARM64 diff --git a/src/veil/ringct/receipt.cpp b/src/veil/ringct/receipt.cpp new file mode 100644 index 0000000000..d6fd8c2ce9 --- /dev/null +++ b/src/veil/ringct/receipt.cpp @@ -0,0 +1,33 @@ +// Copyright (c) 2017-2019 The PIVX developers +// Copyright (c) 2019-2021 The Veil developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include +#include + + +void CMultiTxReceipt::SetStatus(std::string strStatus, int nStatus) +{ + strStatusMessage = strStatus; + this->nStatus = nStatus; +} + +CTransactionRecord CMultiTxReceipt::GetTransactionRecord(const int n) const +{ + if (!mapRecords.count(n)) + return CTransactionRecord(); + return mapRecords.at(n); +} + +void CMultiTxReceipt::AddTransaction(CTransactionRef& txRef, const CTransactionRecord& rtx) +{ + auto n = vtx.size(); + mapRecords.emplace(n, rtx); + vtx.emplace_back(txRef); +} + +std::string CMultiTxReceipt::GetStatusMessage() +{ + return strStatusMessage; +} diff --git a/src/veil/ringct/receipt.h b/src/veil/ringct/receipt.h new file mode 100644 index 0000000000..77ec1cf07b --- /dev/null +++ b/src/veil/ringct/receipt.h @@ -0,0 +1,28 @@ +// Copyright (c) 2017-2019 The PIVX developers +// Copyright (c) 2019-2021 The Veil developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef VEIL_RECEIPT_H +#define VEIL_RECEIPT_H + +#include +#include + +class CMultiTxReceipt +{ +protected: + std::string strStatusMessage; + int nStatus; + std::map mapRecords; // key:tx's spot in vtx + std::vector vtx; + +public: + void AddTransaction(CTransactionRef& txRef, const CTransactionRecord& rtx); + void SetStatus(std::string strStatus, int nStatus); + std::string GetStatusMessage(); + std::vector GetTransactions() const { return vtx; } + CTransactionRecord GetTransactionRecord(int n) const; +}; + +#endif //VEIL_RECEIPT_H diff --git a/src/veil/zerocoin/spendreceipt.cpp b/src/veil/zerocoin/spendreceipt.cpp index 4fe3cc095a..4c484abce1 100644 --- a/src/veil/zerocoin/spendreceipt.cpp +++ b/src/veil/zerocoin/spendreceipt.cpp @@ -4,6 +4,7 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include +#include #include void CZerocoinSpendReceipt::AddSpend(const CZerocoinSpend& spend) @@ -31,26 +32,6 @@ std::vector CZerocoinSpendReceipt::GetSpends_back() void CZerocoinSpendReceipt::SetStatus(std::string strStatus, int nStatus, int nNeededSpends) { - strStatusMessage = strStatus; - this->nStatus = nStatus; + CMultiTxReceipt::SetStatus(strStatus, nStatus); this->nNeededSpends = nNeededSpends; } - -CTransactionRecord CZerocoinSpendReceipt::GetTransactionRecord(const int n) const -{ - if (!mapRecords.count(n)) - return CTransactionRecord(); - return mapRecords.at(n); -} - -void CZerocoinSpendReceipt::AddTransaction(CTransactionRef& txRef, const CTransactionRecord& rtx) -{ - auto n = vtx.size(); - mapRecords.emplace(n, rtx); - vtx.emplace_back(txRef); -} - -std::string CZerocoinSpendReceipt::GetStatusMessage() -{ - return strStatusMessage; -} diff --git a/src/veil/zerocoin/spendreceipt.h b/src/veil/zerocoin/spendreceipt.h index dfd1d1e616..475f8d9311 100644 --- a/src/veil/zerocoin/spendreceipt.h +++ b/src/veil/zerocoin/spendreceipt.h @@ -1,5 +1,5 @@ // Copyright (c) 2017-2019 The PIVX developers -// Copyright (c) 2019 The Veil developers +// Copyright (c) 2019-2021 The Veil developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -7,30 +7,21 @@ #define VEIL_SPENDRECEIPT_H #include +#include #include #include -class CTransactionRecord; - -class CZerocoinSpendReceipt +class CZerocoinSpendReceipt : public CMultiTxReceipt { private: - std::string strStatusMessage; - int nStatus; int nNeededSpends; std::map> mapSpends; // key:tx's spot in vtx - std::map mapRecords; // key:tx's spot in vtx - std::vector vtx; public: void AddSpend(const CZerocoinSpend& spend); - void AddTransaction(CTransactionRef& txRef, const CTransactionRecord& rtx); std::vector GetSpends(int n); std::vector GetSpends_back(); void SetStatus(std::string strStatus, int nStatus, int nNeededSpends = 0); - std::string GetStatusMessage(); - std::vector GetTransactions() const { return vtx; } - CTransactionRecord GetTransactionRecord(int n) const; }; #endif //VEIL_SPENDRECEIPT_H