Skip to content

Commit 657bb41

Browse files
random-zebrafurszy
authored andcommitted
[zPIV][Cleanup] PublicSpend rebase onto IsZerocoin
1 parent 3c74d6d commit 657bb41

File tree

10 files changed

+30
-28
lines changed

10 files changed

+30
-28
lines changed

src/main.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,7 +1085,7 @@ bool CheckZerocoinSpend(const CTransaction& tx, bool fVerifySignature, CValidati
10851085
for (const CTxIn& txin : tx.vin) {
10861086

10871087
//only check txin that is a zcspend
1088-
bool isPublicSpend = txin.scriptSig.IsZerocoinPublicSpend();
1088+
bool isPublicSpend = txin.IsZerocoinPublicSpend();
10891089
if (!txin.IsZerocoinSpend() && !isPublicSpend)
10901090
continue;
10911091

@@ -1221,7 +1221,7 @@ bool CheckTransaction(const CTransaction& tx, bool fZerocoinActive, bool fReject
12211221
//require that a zerocoinspend only has inputs that are zerocoins
12221222
if (tx.HasZerocoinSpendInputs()) {
12231223
for (const CTxIn& in : tx.vin) {
1224-
if (!in.IsZerocoinSpend() && !in.scriptSig.IsZerocoinPublicSpend())
1224+
if (!in.IsZerocoinSpend() && !in.IsZerocoinPublicSpend())
12251225
return state.DoS(100,
12261226
error("CheckTransaction() : zerocoinspend contains inputs that are not zerocoins"));
12271227
}
@@ -1394,7 +1394,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState& state, const CTransa
13941394
//Check for double spending of serial #'s
13951395
for (const CTxIn& txIn : tx.vin) {
13961396
// Only allow for zc spends inputs
1397-
bool isPublicSpend = txIn.scriptSig.IsZerocoinPublicSpend();
1397+
bool isPublicSpend = txIn.IsZerocoinPublicSpend();
13981398
if (!txIn.IsZerocoinSpend() && !isPublicSpend) {
13991399
return state.Invalid(error("%s: ContextualCheckZerocoinSpend failed for tx %s, every input must be a zcspend or zcpublicspend", __func__,
14001400
tx.GetHash().GetHex()), REJECT_INVALID, "bad-txns-invalid-zpiv");
@@ -2447,7 +2447,7 @@ void AddInvalidSpendsToMap(const CBlock& block)
24472447

24482448
//Check all zerocoinspends for bad serials
24492449
for (const CTxIn& in : tx.vin) {
2450-
bool isPublicSpend = in.scriptSig.IsZerocoinPublicSpend();
2450+
bool isPublicSpend = in.IsZerocoinPublicSpend();
24512451
if (in.IsZerocoinSpend() || isPublicSpend) {
24522452

24532453
CoinSpend* spend;
@@ -2654,7 +2654,7 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex
26542654
if (tx.HasZerocoinSpendInputs()) {
26552655
//erase all zerocoinspends in this transaction
26562656
for (const CTxIn &txin : tx.vin) {
2657-
bool isPublicSpend = txin.scriptSig.IsZerocoinPublicSpend();
2657+
bool isPublicSpend = txin.IsZerocoinPublicSpend();
26582658
if (txin.scriptSig.IsZerocoinSpend() || isPublicSpend) {
26592659
CBigNum serial;
26602660
if (isPublicSpend) {
@@ -3223,7 +3223,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
32233223
//Check for double spending of serial #'s
32243224
set<CBigNum> setSerials;
32253225
for (const CTxIn& txIn : tx.vin) {
3226-
bool isPublicSpend = txIn.scriptSig.IsZerocoinPublicSpend();
3226+
bool isPublicSpend = txIn.IsZerocoinPublicSpend();
32273227
bool isPrivZerocoinSpend = txIn.IsZerocoinSpend();
32283228
if (!isPrivZerocoinSpend && !isPublicSpend)
32293229
continue;
@@ -4427,7 +4427,7 @@ bool CheckBlock(const CBlock& block, CValidationState& state, bool fCheckPOW, bo
44274427
// double check that there are no double spent zPIV spends in this block
44284428
if (tx.HasZerocoinSpendInputs()) {
44294429
for (const CTxIn& txIn : tx.vin) {
4430-
bool isPublicSpend = txIn.scriptSig.IsZerocoinPublicSpend();
4430+
bool isPublicSpend = txIn.IsZerocoinPublicSpend();
44314431
if (txIn.IsZerocoinSpend() || isPublicSpend) {
44324432
libzerocoin::CoinSpend spend;
44334433
if (isPublicSpend) {
@@ -4785,7 +4785,7 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CBlockIndex** ppindex,
47854785
for (const CTransaction& tx : block.vtx) {
47864786
for (const CTxIn& in: tx.vin) {
47874787
if(nHeight >= Params().Zerocoin_StartHeight()) {
4788-
bool isPublicSpend = in.scriptSig.IsZerocoinPublicSpend();
4788+
bool isPublicSpend = in.IsZerocoinPublicSpend();
47894789
bool isPrivZerocoinSpend = in.IsZerocoinSpend();
47904790
if (isPrivZerocoinSpend || isPublicSpend) {
47914791

src/miner.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn, CWallet* pwallet,
371371

372372
bool fDoubleSerial = false;
373373
for (const CTxIn& txIn : tx.vin) {
374-
bool isPublicSpend = txIn.scriptSig.IsZerocoinPublicSpend();
374+
bool isPublicSpend = txIn.IsZerocoinPublicSpend();
375375
if (txIn.IsZerocoinSpend() || isPublicSpend) {
376376
libzerocoin::CoinSpend* spend;
377377
if (isPublicSpend) {

src/primitives/transaction.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ bool CTxIn::IsZerocoinSpend() const
6464
return prevout.hash == 0 && scriptSig.IsZerocoinSpend();
6565
}
6666

67+
bool CTxIn::IsZerocoinPublicSpend() const
68+
{
69+
return scriptSig.IsZerocoinPublicSpend();
70+
}
71+
6772
std::string CTxIn::ToString() const
6873
{
6974
std::string str;
@@ -166,7 +171,7 @@ CTransaction& CTransaction::operator=(const CTransaction &tx) {
166171
bool CTransaction::HasZerocoinSpendInputs() const
167172
{
168173
for (const CTxIn& txin: vin) {
169-
if (txin.IsZerocoinSpend() || txin.scriptSig.IsZerocoinPublicSpend())
174+
if (txin.IsZerocoinSpend() || txin.IsZerocoinPublicSpend())
170175
return true;
171176
}
172177
return false;
@@ -181,11 +186,11 @@ bool CTransaction::HasZerocoinMintOutputs() const
181186
return false;
182187
}
183188

184-
bool CTransaction::IsZerocoinPublicSpend() const
189+
bool CTransaction::HasZerocoinPublicSpendInputs() const
185190
{
186191
// The wallet only allows publicSpend inputs in the same tx and not a combination between piv and zpiv
187192
for(const CTxIn& txin : vin) {
188-
if (txin.scriptSig.IsZerocoinPublicSpend())
193+
if (txin.IsZerocoinPublicSpend())
189194
return true;
190195
}
191196
return false;
@@ -254,7 +259,7 @@ CAmount CTransaction::GetZerocoinSpent() const
254259
{
255260
CAmount nValueOut = 0;
256261
for (const CTxIn& txin : vin) {
257-
if(!txin.IsZerocoinSpend() && !txin.scriptSig.IsZerocoinPublicSpend())
262+
if(!txin.IsZerocoinSpend())
258263
continue;
259264

260265
nValueOut += txin.nSequence * COIN;

src/primitives/transaction.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ class CTxIn
9696
}
9797

9898
bool IsZerocoinSpend() const;
99+
bool IsZerocoinPublicSpend() const;
99100

100101
friend bool operator==(const CTxIn& a, const CTxIn& b)
101102
{
@@ -260,16 +261,15 @@ class CTransaction
260261
unsigned int CalculateModifiedSize(unsigned int nTxSize=0) const;
261262

262263
bool HasZerocoinSpendInputs() const;
264+
bool HasZerocoinPublicSpendInputs() const;
263265

264266
bool HasZerocoinMintOutputs() const;
265267

266268
bool ContainsZerocoins() const
267269
{
268-
return HasZerocoinSpendInputs() || HasZerocoinMintOutputs();
270+
return HasZerocoinSpendInputs() || HasZerocoinPublicSpendInputs() || HasZerocoinMintOutputs();
269271
}
270272

271-
bool IsZerocoinPublicSpend() const;
272-
273273
CAmount GetZerocoinMinted() const;
274274
CAmount GetZerocoinSpent() const;
275275
int GetZerocoinMintCount() const;

src/qt/transactionrecord.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ QList<TransactionRecord> TransactionRecord::decomposeTransaction(const CWallet*
4646

4747
if (wtx.HasZerocoinSpendInputs()) {
4848
// a zerocoin spend that was created by this wallet
49-
if (wtx.IsZerocoinPublicSpend()) {
49+
if (wtx.HasZerocoinPublicSpendInputs()) {
5050
libzerocoin::ZerocoinParams* params = Params().Zerocoin_Params(false);
5151
PublicCoinSpend publicSpend(params);
5252
CValidationState state;

src/rpc/blockchain.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1051,7 +1051,7 @@ UniValue getfeeinfo(const UniValue& params, bool fHelp)
10511051
continue;
10521052

10531053
for (unsigned int j = 0; j < tx.vin.size(); j++) {
1054-
if (tx.vin[j].IsZerocoinSpend() || tx.vin[j].scriptSig.IsZerocoinPublicSpend()) {
1054+
if (tx.vin[j].IsZerocoinSpend() || tx.vin[j].IsZerocoinPublicSpend()) {
10551055
nValueIn += tx.vin[j].nSequence * COIN;
10561056
continue;
10571057
}

src/script/script.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,10 +266,7 @@ bool CScript::IsZerocoinSpend() const
266266

267267
bool CScript::IsZerocoinPublicSpend() const
268268
{
269-
if (this->empty())
270-
return false;
271-
272-
return (this->at(0) == OP_ZEROCOINPUBLICSPEND);
269+
return StartsWithOpcode(OP_ZEROCOINPUBLICSPEND);
273270
}
274271

275272
bool CScript::IsPushOnly(const_iterator pc) const

src/txmempool.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -565,11 +565,11 @@ void CTxMemPool::check(const CCoinsViewCache* pcoins) const
565565
fDependsWait = true;
566566
} else {
567567
const CCoins* coins = pcoins->AccessCoins(txin.prevout.hash);
568-
if(!txin.IsZerocoinSpend() && !txin.scriptSig.IsZerocoinPublicSpend())
568+
if(!txin.IsZerocoinSpend() && !txin.IsZerocoinPublicSpend())
569569
assert(coins && coins->IsAvailable(txin.prevout.n));
570570
}
571571
// Check whether its inputs are marked in mapNextTx.
572-
if(!txin.IsZerocoinSpend() && !txin.scriptSig.IsZerocoinPublicSpend()) {
572+
if(!txin.IsZerocoinSpend() && !txin.IsZerocoinPublicSpend()) {
573573
std::map<COutPoint, CInPoint>::const_iterator it3 = mapNextTx.find(txin.prevout);
574574
assert(it3 != mapNextTx.end());
575575
assert(it3->second.ptx == &tx);

src/zpiv/zpivmodule.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ namespace ZPIVModule {
7575
}
7676

7777
bool parseCoinSpend(const CTxIn &in, const CTransaction &tx, const CTxOut &prevOut, PublicCoinSpend &publicCoinSpend) {
78-
if (!in.scriptSig.IsZerocoinPublicSpend() || !prevOut.scriptPubKey.IsZerocoinMint())
78+
if (!in.IsZerocoinPublicSpend() || !prevOut.IsZerocoinMint())
7979
return error("%s: invalid argument/s\n", __func__);
8080

8181
std::vector<char, zero_after_free_allocator<char> > data;
@@ -123,4 +123,4 @@ namespace ZPIVModule {
123123
}
124124
return true;
125125
}
126-
}
126+
}

src/zpivchain.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ std::string ReindexZerocoinDB()
286286
//Record Serials
287287
if (tx.HasZerocoinSpendInputs()) {
288288
for (auto& in : tx.vin) {
289-
bool isPublicSpend = in.scriptSig.IsZerocoinPublicSpend();
289+
bool isPublicSpend = in.IsZerocoinPublicSpend();
290290
if (!in.IsZerocoinSpend() && !isPublicSpend)
291291
continue;
292292
if (isPublicSpend) {
@@ -387,7 +387,7 @@ std::list<libzerocoin::CoinDenomination> ZerocoinSpendListFromBlock(const CBlock
387387
continue;
388388

389389
for (const CTxIn& txin : tx.vin) {
390-
bool isPublicSpend = txin.scriptSig.IsZerocoinPublicSpend();
390+
bool isPublicSpend = txin.IsZerocoinPublicSpend();
391391
if (!txin.IsZerocoinSpend() && !isPublicSpend)
392392
continue;
393393

0 commit comments

Comments
 (0)