Skip to content

Commit 9a0b734

Browse files
committed
[Wallet/RPC] Add argument to mint zerocoin from specific UTXO
1 parent d2b0172 commit 9a0b734

File tree

4 files changed

+67
-5
lines changed

4 files changed

+67
-5
lines changed

src/rpcclient.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ static const CRPCConvertParam vRPCConvertParams[] =
125125
{"listspentzerocoins", 0},
126126
{"listzerocoinamounts", 0},
127127
{"mintzerocoin", 0},
128+
{"mintzerocoin", 1},
128129
{"spendzerocoin", 0},
129130
{"spendzerocoin", 1},
130131
{"spendzerocoin", 2},

src/rpcwallet.cpp

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2481,16 +2481,31 @@ UniValue listspentzerocoins(const UniValue& params, bool fHelp)
24812481

24822482
UniValue mintzerocoin(const UniValue& params, bool fHelp)
24832483
{
2484-
if (fHelp || params.size() != 1)
2484+
if (fHelp || params.size() < 1 || params.size() > 2)
24852485
throw runtime_error(
2486-
"mintzerocoin <amount>\n"
2487-
"Usage: Enter an amount of Piv to convert to zPiv"
2486+
"mintzerocoin <amount> [UTXOs]\n"
2487+
"amount: Enter an amount of Piv to convert to zPiv\n"
2488+
"UTXOs: (string, optional) A json array of objects. Each object the txid (string) vout (numeric)\n"
2489+
" [ (json array of json objects)\n"
2490+
" {\n"
2491+
" \"txid\":\"id\", (string) The transaction id\n"
2492+
" \"vout\": n (numeric) The output number\n"
2493+
" }\n"
2494+
" ,...\n"
2495+
" ]\n"
24882496
+ HelpRequiringPassphrase());
24892497

24902498
LOCK2(cs_main, pwalletMain->cs_wallet);
24912499

2492-
int64_t nTime = GetTimeMillis();
2500+
if (params.size() == 1)
2501+
{
2502+
RPCTypeCheck(params, boost::assign::list_of(UniValue::VNUM));
2503+
} else
2504+
{
2505+
RPCTypeCheck(params, boost::assign::list_of(UniValue::VNUM)(UniValue::VARR));
2506+
}
24932507

2508+
int64_t nTime = GetTimeMillis();
24942509
if(GetAdjustedTime() > GetSporkValue(SPORK_16_ZEROCOIN_MAINTENANCE_MODE))
24952510
throw JSONRPCError(RPC_WALLET_ERROR, "zPIV is currently disabled due to maintenance.");
24962511

@@ -2501,7 +2516,36 @@ UniValue mintzerocoin(const UniValue& params, bool fHelp)
25012516

25022517
CWalletTx wtx;
25032518
vector<CZerocoinMint> vMints;
2504-
string strError = pwalletMain->MintZerocoin(nAmount, wtx, vMints);
2519+
string strError;
2520+
vector<COutPoint> vOutpts;
2521+
2522+
if (params.size() == 2)
2523+
{
2524+
UniValue outputs = params[1].get_array();
2525+
for (unsigned int idx = 0; idx < outputs.size(); idx++) {
2526+
const UniValue& output = outputs[idx];
2527+
if (!output.isObject())
2528+
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, expected object");
2529+
const UniValue& o = output.get_obj();
2530+
2531+
RPCTypeCheckObj(o, boost::assign::map_list_of("txid", UniValue::VSTR)("vout", UniValue::VNUM));
2532+
2533+
string txid = find_value(o, "txid").get_str();
2534+
if (!IsHex(txid))
2535+
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, expected hex txid");
2536+
2537+
int nOutput = find_value(o, "vout").get_int();
2538+
if (nOutput < 0)
2539+
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, vout must be positive");
2540+
2541+
COutPoint outpt(uint256(txid), nOutput);
2542+
vOutpts.push_back(outpt);
2543+
}
2544+
strError = pwalletMain->MintZerocoinFromOutPoint(nAmount, wtx, vMints, vOutpts);
2545+
} else
2546+
{
2547+
strError = pwalletMain->MintZerocoin(nAmount, wtx, vMints);
2548+
}
25052549

25062550
if (strError != "")
25072551
throw JSONRPCError(RPC_WALLET_ERROR, strError);

src/wallet.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4906,6 +4906,22 @@ void CWallet::ZPivBackupWallet()
49064906
BackupWallet(*this, backupPath.string());
49074907
}
49084908

4909+
string CWallet::MintZerocoinFromOutPoint(CAmount nValue, CWalletTx& wtxNew, vector<CZerocoinMint>& vMints, const vector<COutPoint> vOutpts)
4910+
{
4911+
CCoinControl* coinControl = new CCoinControl();
4912+
for (const COutPoint& outpt : vOutpts) {
4913+
coinControl->Select(outpt);
4914+
}
4915+
if (!coinControl->HasSelected()){
4916+
string strError = _("Error: No valid utxo!");
4917+
LogPrintf("MintZerocoin() : %s", strError.c_str());
4918+
return strError;
4919+
}
4920+
string strError = MintZerocoin(nValue, wtxNew, vMints, coinControl);
4921+
delete coinControl;
4922+
return strError;
4923+
}
4924+
49094925
string CWallet::MintZerocoin(CAmount nValue, CWalletTx& wtxNew, vector<CZerocoinMint>& vMints, const CCoinControl* coinControl)
49104926
{
49114927
// Check amount

src/wallet.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
202202
bool CreateZerocoinMintTransaction(const CAmount nValue, CMutableTransaction& txNew, vector<CZerocoinMint>& vMints, CReserveKey* reservekey, int64_t& nFeeRet, std::string& strFailReason, const CCoinControl* coinControl = NULL, const bool isZCSpendChange = false);
203203
bool CreateZerocoinSpendTransaction(CAmount nValue, int nSecurityLevel, CWalletTx& wtxNew, CReserveKey& reserveKey, CZerocoinSpendReceipt& receipt, vector<CZerocoinMint>& vSelectedMints, vector<CZerocoinMint>& vNewMints, bool fMintChange, bool fMinimizeChange, CBitcoinAddress* address = NULL);
204204
bool MintToTxIn(CZerocoinMint zerocoinSelected, int nSecurityLevel, const uint256& hashTxOut, CTxIn& newTxIn, CZerocoinSpendReceipt& receipt);
205+
std::string MintZerocoinFromOutPoint(CAmount nValue, CWalletTx& wtxNew, vector<CZerocoinMint>& vMints, const vector<COutPoint> vOutpts);
205206
std::string MintZerocoin(CAmount nValue, CWalletTx& wtxNew, vector<CZerocoinMint>& vMints, const CCoinControl* coinControl = NULL);
206207
bool SpendZerocoin(CAmount nValue, int nSecurityLevel, CWalletTx& wtxNew, CZerocoinSpendReceipt& receipt, vector<CZerocoinMint>& vMintsSelected, bool fMintChange, bool fMinimizeChange, CBitcoinAddress* addressTo = NULL);
207208
std::string ResetMintZerocoin(bool fExtendedSearch);

0 commit comments

Comments
 (0)