Skip to content

Commit f930016

Browse files
committed
[zPIV] rebase problems fixed. (Needs more testing)
1 parent e7dada8 commit f930016

File tree

4 files changed

+30
-30
lines changed

4 files changed

+30
-30
lines changed

src/main.cpp

+17-16
Original file line numberDiff line numberDiff line change
@@ -2636,17 +2636,17 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex
26362636
* addresses should still be handled by the typical bitcoin based undo code
26372637
* */
26382638
if (tx.ContainsZerocoins()) {
2639-
if (tx.IsZerocoinSpend()) {
2639+
if (tx.HasZerocoinSpendInputs()) {
26402640
//erase all zerocoinspends in this transaction
2641-
for (const CTxIn& txin : tx.vin) {
2641+
for (const CTxIn &txin : tx.vin) {
26422642
bool isPublicSpend = txin.scriptSig.IsZerocoinPublicSpend();
26432643
if (txin.scriptSig.IsZerocoinSpend() || isPublicSpend) {
26442644
CBigNum serial;
26452645
if (isPublicSpend) {
2646-
libzerocoin::ZerocoinParams* params = Params().Zerocoin_Params(false);
2646+
libzerocoin::ZerocoinParams *params = Params().Zerocoin_Params(false);
26472647
PublicCoinSpend publicSpend(params);
26482648
CValidationState state;
2649-
if (!ZPIVModule::ParseZerocoinPublicSpend(txin, tx, state, publicSpend)){
2649+
if (!ZPIVModule::ParseZerocoinPublicSpend(txin, tx, state, publicSpend)) {
26502650
return error("Failed to parse public spend");
26512651
}
26522652
serial = publicSpend.getCoinSerialNumber();
@@ -2660,8 +2660,8 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex
26602660

26612661
//if this was our spend, then mark it unspent now
26622662
if (pwalletMain) {
2663-
if (pwalletMain->IsMyZerocoinSpend(spend.getCoinSerialNumber())) {
2664-
if (!pwalletMain->SetMintUnspent(spend.getCoinSerialNumber()))
2663+
if (pwalletMain->IsMyZerocoinSpend(serial)) {
2664+
if (!pwalletMain->SetMintUnspent(serial))
26652665
LogPrintf("%s: failed to automatically reset mint", __func__);
26662666
}
26672667
}
@@ -2670,18 +2670,19 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex
26702670
}
26712671
}
26722672

2673-
if (tx.HasZerocoinMintOutputs()) {
2674-
//erase all zerocoinmints in this transaction
2675-
for (const CTxOut& txout : tx.vout) {
2676-
if (txout.scriptPubKey.empty() || !txout.IsZerocoinMint())
2677-
continue;
2673+
if (tx.HasZerocoinMintOutputs()) {
2674+
//erase all zerocoinmints in this transaction
2675+
for (const CTxOut &txout : tx.vout) {
2676+
if (txout.scriptPubKey.empty() || !txout.IsZerocoinMint())
2677+
continue;
26782678

2679-
PublicCoin pubCoin(Params().Zerocoin_Params(false));
2680-
if (!TxOutToPublicCoin(txout, pubCoin, state))
2681-
return error("DisconnectBlock(): TxOutToPublicCoin() failed");
2679+
PublicCoin pubCoin(Params().Zerocoin_Params(false));
2680+
if (!TxOutToPublicCoin(txout, pubCoin, state))
2681+
return error("DisconnectBlock(): TxOutToPublicCoin() failed");
26822682

2683-
if(!zerocoinDB->EraseCoinMint(pubCoin.getValue()))
2684-
return error("DisconnectBlock(): Failed to erase coin mint");
2683+
if (!zerocoinDB->EraseCoinMint(pubCoin.getValue()))
2684+
return error("DisconnectBlock(): Failed to erase coin mint");
2685+
}
26852686
}
26862687
}
26872688

src/primitives/transaction.cpp

+10-3
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,16 @@ bool CTransaction::HasZerocoinMintOutputs() const
181181
return false;
182182
}
183183

184+
bool CTransaction::IsZerocoinPublicSpend() const
185+
{
186+
// The wallet only allows publicSpend inputs in the same tx and not a combination between piv and zpiv
187+
for(const CTxIn& txin : vin) {
188+
if (txin.scriptSig.IsZerocoinPublicSpend())
189+
return true;
190+
}
191+
return false;
192+
}
193+
184194
bool CTransaction::IsCoinStake() const
185195
{
186196
if (vin.empty())
@@ -242,9 +252,6 @@ std::list<COutPoint> CTransaction::GetOutPoints() const
242252

243253
CAmount CTransaction::GetZerocoinSpent() const
244254
{
245-
if(!IsZerocoinSpend() && !IsZerocoinPublicSpend())
246-
return 0;
247-
248255
CAmount nValueOut = 0;
249256
for (const CTxIn& txin : vin) {
250257
if(!txin.IsZerocoinSpend() && !txin.scriptSig.IsZerocoinPublicSpend())

src/primitives/transaction.h

+1-10
Original file line numberDiff line numberDiff line change
@@ -268,16 +268,7 @@ class CTransaction
268268
return HasZerocoinSpendInputs() || HasZerocoinMintOutputs();
269269
}
270270

271-
// TODO: Move this to the cpp and add it to the HasZerocoinSpendinputs method
272-
bool IsZerocoinPublicSpend() const
273-
{
274-
// The wallet only allows publicSpend inputs in the same tx and not a combination between piv and zpiv
275-
for(const CTxIn& txin : vin) {
276-
if (txin.scriptSig.IsZerocoinPublicSpend())
277-
return true;
278-
}
279-
return false;
280-
}
271+
bool IsZerocoinPublicSpend() const;
281272

282273
CAmount GetZerocoinMinted() const;
283274
CAmount GetZerocoinSpent() const;

src/zpiv/zpivmodule.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,21 @@ class PublicCoinSpend : public libzerocoin::CoinSpend{
2929
this->coinSerialNumber = serial;
3030
this->randomness = randomness;
3131
this->pubkey = pubkey;
32+
this->spendType = libzerocoin::SpendType::SPEND;
3233
};
3334

3435
template <typename Stream>
3536
PublicCoinSpend(
3637
libzerocoin::ZerocoinParams* params,
3738
Stream& strm):pubCoin(params){
3839
strm >> *this;
40+
this->spendType = libzerocoin::SpendType::SPEND;
3941
}
4042

4143
uint8_t getVersion() const { return libzerocoin::PrivateCoin::PUBKEY_VERSION; }
4244

4345
const uint256 signatureHash() const override;
4446
void setVchSig(std::vector<unsigned char> vchSig) { this->vchSig = vchSig; };
45-
libzerocoin::SpendType getSpendType() const { return libzerocoin::SpendType::SPEND; }
4647
bool Verify(const libzerocoin::Accumulator& a, bool verifyParams = true) const override;
4748
bool validate() const;
4849

0 commit comments

Comments
 (0)