Skip to content

Commit eaf16a5

Browse files
Merge #974: [Refactor] Split ZerocoinSpendReceipt into a generic Receipt.
b10216a Split ZerocoinSpendReceipt into a generic Receipt. (Zannick) Pull request description: This makes it easier to organize multiple transactions into a single receipt regardless of whether it's a zerocoin spend or something else. (#970) Tree-SHA512: be829a0007ccbdc7e7c784964c2b02c198a2e9ce9d050696ea66d6e79999fafc2764e9e7eb088d2feefeb4c4f5529366d450f55e2e62a66f09019d33cacbb747
2 parents f23bf74 + b10216a commit eaf16a5

File tree

5 files changed

+69
-34
lines changed

5 files changed

+69
-34
lines changed

src/Makefile.am

+3-1
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ BITCOIN_CORE_H = \
210210
veil/ringct/keyutil.h \
211211
veil/ringct/outputrecord.h \
212212
veil/ringct/rctindex.h \
213+
veil/ringct/receipt.h \
213214
veil/ringct/rpcanonwallet.h \
214215
veil/ringct/stealth.h \
215216
veil/ringct/temprecipient.h \
@@ -353,11 +354,12 @@ libbitcoin_wallet_a_SOURCES = \
353354
veil/zerocoin/spendreceipt.cpp \
354355
veil/zerocoin/ztracker.cpp \
355356
veil/zerocoin/zwallet.cpp \
356-
veil/ringct/temprecipient.cpp \
357357
veil/ringct/anonwalletdb.cpp \
358358
veil/ringct/anonwallet.cpp \
359359
veil/ringct/outputrecord.cpp \
360+
veil/ringct/receipt.cpp \
360361
veil/ringct/rpcanonwallet.cpp \
362+
veil/ringct/temprecipient.cpp \
361363
$(BITCOIN_CORE_H)
362364

363365
if TARGET_ARM64

src/veil/ringct/receipt.cpp

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright (c) 2017-2019 The PIVX developers
2+
// Copyright (c) 2019-2021 The Veil developers
3+
// Distributed under the MIT software license, see the accompanying
4+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
5+
6+
#include <veil/ringct/receipt.h>
7+
#include <veil/ringct/transactionrecord.h>
8+
9+
10+
void CMultiTxReceipt::SetStatus(std::string strStatus, int nStatus)
11+
{
12+
strStatusMessage = strStatus;
13+
this->nStatus = nStatus;
14+
}
15+
16+
CTransactionRecord CMultiTxReceipt::GetTransactionRecord(const int n) const
17+
{
18+
if (!mapRecords.count(n))
19+
return CTransactionRecord();
20+
return mapRecords.at(n);
21+
}
22+
23+
void CMultiTxReceipt::AddTransaction(CTransactionRef& txRef, const CTransactionRecord& rtx)
24+
{
25+
auto n = vtx.size();
26+
mapRecords.emplace(n, rtx);
27+
vtx.emplace_back(txRef);
28+
}
29+
30+
std::string CMultiTxReceipt::GetStatusMessage()
31+
{
32+
return strStatusMessage;
33+
}

src/veil/ringct/receipt.h

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright (c) 2017-2019 The PIVX developers
2+
// Copyright (c) 2019-2021 The Veil developers
3+
// Distributed under the MIT software license, see the accompanying
4+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
5+
6+
#ifndef VEIL_RECEIPT_H
7+
#define VEIL_RECEIPT_H
8+
9+
#include <veil/ringct/temprecipient.h>
10+
#include <veil/ringct/transactionrecord.h>
11+
12+
class CMultiTxReceipt
13+
{
14+
protected:
15+
std::string strStatusMessage;
16+
int nStatus;
17+
std::map<int, CTransactionRecord> mapRecords; // key:tx's spot in vtx
18+
std::vector<CTransactionRef> vtx;
19+
20+
public:
21+
void AddTransaction(CTransactionRef& txRef, const CTransactionRecord& rtx);
22+
void SetStatus(std::string strStatus, int nStatus);
23+
std::string GetStatusMessage();
24+
std::vector<CTransactionRef> GetTransactions() const { return vtx; }
25+
CTransactionRecord GetTransactionRecord(int n) const;
26+
};
27+
28+
#endif //VEIL_RECEIPT_H

