From 8134a6b5d40568dcf32fdb21163cb1792efddc27 Mon Sep 17 00:00:00 2001 From: rkrux Date: Thu, 27 Feb 2025 17:35:34 +0530 Subject: [PATCH 1/3] rpc: add cli example for `walletcreatefundedpsbt` RPC The only example present earlier was one that creates an OP_RETURN output. This lack of examples has discouraged me earlier to use this RPC. Adding an example that creates PSBT sending bitcoin to address, a scenario that is much more common. --- src/wallet/rpc/spend.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/wallet/rpc/spend.cpp b/src/wallet/rpc/spend.cpp index 0cba830e2ab..567ddfcba7b 100644 --- a/src/wallet/rpc/spend.cpp +++ b/src/wallet/rpc/spend.cpp @@ -1729,8 +1729,10 @@ RPCHelpMan walletcreatefundedpsbt() } }, RPCExamples{ - "\nCreate a transaction with no inputs\n" - + HelpExampleCli("walletcreatefundedpsbt", "\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\" \"[{\\\"data\\\":\\\"00010203\\\"}]\"") + "\nCreate a PSBT with automatically picked inputs that sends 0.5 BTC to an address and has a fee rate of 2 sat/vB:\n" + + HelpExampleCli("walletcreatefundedpsbt", "\"[]\" \"[{\\\"" + EXAMPLE_ADDRESS[0] + "\\\":0.5}]\" 0 \"{\\\"add_inputs\\\":true,\\\"fee_rate\\\":2}\"") + + "\nCreate the same PSBT as the above one instead using named arguments:\n" + + HelpExampleCli("-named walletcreatefundedpsbt", "outputs=\"[{\\\"" + EXAMPLE_ADDRESS[0] + "\\\":0.5}]\" add_inputs=true fee_rate=2") }, [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { From 931117a46f5854d487e13b2b1446b621409c8371 Mon Sep 17 00:00:00 2001 From: rkrux Date: Thu, 27 Feb 2025 17:42:28 +0530 Subject: [PATCH 2/3] rpc: update the doc for `data` field in `outputs` argument This affects docs of the following RPCs: `bumpfee`, `psbtbumpfee`, `send`, `walletcreatefundedpsbt`, `createpsbt`, and `createrawtransaction` It was not evident to me that this field creates an `OP_RETURN` output until I read the code and tried it out. Thus, making the doc explicitly mention it. --- src/rpc/rawtransaction.cpp | 2 +- src/wallet/rpc/spend.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index 421656152cb..fd3aa0d14b8 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -150,7 +150,7 @@ static std::vector CreateTxDoc() }, {"", RPCArg::Type::OBJ, RPCArg::Optional::OMITTED, "", { - {"data", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "A key-value pair. The key must be \"data\", the value is hex-encoded data"}, + {"data", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "A key-value pair. The key must be \"data\", the value is hex-encoded data that becomes a part of an OP_RETURN output"}, }, }, }, diff --git a/src/wallet/rpc/spend.cpp b/src/wallet/rpc/spend.cpp index 567ddfcba7b..595b5f523e4 100644 --- a/src/wallet/rpc/spend.cpp +++ b/src/wallet/rpc/spend.cpp @@ -978,7 +978,7 @@ static std::vector OutputsDoc() }, {"", RPCArg::Type::OBJ, RPCArg::Optional::OMITTED, "", { - {"data", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "A key-value pair. The key must be \"data\", the value is hex-encoded data"}, + {"data", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "A key-value pair. The key must be \"data\", the value is hex-encoded data that becomes a part of an OP_RETURN output"}, }, }, }; From 32dcec269bf33f7be28245d88a1d8f2889cc39ae Mon Sep 17 00:00:00 2001 From: rkrux Date: Wed, 26 Mar 2025 18:49:30 +0530 Subject: [PATCH 3/3] rpc: update RPC help of `createpsbt` Update the example wherein the PSBT sends bitcoin to an address instead of creating an OP_RETURN output. Also, update the RPC description to reflect the fact that the created transaction is unsigned. --- src/rpc/rawtransaction.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index fd3aa0d14b8..7ed45396171 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -1550,13 +1550,15 @@ static RPCHelpMan createpsbt() { return RPCHelpMan{"createpsbt", "\nCreates a transaction in the Partially Signed Transaction format.\n" - "Implements the Creator role.\n", + "Implements the Creator role.\n" + "Note that the transaction's inputs are not signed, and\n" + "it is not stored in the wallet or transmitted to the network.\n", CreateTxDoc(), RPCResult{ RPCResult::Type::STR, "", "The resulting raw transaction (base64-encoded string)" }, RPCExamples{ - HelpExampleCli("createpsbt", "\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\" \"[{\\\"data\\\":\\\"00010203\\\"}]\"") + HelpExampleCli("createpsbt", "\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\" \"[{\\\"address\\\":0.01}]\"") }, [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue {