MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / FillPSBT

Method FillPSBT

src/wallet/scriptpubkeyman.cpp:1359–1452  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1357}
1358
1359std::optional<PSBTError> DescriptorScriptPubKeyMan::FillPSBT(PartiallySignedTransaction& psbtx, const PrecomputedTransactionData& txdata, const common::PSBTFillOptions& options, int* n_signed) const
1360{
1361 if (n_signed) {
1362 *n_signed = 0;
1363 }
1364 for (unsigned int i = 0; i < psbtx.inputs.size(); ++i) {
1365 PSBTInput& input = psbtx.inputs.at(i);
1366
1367 if (PSBTInputSigned(input)) {
1368 continue;
1369 }
1370
1371 // Get the scriptPubKey to know which SigningProvider to use
1372 CScript script;
1373 if (!input.witness_utxo.IsNull()) {
1374 script = input.witness_utxo.scriptPubKey;
1375 } else if (input.non_witness_utxo) {
1376 if (input.prev_out >= input.non_witness_utxo->vout.size()) {
1377 return PSBTError::MISSING_INPUTS;
1378 }
1379 script = input.non_witness_utxo->vout[input.prev_out].scriptPubKey;
1380 } else {
1381 // There's no UTXO so we can just skip this now
1382 continue;
1383 }
1384
1385 std::unique_ptr<FlatSigningProvider> keys = std::make_unique<FlatSigningProvider>();
1386 std::unique_ptr<FlatSigningProvider> script_keys = GetSigningProvider(script, /*include_private=*/options.sign);
1387 if (script_keys) {
1388 keys->Merge(std::move(*script_keys));
1389 } else {
1390 // Maybe there are pubkeys listed that we can sign for
1391 std::vector<CPubKey> pubkeys;
1392 pubkeys.reserve(input.hd_keypaths.size() + 2);
1393
1394 // ECDSA Pubkeys
1395 for (const auto& [pk, _] : input.hd_keypaths) {
1396 pubkeys.push_back(pk);
1397 }
1398
1399 // Taproot output pubkey
1400 std::vector<std::vector<unsigned char>> sols;
1401 if (Solver(script, sols) == TxoutType::WITNESS_V1_TAPROOT) {
1402 sols[0].insert(sols[0].begin(), 0x02);
1403 pubkeys.emplace_back(sols[0]);
1404 sols[0][0] = 0x03;
1405 pubkeys.emplace_back(sols[0]);
1406 }
1407
1408 // Taproot pubkeys
1409 for (const auto& pk_pair : input.m_tap_bip32_paths) {
1410 const XOnlyPubKey& pubkey = pk_pair.first;
1411 for (unsigned char prefix : {0x02, 0x03}) {
1412 unsigned char b[33] = {prefix};
1413 std::copy(pubkey.begin(), pubkey.end(), b + 1);
1414 CPubKey fullpubkey;
1415 fullpubkey.Set(b, b + 33);
1416 pubkeys.push_back(fullpubkey);

Callers

nothing calls this directly

Calls 15

PSBTInputSignedFunction · 0.85
SolverFunction · 0.85
SignPSBTInputFunction · 0.85
UpdatePSBTOutputFunction · 0.85
sizeMethod · 0.45
atMethod · 0.45
IsNullMethod · 0.45
MergeMethod · 0.45
reserveMethod · 0.45
push_backMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected