Skip to content

Commit

Permalink
[RPC][Cleanup] Remove zerocoin RPC functions
Browse files Browse the repository at this point in the history
  • Loading branch information
random-zebra committed Dec 2, 2020
1 parent 0805834 commit ad7a532
Show file tree
Hide file tree
Showing 11 changed files with 5 additions and 1,558 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,6 @@ set(WALLET_SOURCES
./src/zpiv/zerocoin.cpp
./src/wallet/scriptpubkeyman.cpp
./src/wallet/rpcwallet.cpp
./src/wallet/rpczpiv.cpp
./src/kernel.cpp
./src/legacy/stakemodifier.cpp
./src/wallet/wallet.cpp
Expand Down
1 change: 0 additions & 1 deletion src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,6 @@ libbitcoin_wallet_a_SOURCES = \
wallet/db.cpp \
wallet/rpcdump.cpp \
wallet/rpcwallet.cpp \
wallet/rpczpiv.cpp \
wallet/hdchain.cpp \
wallet/scriptpubkeyman.cpp \
destination_io.cpp \
Expand Down
2 changes: 0 additions & 2 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1083,8 +1083,6 @@ bool AppInit2()
} else {
// Register wallet RPC commands
RegisterWalletRPCCommands(tableRPC);
// Register zPIV RPC commands
RegisterZPIVRPCCommands(tableRPC);
}
#endif

Expand Down
163 changes: 3 additions & 160 deletions src/rpc/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1249,40 +1249,6 @@ UniValue reconsiderblock(const JSONRPCRequest& request)
return NullUniValue;
}

UniValue findserial(const JSONRPCRequest& request)
{
if(request.fHelp || request.params.size() != 1)
throw std::runtime_error(
"findserial \"serial\"\n"
"\nSearches the zerocoin database for a zerocoin spend transaction that contains the specified serial\n"

"\nArguments:\n"
"1. serial (string, required) the serial of a zerocoin spend to search for.\n"

"\nResult:\n"
"{\n"
" \"success\": true|false (boolean) Whether the serial was found\n"
" \"txid\": \"xxx\" (string) The transaction that contains the spent serial\n"
"}\n"

"\nExamples:\n" +
HelpExampleCli("findserial", "\"serial\"") + HelpExampleRpc("findserial", "\"serial\""));

std::string strSerial = request.params[0].get_str();
CBigNum bnSerial = 0;
bnSerial.SetHex(strSerial);
if (!bnSerial)
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid serial");

uint256 txid;
bool fSuccess = zerocoinDB->ReadCoinSpend(bnSerial, txid);

UniValue ret(UniValue::VOBJ);
ret.pushKV("success", fSuccess);
ret.pushKV("txid", txid.GetHex());
return ret;
}

