Skip to content

Commit afdb9d4

Browse files
committed
[RPC] Parse public spend on getserials rpc command.
[Cleanup] non used variable commented.
1 parent 88cdfc6 commit afdb9d4

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

src/qt/privacydialog.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -440,17 +440,19 @@ void PrivacyDialog::sendzPIV()
440440

441441
// Display errors during spend
442442
if (!fSuccess) {
443+
/*
443444
int nNeededSpends = receipt.GetNeededSpends(); // Number of spends we would need for this transaction
444-
/*const int nMaxSpends = Params().Zerocoin_MaxSpendsPerTransaction(); // Maximum possible spends for one zPIV transaction
445+
const int nMaxSpends = Params().Zerocoin_MaxSpendsPerTransaction(); // Maximum possible spends for one zPIV transaction
445446
if (nNeededSpends > nMaxSpends) {
446447
QString strStatusMessage = tr("Too much inputs (") + QString::number(nNeededSpends, 10) + tr(") needed.\nMaximum allowed: ") + QString::number(nMaxSpends, 10);
447448
strStatusMessage += tr("\nEither mint higher denominations (so fewer inputs are needed) or reduce the amount to spend.");
448449
QMessageBox::warning(this, tr("Spend Zerocoin"), strStatusMessage.toStdString().c_str(), QMessageBox::Ok, QMessageBox::Ok);
449450
ui->TEMintStatus->setPlainText(tr("Spend Zerocoin failed with status = ") +QString::number(receipt.GetStatus(), 10) + "\n" + "Message: " + QString::fromStdString(strStatusMessage.toStdString()));
450451
}
451-
else {*/
452-
QMessageBox::warning(this, tr("Spend Zerocoin"), receipt.GetStatusMessage().c_str(), QMessageBox::Ok, QMessageBox::Ok);
453-
ui->TEMintStatus->setPlainText(tr("Spend Zerocoin failed with status = ") +QString::number(receipt.GetStatus(), 10) + "\n" + "Message: " + QString::fromStdString(receipt.GetStatusMessage()));
452+
else {
453+
*/
454+
QMessageBox::warning(this, tr("Spend Zerocoin"), receipt.GetStatusMessage().c_str(), QMessageBox::Ok, QMessageBox::Ok);
455+
ui->TEMintStatus->setPlainText(tr("Spend Zerocoin failed with status = ") +QString::number(receipt.GetStatus(), 10) + "\n" + "Message: " + QString::fromStdString(receipt.GetStatusMessage()));
454456
//}
455457
ui->zPIVpayAmount->setFocus();
456458
ui->TEMintStatus->repaint();

src/rpc/blockchain.cpp

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "zpiv/accumulatormap.h"
1818
#include "zpiv/accumulators.h"
1919
#include "wallet/wallet.h"
20+
#include "zpiv/zpivmodule.h"
2021
#include "zpivchain.h"
2122

2223
#include <stdint.h>
@@ -1446,14 +1447,31 @@ UniValue getserials(const UniValue& params, bool fHelp) {
14461447
}
14471448
// loop through each input
14481449
for (const CTxIn& txin : tx.vin) {
1449-
// TODO: Add public coin spend parse here..
1450-
if (txin.IsZerocoinSpend()) {
1451-
libzerocoin::CoinSpend spend = TxInToZerocoinSpend(txin);
1452-
std::string serial_str = spend.getCoinSerialNumber().ToString(16);
1450+
bool isPublicSpend = txin.IsZerocoinPublicSpend();
1451+
if (txin.IsZerocoinSpend() || isPublicSpend) {
1452+
std::string serial_str;
1453+
int denom;
1454+
if (isPublicSpend) {
1455+
CTxOut prevOut;
1456+
CValidationState state;
1457+
if(!GetOutput(txin.prevout.hash, txin.prevout.n, state, prevOut)){
1458+
throw JSONRPCError(RPC_INTERNAL_ERROR, "public zerocoin spend prev output not found");
1459+
}
1460+
libzerocoin::ZerocoinParams *params = Params().Zerocoin_Params(false);
1461+
PublicCoinSpend publicSpend(params);
1462+
if (!ZPIVModule::parseCoinSpend(txin, tx, prevOut, publicSpend)) {
1463+
throw JSONRPCError(RPC_INTERNAL_ERROR, "public zerocoin spend parse failed");
1464+
}
1465+
serial_str = publicSpend.getCoinSerialNumber().ToString(16);
1466+
denom = libzerocoin::ZerocoinDenominationToInt(publicSpend.getDenomination());
1467+
} else {
1468+
libzerocoin::CoinSpend spend = TxInToZerocoinSpend(txin);
1469+
serial_str = spend.getCoinSerialNumber().ToString(16);
1470+
denom = libzerocoin::ZerocoinDenominationToInt(spend.getDenomination());
1471+
}
14531472
if (!fVerbose) {
14541473
serialsArr.push_back(serial_str);
14551474
} else {
1456-
int denom = libzerocoin::ZerocoinDenominationToInt(spend.getDenomination());
14571475
UniValue s(UniValue::VOBJ);
14581476
s.push_back(Pair("serial", serial_str));
14591477
s.push_back(Pair("denom", denom));
@@ -1464,7 +1482,6 @@ UniValue getserials(const UniValue& params, bool fHelp) {
14641482
s.push_back(Pair("blocktime", block.GetBlockTime()));
14651483
serialsArr.push_back(s);
14661484
}
1467-
14681485
}
14691486

14701487
} // end for vin in tx

0 commit comments

Comments
 (0)