From afdb9d492c7e666a82b85ebb22fb9416ef61aed2 Mon Sep 17 00:00:00 2001 From: furszy Date: Thu, 16 May 2019 19:08:59 +0200 Subject: [PATCH] [RPC] Parse public spend on getserials rpc command. [Cleanup] non used variable commented. --- src/qt/privacydialog.cpp | 10 ++++++---- src/rpc/blockchain.cpp | 29 +++++++++++++++++++++++------ 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/src/qt/privacydialog.cpp b/src/qt/privacydialog.cpp index 99f8586e6b8d9..63904fa391691 100644 --- a/src/qt/privacydialog.cpp +++ b/src/qt/privacydialog.cpp @@ -440,17 +440,19 @@ void PrivacyDialog::sendzPIV() // Display errors during spend if (!fSuccess) { + /* int nNeededSpends = receipt.GetNeededSpends(); // Number of spends we would need for this transaction - /*const int nMaxSpends = Params().Zerocoin_MaxSpendsPerTransaction(); // Maximum possible spends for one zPIV transaction + const int nMaxSpends = Params().Zerocoin_MaxSpendsPerTransaction(); // Maximum possible spends for one zPIV transaction if (nNeededSpends > nMaxSpends) { QString strStatusMessage = tr("Too much inputs (") + QString::number(nNeededSpends, 10) + tr(") needed.\nMaximum allowed: ") + QString::number(nMaxSpends, 10); strStatusMessage += tr("\nEither mint higher denominations (so fewer inputs are needed) or reduce the amount to spend."); QMessageBox::warning(this, tr("Spend Zerocoin"), strStatusMessage.toStdString().c_str(), QMessageBox::Ok, QMessageBox::Ok); ui->TEMintStatus->setPlainText(tr("Spend Zerocoin failed with status = ") +QString::number(receipt.GetStatus(), 10) + "\n" + "Message: " + QString::fromStdString(strStatusMessage.toStdString())); } - else {*/ - QMessageBox::warning(this, tr("Spend Zerocoin"), receipt.GetStatusMessage().c_str(), QMessageBox::Ok, QMessageBox::Ok); - ui->TEMintStatus->setPlainText(tr("Spend Zerocoin failed with status = ") +QString::number(receipt.GetStatus(), 10) + "\n" + "Message: " + QString::fromStdString(receipt.GetStatusMessage())); + else { + */ + QMessageBox::warning(this, tr("Spend Zerocoin"), receipt.GetStatusMessage().c_str(), QMessageBox::Ok, QMessageBox::Ok); + ui->TEMintStatus->setPlainText(tr("Spend Zerocoin failed with status = ") +QString::number(receipt.GetStatus(), 10) + "\n" + "Message: " + QString::fromStdString(receipt.GetStatusMessage())); //} ui->zPIVpayAmount->setFocus(); ui->TEMintStatus->repaint(); diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index e6290f2a291af..7fe601864fcc6 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -17,6 +17,7 @@ #include "zpiv/accumulatormap.h" #include "zpiv/accumulators.h" #include "wallet/wallet.h" +#include "zpiv/zpivmodule.h" #include "zpivchain.h" #include @@ -1446,14 +1447,31 @@ UniValue getserials(const UniValue& params, bool fHelp) { } // loop through each input for (const CTxIn& txin : tx.vin) { - // TODO: Add public coin spend parse here.. - if (txin.IsZerocoinSpend()) { - libzerocoin::CoinSpend spend = TxInToZerocoinSpend(txin); - std::string serial_str = spend.getCoinSerialNumber().ToString(16); + bool isPublicSpend = txin.IsZerocoinPublicSpend(); + if (txin.IsZerocoinSpend() || isPublicSpend) { + std::string serial_str; + int denom; + if (isPublicSpend) { + CTxOut prevOut; + CValidationState state; + if(!GetOutput(txin.prevout.hash, txin.prevout.n, state, prevOut)){ + throw JSONRPCError(RPC_INTERNAL_ERROR, "public zerocoin spend prev output not found"); + } + libzerocoin::ZerocoinParams *params = Params().Zerocoin_Params(false); + PublicCoinSpend publicSpend(params); + if (!ZPIVModule::parseCoinSpend(txin, tx, prevOut, publicSpend)) { + throw JSONRPCError(RPC_INTERNAL_ERROR, "public zerocoin spend parse failed"); + } + serial_str = publicSpend.getCoinSerialNumber().ToString(16); + denom = libzerocoin::ZerocoinDenominationToInt(publicSpend.getDenomination()); + } else { + libzerocoin::CoinSpend spend = TxInToZerocoinSpend(txin); + serial_str = spend.getCoinSerialNumber().ToString(16); + denom = libzerocoin::ZerocoinDenominationToInt(spend.getDenomination()); + } if (!fVerbose) { serialsArr.push_back(serial_str); } else { - int denom = libzerocoin::ZerocoinDenominationToInt(spend.getDenomination()); UniValue s(UniValue::VOBJ); s.push_back(Pair("serial", serial_str)); s.push_back(Pair("denom", denom)); @@ -1464,7 +1482,6 @@ UniValue getserials(const UniValue& params, bool fHelp) { s.push_back(Pair("blocktime", block.GetBlockTime())); serialsArr.push_back(s); } - } } // end for vin in tx