void validaterange(const UniValue& params, int& heightStart, int& heightEnd, int minHeightStart = 1)
{
if (params.size() < 2) {
Expand Down Expand Up @@ -1316,124 +1282,6 @@ void validaterange(const UniValue& params, int& heightStart, int& heightEnd, int
}
}

UniValue getserials(const JSONRPCRequest& request) {
if (request.fHelp || request.params.size() < 2 || request.params.size() > 3)
throw std::runtime_error(
"getserials height range ( fVerbose )\n"
"\nLook the inputs of any tx in a range of blocks and returns the serial numbers for any coinspend.\n"

"\nArguments:\n"
"1. starting_height (numeric, required) the height of the first block to check\n"
"2. range (numeric, required) the amount of blocks to check\n"
"3. fVerbose (boolean, optional, default=False) return verbose output\n"

"\nExamples:\n" +
HelpExampleCli("getserials", "1254000 1000") +
HelpExampleRpc("getserials", "1254000, 1000"));

int heightStart, heightEnd;
const int heightMax = Params().GetConsensus().vUpgrades[Consensus::UPGRADE_ZC].nActivationHeight;
validaterange(request.params, heightStart, heightEnd, heightMax);

bool fVerbose = false;
if (request.params.size() > 2) {
fVerbose = request.params[2].get_bool();
}

CBlockIndex* pblockindex = nullptr;
{
LOCK(cs_main);
pblockindex = chainActive[heightStart];
}

if (!pblockindex)
throw JSONRPCError(RPC_INVALID_PARAMETER, "invalid block height");

UniValue serialsObj(UniValue::VOBJ); // for fVerbose
UniValue serialsArr(UniValue::VARR);

while (true) {
CBlock block;
if (!ReadBlockFromDisk(block, pblockindex))
throw JSONRPCError(RPC_INTERNAL_ERROR, "Can't read block from disk");

// loop through each tx in the block
for (const auto& txIn : block.vtx) {
const CTransaction& tx = *txIn;
std::string txid = tx.GetHash().GetHex();
// collect the destination (first output) if fVerbose
std::string spentTo = "";
if (fVerbose) {
if (tx.vout[0].IsZerocoinMint()) {
spentTo = "Zerocoin Mint";
} else if (tx.vout[0].IsEmpty()) {
spentTo = "Zerocoin Stake";
} else {
txnouttype type;
std::vector<CTxDestination> addresses;
int nRequired;
if (!ExtractDestinations(tx.vout[0].scriptPubKey, type, addresses, nRequired)) {
spentTo = strprintf("type: %d", GetTxnOutputType(type));
} else {
spentTo = EncodeDestination(addresses[0]);
}
}
}
// loop through each input
for (const CTxIn& txin : tx.vin) {
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().GetConsensus().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 {
UniValue s(UniValue::VOBJ);
s.pushKV("serial", serial_str);
s.pushKV("denom", denom);
s.pushKV("bitsize", (int)serial_str.size()*4);
s.pushKV("spentTo", spentTo);
s.pushKV("txid", txid);
s.pushKV("blocknum", pblockindex->nHeight);
s.pushKV("blocktime", block.GetBlockTime());
serialsArr.push_back(s);
}
}

} // end for vin in tx
} // end for tx in block

if (pblockindex->nHeight < heightEnd) {
LOCK(cs_main);
pblockindex = chainActive.Next(pblockindex);
} else {
break;
}

} // end for blocks

return serialsArr;

}

