Skip to content

Commit c5e69bd

Browse files
committed
Hooked up the "walletdeniabilizecoin" to the RPC commands.
Cleaned up the input json parsing.
1 parent 3b4fd01 commit c5e69bd

File tree

3 files changed

+28
-12
lines changed

3 files changed

+28
-12
lines changed

src/rpc/client.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ static const CRPCConvertParam vRPCConvertParams[] =
130130
{ "walletcreatefundedpsbt", 2, "locktime" },
131131
{ "walletcreatefundedpsbt", 3, "options" },
132132
{ "walletcreatefundedpsbt", 4, "bip32derivs" },
133+
{ "walletdeniabilizecoin", 0, "inputs" },
134+
{ "walletdeniabilizecoin", 1, "conf_target" },
135+
{ "walletdeniabilizecoin", 2, "add_to_wallet" },
133136
{ "walletprocesspsbt", 1, "sign" },
134137
{ "walletprocesspsbt", 3, "bip32derivs" },
135138
{ "walletprocesspsbt", 4, "finalize" },

src/wallet/rpc/spend.cpp

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1732,9 +1732,12 @@ RPCHelpMan walletdeniabilizecoin()
17321732
{
17331733
{"inputs", RPCArg::Type::ARR, RPCArg::Optional::NO, "Specify inputs (must share the same address). A JSON array of JSON objects",
17341734
{
1735-
{"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction id"},
1736-
{"vout", RPCArg::Type::NUM, RPCArg::Optional::NO, "The output number"},
1737-
{"sequence", RPCArg::Type::NUM, RPCArg::Optional::NO, "The sequence number"},
1735+
{"", RPCArg::Type::OBJ, RPCArg::Optional::OMITTED, "",
1736+
{
1737+
{"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction id"},
1738+
{"vout", RPCArg::Type::NUM, RPCArg::Optional::NO, "The output number"},
1739+
}
1740+
}
17381741
},
17391742
},
17401743
{"conf_target", RPCArg::Type::NUM, RPCArg::DefaultHint{"wallet -txconfirmtarget"}, "Confirmation target in blocks"},
@@ -1748,24 +1751,29 @@ RPCHelpMan walletdeniabilizecoin()
17481751
{RPCResult::Type::STR_HEX, "hex", /*optional=*/true, "If add_to_wallet is false, the hex-encoded raw transaction with signature(s)"},
17491752
}
17501753
},
1751-
RPCExamples{""
1754+
RPCExamples{
1755+
"\nDeniabilize a single UTXO\n"
1756+
+ HelpExampleCli("walletdeniabilizecoin", "\"[{\"txid\":\"4c14d20709daef476854fe7ef75bdfcfd5a7636a431b4622ec9481f297e12e8c\", \"vout\": 0}]\"")
17521757
},
17531758
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
17541759
{
17551760
std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest(request);
17561761
if (!pwallet) return UniValue::VNULL;
17571762

1758-
CMutableTransaction rawTx;
1759-
AddInputs(rawTx, request.params[0], true);
1760-
1761-
unsigned int confirm_target = !request.params[1].isNull() ? request.params[1].getInt<unsigned int>() : 6;
1762-
const bool add_to_wallet = !request.params[2].isNull() ? request.params[2].get_bool() : true;
1763-
17641763
std::optional<CTxDestination> shared_address;
17651764
std::set<COutPoint> inputs;
17661765
unsigned int deniabilization_cycles = 0;
1767-
for (const auto& txIn: rawTx.vin) {
1768-
const auto& outpoint = txIn.prevout;
1766+
for (const UniValue& input : request.params[0].get_array().getValues()) {
1767+
uint256 txid = ParseHashO(input, "txid");
1768+
1769+
const UniValue& vout_v = input.find_value("vout");
1770+
if (!vout_v.isNum())
1771+
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, missing vout key");
1772+
int nOutput = vout_v.getInt<int>();
1773+
if (nOutput < 0)
1774+
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, vout cannot be negative");
1775+
1776+
COutPoint outpoint(txid, nOutput);
17691777
LOCK(pwallet->cs_wallet);
17701778
auto walletTx = pwallet->GetWalletTx(outpoint.hash);
17711779
if (!walletTx) {
@@ -1797,6 +1805,9 @@ RPCHelpMan walletdeniabilizecoin()
17971805
deniabilization_cycles = std::min(deniabilization_cycles, cycles_res.first);
17981806
}
17991807

1808+
unsigned int confirm_target = !request.params[1].isNull() ? request.params[1].getInt<unsigned int>() : 6;
1809+
const bool add_to_wallet = !request.params[2].isNull() ? request.params[2].get_bool() : true;
1810+
18001811
CTransactionRef tx;
18011812
CAmount tx_fee = 0;
18021813
{

src/wallet/rpc/wallet.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -869,6 +869,7 @@ RPCHelpMan send();
869869
RPCHelpMan sendall();
870870
RPCHelpMan walletprocesspsbt();
871871
RPCHelpMan walletcreatefundedpsbt();
872+
RPCHelpMan walletdeniabilizecoin();
872873
RPCHelpMan signrawtransactionwithwallet();
873874

874875
// signmessage
@@ -956,6 +957,7 @@ Span<const CRPCCommand> GetWalletRPCCommands()
956957
{"wallet", &walletpassphrase},
957958
{"wallet", &walletpassphrasechange},
958959
{"wallet", &walletprocesspsbt},
960+
{"wallet", &walletdeniabilizecoin},
959961
};
960962
return commands;
961963
}

0 commit comments

Comments
 (0)