MCPcopy Create free account
hub / github.com/ElementsProject/elements / joinpsbts

Function joinpsbts

src/rpc/rawtransaction.cpp:2435–2546  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2433}
2434#if 0
2435static RPCHelpMan joinpsbts()
2436{
2437 return RPCHelpMan{"joinpsbts",
2438 "\nJoins multiple distinct PSBTs with different inputs and outputs into one PSBT with inputs and outputs from all of the PSBTs\n"
2439 "No input in any of the PSBTs can be in more than one of the PSBTs.\n",
2440 {
2441 {"txs", RPCArg::Type::ARR, RPCArg::Optional::NO, "The base64 strings of partially signed transactions",
2442 {
2443 {"psbt", RPCArg::Type::STR, RPCArg::Optional::NO, "A base64 string of a PSBT"}
2444 }}
2445 },
2446 RPCResult {
2447 RPCResult::Type::STR, "", "The base64-encoded partially signed transaction"
2448 },
2449 RPCExamples {
2450 HelpExampleCli("joinpsbts", "\"psbt\"")
2451 },
2452 [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
2453{
2454 RPCTypeCheck(request.params, {UniValue::VARR}, true);
2455
2456 // Unserialize the transactions
2457 std::vector<PartiallySignedTransaction> psbtxs;
2458 UniValue txs = request.params[0].get_array();
2459
2460 if (txs.size() <= 1) {
2461 throw JSONRPCError(RPC_INVALID_PARAMETER, "At least two PSBTs are required to join PSBTs.");
2462 }
2463
2464 int32_t best_version = 1;
2465 uint32_t best_locktime = 0xffffffff;
2466 for (unsigned int i = 0; i < txs.size(); ++i) {
2467 PartiallySignedTransaction psbtx;
2468 std::string error;
2469 if (!DecodeBase64PSBT(psbtx, txs[i].get_str(), error)) {
2470 throw JSONRPCError(RPC_DESERIALIZATION_ERROR, strprintf("TX decode failed %s", error));
2471 }
2472 if (psbtx.GetVersion() != 0) {
2473 throw JSONRPCError(RPC_INVALID_PARAMETER, "joinpsbts only operates on version 0 PSBTs");
2474 }
2475 psbtxs.push_back(psbtx);
2476 // Choose the highest version number
2477 if (*psbtx.tx_version > best_version) {
2478 best_version = *psbtx.tx_version;
2479 best_version = static_cast<uint32_t>(psbtx.tx->nVersion);
2480 }
2481 // Choose the lowest lock time
2482 if (*psbtx.fallback_locktime < best_locktime) {
2483 best_locktime = *psbtx.fallback_locktime;
2484 }
2485 }
2486
2487 // Create a blank psbt where everything will be added
2488 PartiallySignedTransaction merged_psbt;
2489 merged_psbt.tx_version = best_version;
2490 merged_psbt.fallback_locktime = best_locktime;
2491 // TODO: Remove for PSBTv2
2492 merged_psbt.tx = CMutableTransaction();

Callers

nothing calls this directly

Calls 15

HelpExampleCliFunction · 0.85
RPCTypeCheckFunction · 0.85
JSONRPCErrorFunction · 0.85
DecodeBase64PSBTFunction · 0.85
FastRandomContextClass · 0.85
AddOutputMethod · 0.80
countMethod · 0.80
CMutableTransactionClass · 0.70
ShuffleFunction · 0.50
EncodeBase64Function · 0.50
sizeMethod · 0.45
GetVersionMethod · 0.45

Tested by

no test coverage detected