UniValue getblockindexstats(const JSONRPCRequest& request) {
if (request.fHelp || request.params.size() < 2 || request.params.size() > 3)
throw std::runtime_error(
Expand Down Expand Up @@ -1462,9 +1310,9 @@ UniValue getblockindexstats(const JSONRPCRequest& request) {
" \"denom_5\": xxxx (numeric) number of PUBLIC spends of denom_5 occurred over the block range\n"
" ... ... number of PUBLIC spends of other denominations: ..., 10, 50, 100, 500, 1000, 5000\n"
" }\n"
" \"txbytes\": xxxxx (numeric) Sum of the size of all txes (zPIV excluded) over block range\n"
" \"ttlfee\": xxxxx (numeric) Sum of the fee amount of all txes (zPIV mints excluded) over block range\n"
" \"ttlfee_all\": xxxxx (numeric) Sum of the fee amount of all txes (zPIV mints included) over block range\n"
" \"txbytes\": xxxxx (numeric) Sum of the size of all txes over block range\n"
" \"ttlfee\": xxxxx (numeric) Sum of the fee amount of all txes over block range\n"
" \"ttlfee_all\": xxxxx (numeric) Sum of the fee amount of all txes over block range\n"
" \"feeperkb\": xxxxx (numeric) Average fee per kb (excluding zc txes)\n"
"}\n"

Expand Down Expand Up @@ -1666,11 +1514,6 @@ static const CRPCCommand commands[] =
{ "hidden", "waitforblock", &waitforblock, true },
{ "hidden", "waitforblockheight", &waitforblockheight, true },

// TODO: Remove these two RPC commands after 5.0 is locked in
/* Zerocoin functions to be removed post-5.0 */
{ "zerocoin", "findserial", &findserial, true },
{ "zerocoin", "getserials", &getserials, true },


};

Expand Down
22 changes: 0 additions & 22 deletions src/rpc/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,28 +149,6 @@ static const CRPCConvertParam vRPCConvertParams[] = {
{ "setstakesplitthreshold", 0 },
{ "autocombinerewards", 0 },
{ "autocombinerewards", 1 },
{ "getzerocoinbalance", 0 },
{ "listmintedzerocoins", 0 },
{ "listmintedzerocoins", 1 },
{ "listspentzerocoins", 0 },
{ "listzerocoinamounts", 0 },
{ "mintzerocoin", 0 },
{ "mintzerocoin", 1 },
{ "spendzerocoin", 0 },
{ "spendrawzerocoin", 2 },
{ "spendzerocoinmints", 0 },
{ "importzerocoins", 0 },
{ "exportzerocoins", 0 },
{ "exportzerocoins", 1 },
{ "resetmintzerocoin", 0 },
{ "getspentzerocoinamount", 1 },
{ "generatemintlist", 0 },
{ "generatemintlist", 1 },
{ "searchdzpiv", 0 },
{ "searchdzpiv", 1 },
{ "searchdzpiv", 2 },
{ "getmintsvalues", 2 },
{ "enableautomintaddress", 0 },
{ "getblockindexstats", 0 },
{ "getblockindexstats", 1 },
{ "getblockindexstats", 2 },
Expand Down
114 changes: 0 additions & 114 deletions src/rpc/rawtransaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@
#include "net.h"
#include "policy/policy.h"
#include "primitives/transaction.h"
#include "zpiv/deterministicmint.h"
#include "rpc/server.h"
#include "script/script.h"
#include "script/script_error.h"
#include "script/sign.h"
#include "script/standard.h"
#include "uint256.h"
#include "utilmoneystr.h"
#include "zpivchain.h"
#ifdef ENABLE_WALLET
#include "sapling/key_io_sapling.h"
#include "sapling/address.hpp"
Expand Down Expand Up @@ -901,113 +899,6 @@ UniValue sendrawtransaction(const JSONRPCRequest& request)
return hashTx.GetHex();
}

UniValue getspentzerocoinamount(const JSONRPCRequest& request)
{
if (request.fHelp || request.params.size() != 2)
throw std::runtime_error(
"getspentzerocoinamount hexstring index\n"
"\nReturns value of spent zerocoin output designated by transaction hash and input index.\n"

"\nArguments:\n"
"1. hash (hexstring) Transaction hash\n"
"2. index (int) Input index\n"

"\nResult:\n"
"\"value\" (int) Spent output value, -1 if error\n"

"\nExamples:\n" +
HelpExampleCli("getspentzerocoinamount", "78021ebf92a80dfccef1413067f1222e37535399797cce029bb40ad981131706 0"));

LOCK(cs_main);

uint256 txHash = ParseHashV(request.params[0], "parameter 1");
int inputIndex = request.params[1].get_int();
if (inputIndex < 0)
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter for transaction input");

CTransaction tx;
uint256 hashBlock = UINT256_ZERO;
if (!GetTransaction(txHash, tx, hashBlock, true))
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "No information available about transaction");

if (inputIndex >= (int)tx.vin.size())
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter for transaction input");

const CTxIn& input = tx.vin[inputIndex];
if (!input.IsZerocoinSpend())
return -1;

libzerocoin::CoinSpend spend = TxInToZerocoinSpend(input);
CAmount nValue = libzerocoin::ZerocoinDenominationToAmount(spend.getDenomination());
return FormatMoney(nValue);
}

#ifdef ENABLE_WALLET

UniValue createrawzerocoinspend(const JSONRPCRequest& request)
{
if (request.fHelp || request.params.size() < 1 || request.params.size() > 3)
throw std::runtime_error(
"createrawzerocoinspend mint_input ( \"address\" )\n"
"\nCreates raw zPIV public spend.\n" +
HelpRequiringPassphrase() + "\n"

"\nArguments:\n"
"1. mint_input (hex string, required) serial hash of the mint used as input\n"
"2. \"address\" (string, optional, default=change) Send to specified address or to a new change address.\n"


"\nResult:\n"
"{\n"
" \"hex\": \"xxx\", (hex string) raw public spend signed transaction\n"
"}\n"
"\nExamples\n" +
HelpExampleCli("createrawzerocoinspend", "0d8c16eee7737e3cc1e4e70dc006634182b175e039700931283b202715a0818f") +
HelpExampleRpc("createrawzerocoinspend", "0d8c16eee7737e3cc1e4e70dc006634182b175e039700931283b202715a0818f"));

const std::string serial_hash = request.params[0].get_str();
const std::string address_str = (request.params.size() > 1 ? request.params[1].get_str() : "");

if (!IsHex(serial_hash))
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, expected hex serial hash");

CTxDestination dest{CNoDestination()};
if (address_str != "") {
dest = DecodeDestination(address_str);
if(!IsValidDestination(dest))
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid PIVX address");
}

assert(pwalletMain != NULL);
EnsureWalletIsUnlocked();
LOCK2(cs_main, pwalletMain->cs_wallet);

uint256 hashSerial(uint256S(serial_hash));
CZerocoinMint input_mint;
if (!pwalletMain->GetMint(hashSerial, input_mint)) {
std::string strErr = "Failed to fetch mint associated with serial hash " + serial_hash;
throw JSONRPCError(RPC_WALLET_ERROR, strErr);
}
CAmount nAmount = input_mint.GetDenominationAsAmount();
std::vector<CZerocoinMint> vMintsSelected = std::vector<CZerocoinMint>(1,input_mint);

// create the spend
CWalletTx rawTx;
CZerocoinSpendReceipt receipt;
CReserveKey reserveKey(pwalletMain);
std::vector<CDeterministicMint> vNewMints;
std::list<std::pair<CTxDestination, CAmount>> outputs;
if (IsValidDestination(dest)) {
outputs.push_back(std::pair<CTxDestination, CAmount>(dest, nAmount));
}
if (!pwalletMain->CreateZCPublicSpendTransaction(nAmount, rawTx, reserveKey, receipt, vMintsSelected, vNewMints, outputs, nullptr))
throw JSONRPCError(RPC_WALLET_ERROR, receipt.GetStatusMessage());

// output the raw transaction
return EncodeHexTx(rawTx);
}
#endif

static const CRPCCommand commands[] =
{ // category name actor (function) okSafeMode
// --------------------- ------------------------ ----------------------- ----------
Expand All @@ -1018,11 +909,6 @@ static const CRPCCommand commands[] =
{ "rawtransactions", "fundrawtransaction", &fundrawtransaction, false },
{ "rawtransactions", "signrawtransaction", &signrawtransaction, false }, /* uses wallet if enabled */
{ "rawtransactions", "sendrawtransaction", &sendrawtransaction, false },

{ "zerocoin", "getspentzerocoinamount", &getspentzerocoinamount, false },
#ifdef ENABLE_WALLET
{ "zerocoin", "createrawzerocoinspend", &createrawzerocoinspend, false },
#endif // ENABLE_WALLET
};

void RegisterRawTransactionRPCCommands(CRPCTable &tableRPC)
Expand Down
1 change: 0 additions & 1 deletion src/rpc/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#define BITCOIN_RPCSERVER_H

#include "amount.h"
#include "zpiv/zerocoin.h"
#include "rpc/protocol.h"
#include "uint256.h"

Expand Down
Loading

0 comments on commit ad7a532

Please sign in to comment.