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

Method FillPSBT

src/wallet/scriptpubkeyman.cpp:636–681  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

634}
635
636TransactionError LegacyScriptPubKeyMan::FillPSBT(PartiallySignedTransaction& psbtx, const PrecomputedTransactionData& txdata, int sighash_type, bool sign, bool bip32derivs, int* n_signed, bool finalize) const
637{
638 if (n_signed) {
639 *n_signed = 0;
640 }
641 for (unsigned int i = 0; i < psbtx.inputs.size(); ++i) {
642 PSBTInput& input = psbtx.inputs.at(i);
643
644 if (PSBTInputSigned(input)) {
645 continue;
646 }
647
648 // Get the Sighash type
649 if (sign && input.sighash_type != std::nullopt && *input.sighash_type != sighash_type) {
650 return TransactionError::SIGHASH_MISMATCH;
651 }
652
653 // Check non_witness_utxo has specified prevout
654 if (input.non_witness_utxo) {
655 if (*input.prev_out >= input.non_witness_utxo->vout.size()) {
656 return TransactionError::MISSING_INPUTS;
657 }
658 } else if (input.witness_utxo.IsNull() && (!input.m_peg_in_value || input.m_peg_in_claim_script.empty())) {
659 // There's no UTXO so we can just skip this now
660 continue;
661 }
662 SignatureData sigdata;
663 input.FillSignatureData(sigdata);
664 SignPSBTInput(HidingSigningProvider(this, !sign, !bip32derivs), psbtx, i, &txdata, sighash_type, nullptr, finalize);
665
666 bool signed_one = PSBTInputSigned(input);
667 if (n_signed && (signed_one || !sign)) {
668 // If sign is false, we assume that we _could_ sign if we get here. This
669 // will never have false negatives; it is hard to tell under what i
670 // circumstances it could have false positives.
671 (*n_signed)++;
672 }
673 }
674
675 // Fill in the bip32 keypaths and redeemscripts for the outputs so that hardware wallets can identify change
676 for (unsigned int i = 0; i < psbtx.outputs.size(); ++i) {
677 UpdatePSBTOutput(HidingSigningProvider(this, true, !bip32derivs), psbtx, i);
678 }
679
680 return TransactionError::OK;
681}
682
683std::unique_ptr<CKeyMetadata> LegacyScriptPubKeyMan::GetMetadata(const CTxDestination& dest) const
684{

Callers

nothing calls this directly

Calls 10

PSBTInputSignedFunction · 0.85
SignPSBTInputFunction · 0.85
UpdatePSBTOutputFunction · 0.85
MergeFunction · 0.85
FillSignatureDataMethod · 0.80
sizeMethod · 0.45
IsNullMethod · 0.45
emptyMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected