Skip to content

Commit

Permalink
[RPC] Parse public spend on getserials rpc command.
Browse files Browse the repository at this point in the history
[Cleanup] non used variable commented.
  • Loading branch information
furszy committed Jun 4, 2019
1 parent 88cdfc6 commit afdb9d4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
10 changes: 6 additions & 4 deletions src/qt/privacydialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
29 changes: 23 additions & 6 deletions src/rpc/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "zpiv/accumulatormap.h"
#include "zpiv/accumulators.h"
#include "wallet/wallet.h"
#include "zpiv/zpivmodule.h"
#include "zpivchain.h"

#include <stdint.h>
Expand Down Expand Up @@ -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));
Expand All @@ -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
Expand Down

0 comments on commit afdb9d4

Please sign in to comment.