Skip to content

Commit

Permalink
[zPIV][Cleanup] PublicSpend rebase onto IsZerocoin
Browse files Browse the repository at this point in the history
  • Loading branch information
random-zebra authored and furszy committed May 23, 2019
1 parent 3c74d6d commit 657bb41
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 28 deletions.
16 changes: 8 additions & 8 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1085,7 +1085,7 @@ bool CheckZerocoinSpend(const CTransaction& tx, bool fVerifySignature, CValidati
for (const CTxIn& txin : tx.vin) {

//only check txin that is a zcspend
bool isPublicSpend = txin.scriptSig.IsZerocoinPublicSpend();
bool isPublicSpend = txin.IsZerocoinPublicSpend();
if (!txin.IsZerocoinSpend() && !isPublicSpend)
continue;

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

//Check all zerocoinspends for bad serials
for (const CTxIn& in : tx.vin) {
bool isPublicSpend = in.scriptSig.IsZerocoinPublicSpend();
bool isPublicSpend = in.IsZerocoinPublicSpend();
if (in.IsZerocoinSpend() || isPublicSpend) {

CoinSpend* spend;
Expand Down Expand Up @@ -2654,7 +2654,7 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex
if (tx.HasZerocoinSpendInputs()) {
//erase all zerocoinspends in this transaction
for (const CTxIn &txin : tx.vin) {
bool isPublicSpend = txin.scriptSig.IsZerocoinPublicSpend();
bool isPublicSpend = txin.IsZerocoinPublicSpend();
if (txin.scriptSig.IsZerocoinSpend() || isPublicSpend) {
CBigNum serial;
if (isPublicSpend) {
Expand Down Expand Up @@ -3223,7 +3223,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
//Check for double spending of serial #'s
set<CBigNum> setSerials;
for (const CTxIn& txIn : tx.vin) {
bool isPublicSpend = txIn.scriptSig.IsZerocoinPublicSpend();
bool isPublicSpend = txIn.IsZerocoinPublicSpend();
bool isPrivZerocoinSpend = txIn.IsZerocoinSpend();
if (!isPrivZerocoinSpend && !isPublicSpend)
continue;
Expand Down Expand Up @@ -4427,7 +4427,7 @@ bool CheckBlock(const CBlock& block, CValidationState& state, bool fCheckPOW, bo
// double check that there are no double spent zPIV spends in this block
if (tx.HasZerocoinSpendInputs()) {
for (const CTxIn& txIn : tx.vin) {
bool isPublicSpend = txIn.scriptSig.IsZerocoinPublicSpend();
bool isPublicSpend = txIn.IsZerocoinPublicSpend();
if (txIn.IsZerocoinSpend() || isPublicSpend) {
libzerocoin::CoinSpend spend;
if (isPublicSpend) {
Expand Down Expand Up @@ -4785,7 +4785,7 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CBlockIndex** ppindex,
for (const CTransaction& tx : block.vtx) {
for (const CTxIn& in: tx.vin) {
if(nHeight >= Params().Zerocoin_StartHeight()) {
bool isPublicSpend = in.scriptSig.IsZerocoinPublicSpend();
bool isPublicSpend = in.IsZerocoinPublicSpend();
bool isPrivZerocoinSpend = in.IsZerocoinSpend();
if (isPrivZerocoinSpend || isPublicSpend) {

Expand Down
2 changes: 1 addition & 1 deletion src/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn, CWallet* pwallet,

bool fDoubleSerial = false;
for (const CTxIn& txIn : tx.vin) {
bool isPublicSpend = txIn.scriptSig.IsZerocoinPublicSpend();
bool isPublicSpend = txIn.IsZerocoinPublicSpend();
if (txIn.IsZerocoinSpend() || isPublicSpend) {
libzerocoin::CoinSpend* spend;
if (isPublicSpend) {
Expand Down
13 changes: 9 additions & 4 deletions src/primitives/transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ bool CTxIn::IsZerocoinSpend() const
return prevout.hash == 0 && scriptSig.IsZerocoinSpend();
}

bool CTxIn::IsZerocoinPublicSpend() const
{
return scriptSig.IsZerocoinPublicSpend();
}

std::string CTxIn::ToString() const
{
std::string str;
Expand Down Expand Up @@ -166,7 +171,7 @@ CTransaction& CTransaction::operator=(const CTransaction &tx) {
bool CTransaction::HasZerocoinSpendInputs() const
{
for (const CTxIn& txin: vin) {
if (txin.IsZerocoinSpend() || txin.scriptSig.IsZerocoinPublicSpend())
if (txin.IsZerocoinSpend() || txin.IsZerocoinPublicSpend())
return true;
}
return false;
Expand All @@ -181,11 +186,11 @@ bool CTransaction::HasZerocoinMintOutputs() const
return false;
}

bool CTransaction::IsZerocoinPublicSpend() const
bool CTransaction::HasZerocoinPublicSpendInputs() const
{
// The wallet only allows publicSpend inputs in the same tx and not a combination between piv and zpiv
for(const CTxIn& txin : vin) {
if (txin.scriptSig.IsZerocoinPublicSpend())
if (txin.IsZerocoinPublicSpend())
return true;
}
return false;
Expand Down Expand Up @@ -254,7 +259,7 @@ CAmount CTransaction::GetZerocoinSpent() const
{
CAmount nValueOut = 0;
for (const CTxIn& txin : vin) {
if(!txin.IsZerocoinSpend() && !txin.scriptSig.IsZerocoinPublicSpend())
if(!txin.IsZerocoinSpend())
continue;

nValueOut += txin.nSequence * COIN;
Expand Down
6 changes: 3 additions & 3 deletions src/primitives/transaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class CTxIn
}

bool IsZerocoinSpend() const;
bool IsZerocoinPublicSpend() const;

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

bool HasZerocoinSpendInputs() const;
bool HasZerocoinPublicSpendInputs() const;

bool HasZerocoinMintOutputs() const;

bool ContainsZerocoins() const
{
return HasZerocoinSpendInputs() || HasZerocoinMintOutputs();
return HasZerocoinSpendInputs() || HasZerocoinPublicSpendInputs() || HasZerocoinMintOutputs();
}

bool IsZerocoinPublicSpend() const;

CAmount GetZerocoinMinted() const;
CAmount GetZerocoinSpent() const;
int GetZerocoinMintCount() const;
Expand Down
2 changes: 1 addition & 1 deletion src/qt/transactionrecord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ QList<TransactionRecord> TransactionRecord::decomposeTransaction(const CWallet*

if (wtx.HasZerocoinSpendInputs()) {
// a zerocoin spend that was created by this wallet
if (wtx.IsZerocoinPublicSpend()) {
if (wtx.HasZerocoinPublicSpendInputs()) {
libzerocoin::ZerocoinParams* params = Params().Zerocoin_Params(false);
PublicCoinSpend publicSpend(params);
CValidationState state;
Expand Down
2 changes: 1 addition & 1 deletion src/rpc/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1051,7 +1051,7 @@ UniValue getfeeinfo(const UniValue& params, bool fHelp)
continue;

for (unsigned int j = 0; j < tx.vin.size(); j++) {
if (tx.vin[j].IsZerocoinSpend() || tx.vin[j].scriptSig.IsZerocoinPublicSpend()) {
if (tx.vin[j].IsZerocoinSpend() || tx.vin[j].IsZerocoinPublicSpend()) {
nValueIn += tx.vin[j].nSequence * COIN;
continue;
}
Expand Down
5 changes: 1 addition & 4 deletions src/script/script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,7 @@ bool CScript::IsZerocoinSpend() const

bool CScript::IsZerocoinPublicSpend() const
{
if (this->empty())
return false;

return (this->at(0) == OP_ZEROCOINPUBLICSPEND);
return StartsWithOpcode(OP_ZEROCOINPUBLICSPEND);
}

bool CScript::IsPushOnly(const_iterator pc) const
Expand Down
4 changes: 2 additions & 2 deletions src/txmempool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -565,11 +565,11 @@ void CTxMemPool::check(const CCoinsViewCache* pcoins) const
fDependsWait = true;
} else {
const CCoins* coins = pcoins->AccessCoins(txin.prevout.hash);
if(!txin.IsZerocoinSpend() && !txin.scriptSig.IsZerocoinPublicSpend())
if(!txin.IsZerocoinSpend() && !txin.IsZerocoinPublicSpend())
assert(coins && coins->IsAvailable(txin.prevout.n));
}
// Check whether its inputs are marked in mapNextTx.
if(!txin.IsZerocoinSpend() && !txin.scriptSig.IsZerocoinPublicSpend()) {
if(!txin.IsZerocoinSpend() && !txin.IsZerocoinPublicSpend()) {
std::map<COutPoint, CInPoint>::const_iterator it3 = mapNextTx.find(txin.prevout);
assert(it3 != mapNextTx.end());
assert(it3->second.ptx == &tx);
Expand Down
4 changes: 2 additions & 2 deletions src/zpiv/zpivmodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ namespace ZPIVModule {
}

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

std::vector<char, zero_after_free_allocator<char> > data;
Expand Down Expand Up @@ -123,4 +123,4 @@ namespace ZPIVModule {
}
return true;
}
}
}
4 changes: 2 additions & 2 deletions src/zpivchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ std::string ReindexZerocoinDB()
//Record Serials
if (tx.HasZerocoinSpendInputs()) {
for (auto& in : tx.vin) {
bool isPublicSpend = in.scriptSig.IsZerocoinPublicSpend();
bool isPublicSpend = in.IsZerocoinPublicSpend();
if (!in.IsZerocoinSpend() && !isPublicSpend)
continue;
if (isPublicSpend) {
Expand Down Expand Up @@ -387,7 +387,7 @@ std::list<libzerocoin::CoinDenomination> ZerocoinSpendListFromBlock(const CBlock
continue;

for (const CTxIn& txin : tx.vin) {
bool isPublicSpend = txin.scriptSig.IsZerocoinPublicSpend();
bool isPublicSpend = txin.IsZerocoinPublicSpend();
if (!txin.IsZerocoinSpend() && !isPublicSpend)
continue;

Expand Down

0 comments on commit 657bb41

Please sign in to comment.