src/veil/zerocoin/spendreceipt.cpp

+2-21
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
55

66
#include <veil/zerocoin/spendreceipt.h>
7+
#include <veil/ringct/receipt.h>
78
#include <veil/ringct/transactionrecord.h>
89

910
void CZerocoinSpendReceipt::AddSpend(const CZerocoinSpend& spend)
@@ -31,26 +32,6 @@ std::vector<CZerocoinSpend> CZerocoinSpendReceipt::GetSpends_back()
3132

3233
void CZerocoinSpendReceipt::SetStatus(std::string strStatus, int nStatus, int nNeededSpends)
3334
{
34-
strStatusMessage = strStatus;
35-
this->nStatus = nStatus;
35+
CMultiTxReceipt::SetStatus(strStatus, nStatus);
3636
this->nNeededSpends = nNeededSpends;
3737
}
38-
39-
CTransactionRecord CZerocoinSpendReceipt::GetTransactionRecord(const int n) const
40-
{
41-
if (!mapRecords.count(n))
42-
return CTransactionRecord();
43-
return mapRecords.at(n);
44-
}
45-
46-
void CZerocoinSpendReceipt::AddTransaction(CTransactionRef& txRef, const CTransactionRecord& rtx)
47-
{
48-
auto n = vtx.size();
49-
mapRecords.emplace(n, rtx);
50-
vtx.emplace_back(txRef);
51-
}
52-
53-
std::string CZerocoinSpendReceipt::GetStatusMessage()
54-
{
55-
return strStatusMessage;
56-
}

src/veil/zerocoin/spendreceipt.h

+3-12
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,27 @@
11
// Copyright (c) 2017-2019 The PIVX developers
2-
// Copyright (c) 2019 The Veil developers
2+
// Copyright (c) 2019-2021 The Veil developers
33
// Distributed under the MIT software license, see the accompanying
44
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
55

66
#ifndef VEIL_SPENDRECEIPT_H
77
#define VEIL_SPENDRECEIPT_H
88

99
#include <primitives/zerocoin.h>
10+
#include <veil/ringct/receipt.h>
1011
#include <veil/ringct/temprecipient.h>
1112
#include <veil/ringct/transactionrecord.h>
1213

13-
class CTransactionRecord;
14-
15-
class CZerocoinSpendReceipt
14+
class CZerocoinSpendReceipt : public CMultiTxReceipt
1615
{
1716
private:
18-
std::string strStatusMessage;
19-
int nStatus;
2017
int nNeededSpends;
2118
std::map<int, std::vector<CZerocoinSpend>> mapSpends; // key:tx's spot in vtx
22-
std::map<int, CTransactionRecord> mapRecords; // key:tx's spot in vtx
23-
std::vector<CTransactionRef> vtx;
2419

2520
public:
2621
void AddSpend(const CZerocoinSpend& spend);
27-
void AddTransaction(CTransactionRef& txRef, const CTransactionRecord& rtx);
2822
std::vector<CZerocoinSpend> GetSpends(int n);
2923
std::vector<CZerocoinSpend> GetSpends_back();
3024
void SetStatus(std::string strStatus, int nStatus, int nNeededSpends = 0);
31-
std::string GetStatusMessage();
32-
std::vector<CTransactionRef> GetTransactions() const { return vtx; }
33-
CTransactionRecord GetTransactionRecord(int n) const;
3425
};
3526

3627
#endif //VEIL_SPENDRECEIPT_H

0 commit comments

Comments
 (0)