@@ -172,8 +172,9 @@ static std::vector<RPCArg> CreateTxDoc()
172
172
};
173
173
}
174
174
175
- // Update PSBT with information from the mempool, the UTXO set, the txindex, and the provided descriptors
176
- PartiallySignedTransaction ProcessPSBT (const std::string& psbt_string, const std::any& context, const HidingSigningProvider& provider)
175
+ // Update PSBT with information from the mempool, the UTXO set, the txindex, and the provided descriptors.
176
+ // Optionally, sign the inputs that we can using information from the descriptors.
177
+ PartiallySignedTransaction ProcessPSBT (const std::string& psbt_string, const std::any& context, const HidingSigningProvider& provider, int sighash_type, bool finalize)
177
178
{
178
179
// Unserialize the transactions
179
180
PartiallySignedTransaction psbtx;
@@ -242,9 +243,10 @@ PartiallySignedTransaction ProcessPSBT(const std::string& psbt_string, const std
242
243
}
243
244
244
245
// Update script/keypath information using descriptor data.
245
- // Note that SignPSBTInput does a lot more than just constructing ECDSA signatures
246
- // we don't actually care about those here, in fact.
247
- SignPSBTInput (provider, psbtx, /* index=*/ i, &txdata, /* sighash=*/ 1 );
246
+ // Note that SignPSBTInput does a lot more than just constructing ECDSA signatures.
247
+ // We only actually care about those if our signing provider doesn't hide private
248
+ // information, as is the case with `descriptorprocesspsbt`
249
+ SignPSBTInput (provider, psbtx, /* index=*/ i, &txdata, sighash_type, /* out_sigdata=*/ nullptr , finalize);
248
250
}
249
251
250
252
// Update script/keypath information using descriptor data.
@@ -1697,7 +1699,9 @@ static RPCHelpMan utxoupdatepsbt()
1697
1699
const PartiallySignedTransaction& psbtx = ProcessPSBT (
1698
1700
request.params [0 ].get_str (),
1699
1701
request.context ,
1700
- HidingSigningProvider (&provider, /* hide_secret=*/ true , /* hide_origin=*/ false ));
1702
+ HidingSigningProvider (&provider, /* hide_secret=*/ true , /* hide_origin=*/ false ),
1703
+ /* sighash_type=*/ SIGHASH_ALL,
1704
+ /* finalize=*/ false );
1701
1705
1702
1706
CDataStream ssTx (SER_NETWORK, PROTOCOL_VERSION);
1703
1707
ssTx << psbtx;
@@ -1916,6 +1920,82 @@ static RPCHelpMan analyzepsbt()
1916
1920
};
1917
1921
}
1918
1922
1923
+ RPCHelpMan descriptorprocesspsbt ()
1924
+ {
1925
+ return RPCHelpMan{" descriptorprocesspsbt" ,
1926
+ " \n Update all segwit inputs in a PSBT with information from output descriptors, the UTXO set or the mempool. \n "
1927
+ " Then, sign the inputs we are able to with information from the output descriptors. " ,
1928
+ {
1929
+ {" psbt" , RPCArg::Type::STR, RPCArg::Optional::NO, " The transaction base64 string" },
1930
+ {" descriptors" , RPCArg::Type::ARR, RPCArg::Optional::NO, " An array of either strings or objects" , {
1931
+ {" " , RPCArg::Type::STR, RPCArg::Optional::OMITTED, " An output descriptor" },
1932
+ {" " , RPCArg::Type::OBJ, RPCArg::Optional::OMITTED, " An object with an output descriptor and extra information" , {
1933
+ {" desc" , RPCArg::Type::STR, RPCArg::Optional::NO, " An output descriptor" },
1934
+ {" range" , RPCArg::Type::RANGE, RPCArg::Default{1000 }, " Up to what index HD chains should be explored (either end or [begin,end])" },
1935
+ }},
1936
+ }},
1937
+ {" sighashtype" , RPCArg::Type::STR, RPCArg::Default{" DEFAULT for Taproot, ALL otherwise" }, " The signature hash type to sign with if not specified by the PSBT. Must be one of\n "
1938
+ " \" DEFAULT\"\n "
1939
+ " \" ALL\"\n "
1940
+ " \" NONE\"\n "
1941
+ " \" SINGLE\"\n "
1942
+ " \" ALL|ANYONECANPAY\"\n "
1943
+ " \" NONE|ANYONECANPAY\"\n "
1944
+ " \" SINGLE|ANYONECANPAY\" " },
1945
+ {" bip32derivs" , RPCArg::Type::BOOL, RPCArg::Default{true }, " Include BIP 32 derivation paths for public keys if we know them" },
1946
+ {" finalize" , RPCArg::Type::BOOL, RPCArg::Default{true }, " Also finalize inputs if possible" },
1947
+ },
1948
+ RPCResult{
1949
+ RPCResult::Type::OBJ, " " , " " ,
1950
+ {
1951
+ {RPCResult::Type::STR, " psbt" , " The base64-encoded partially signed transaction" },
1952
+ {RPCResult::Type::BOOL, " complete" , " If the transaction has a complete set of signatures" },
1953
+ }
1954
+ },
1955
+ RPCExamples{
1956
+ HelpExampleCli (" descriptorprocesspsbt" , " \" psbt\" \" [\\\" descriptor1\\\" , \\\" descriptor2\\\" ]\" " ) +
1957
+ HelpExampleCli (" descriptorprocesspsbt" , " \" psbt\" \" [{\\\" desc\\\" :\\\" mydescriptor\\\" , \\\" range\\\" :21}]\" " )
1958
+ },
1959
+ [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
1960
+ {
1961
+ // Add descriptor information to a signing provider
1962
+ FlatSigningProvider provider;
1963
+
1964
+ auto descs = request.params [1 ].get_array ();
1965
+ for (size_t i = 0 ; i < descs.size (); ++i) {
1966
+ EvalDescriptorStringOrObject (descs[i], provider, /* expand_priv=*/ true );
1967
+ }
1968
+
1969
+ int sighash_type = ParseSighashString (request.params [2 ]);
1970
+ bool bip32derivs = request.params [3 ].isNull () ? true : request.params [3 ].get_bool ();
1971
+ bool finalize = request.params [4 ].isNull () ? true : request.params [4 ].get_bool ();
1972
+
1973
+ const PartiallySignedTransaction& psbtx = ProcessPSBT (
1974
+ request.params [0 ].get_str (),
1975
+ request.context ,
1976
+ HidingSigningProvider (&provider, /* hide_secret=*/ false , !bip32derivs),
1977
+ sighash_type,
1978
+ finalize);
1979
+
1980
+ // Check whether or not all of the inputs are now signed
1981
+ bool complete = true ;
1982
+ for (const auto & input : psbtx.inputs ) {
1983
+ complete &= PSBTInputSigned (input);
1984
+ }
1985
+
1986
+ CDataStream ssTx (SER_NETWORK, PROTOCOL_VERSION);
1987
+ ssTx << psbtx;
1988
+
1989
+ UniValue result (UniValue::VOBJ);
1990
+
1991
+ result.pushKV (" psbt" , EncodeBase64 (ssTx));
1992
+ result.pushKV (" complete" , complete);
1993
+
1994
+ return result;
1995
+ },
1996
+ };
1997
+ }
1998
+
1919
1999
void RegisterRawTransactionRPCCommands (CRPCTable& t)
1920
2000
{
1921
2001
static const CRPCCommand commands[]{
@@ -1931,6 +2011,7 @@ void RegisterRawTransactionRPCCommands(CRPCTable& t)
1931
2011
{" rawtransactions" , &createpsbt},
1932
2012
{" rawtransactions" , &converttopsbt},
1933
2013
{" rawtransactions" , &utxoupdatepsbt},
2014
+ {" rawtransactions" , &descriptorprocesspsbt},
1934
2015
{" rawtransactions" , &joinpsbts},
1935
2016
{" rawtransactions" , &analyzepsbt},
1936
2017
};
0 commit comments