 |
Bitcoin Core
22.99.0
P2P Digital Currency
|
Go to the documentation of this file.
25 if (
tx->GetHash() != psbt.
tx->GetHash()) {
29 for (
unsigned int i = 0; i <
inputs.size(); ++i) {
32 for (
unsigned int i = 0; i <
outputs.size(); ++i) {
35 for (
auto& xpub_pair : psbt.
m_xpubs) {
36 if (
m_xpubs.count(xpub_pair.first) == 0) {
37 m_xpubs[xpub_pair.first] = xpub_pair.second;
39 m_xpubs[xpub_pair.first].insert(xpub_pair.second.begin(), xpub_pair.second.end());
49 if (std::find(
tx->vin.begin(),
tx->vin.end(), txin) !=
tx->vin.end()) {
52 tx->vin.push_back(txin);
62 tx->vout.push_back(txout);
70 uint32_t prevout_index =
tx->vin[input_index].prevout.n;
114 sigdata.
misc_pubkeys.emplace(key_pair.first.GetID(), key_pair);
178 sigdata.
misc_pubkeys.emplace(key_pair.first.GetID(), key_pair);
215 for (
const auto& input : psbt.
inputs) {
247 bool have_all_spent_outputs =
true;
248 std::vector<CTxOut> utxos(tx.
vin.size());
249 for (
size_t idx = 0; idx < tx.
vin.size(); ++idx) {
250 if (!psbt.
GetInputUTXO(utxos[idx], idx)) have_all_spent_outputs =
false;
253 if (have_all_spent_outputs) {
254 txdata.
Init(tx, std::move(utxos),
true);
256 txdata.
Init(tx, {},
true);
275 bool require_witness_sig =
false;
294 require_witness_sig =
true;
301 if (txdata ==
nullptr) {
308 if (require_witness_sig && !sigdata.
witness)
return false;
339 bool complete =
true;
341 for (
unsigned int i = 0; i < psbtx.
tx->vin.size(); ++i) {
357 for (
unsigned int i = 0; i < result.
vin.size(); ++i) {
358 result.
vin[i].scriptSig = psbtx.
inputs[i].final_script_sig;
359 result.
vin[i].scriptWitness = psbtx.
inputs[i].final_script_witness;
369 for (
auto it = std::next(psbtxs.begin()); it != psbtxs.end(); ++it) {
370 if (!out.
Merge(*it)) {
392 std::string tx_data =
DecodeBase64(base64_tx, &invalid);
394 error =
"invalid base64";
405 if (!ss_data.
empty()) {
406 error =
"extra data after PSBT";
409 }
catch (
const std::exception& e) {
An input of a transaction.
Span< const std::byte > MakeByteSpan(V &&v) noexcept
uint32_t GetVersion() const
TransactionError CombinePSBTs(PartiallySignedTransaction &out, const std::vector< PartiallySignedTransaction > &psbtxs)
Combines PSBTs with the same underlying transaction, resulting in a single PSBT with all partial sign...
bool FinalizePSBT(PartiallySignedTransaction &psbtx)
Finalizes a PSBT if possible, combining partial signatures.
uint160 missing_redeem_script
ScriptID of the missing redeemScript (if any)
bool SignPSBTInput(const SigningProvider &provider, PartiallySignedTransaction &psbt, int index, const PrecomputedTransactionData *txdata, int sighash, SignatureData *out_sigdata, bool finalize)
Signs a PSBTInput, verifying that all provided data matches what is being signed.
CScriptWitness scriptWitness
The scriptWitness of an input. Contains complete signatures or the traditional partial signatures for...
const BaseSignatureCreator & DUMMY_SIGNATURE_CREATOR
A signature creator that just produces 71-byte empty signatures.
void FillSignatureData(SignatureData &sigdata) const
std::vector< PSBTInput > inputs
bool AddInput(const CTxIn &txin, PSBTInput &psbtin)
An interface to be implemented by keystores that support signing.
A signature creator for transactions.
bool FinalizeAndExtractPSBT(PartiallySignedTransaction &psbtx, CMutableTransaction &result)
Finalizes a PSBT if possible, and extracts it to a CMutableTransaction if it could be finalized.
std::optional< uint32_t > m_version
const SigningProvider & DUMMY_SIGNING_PROVIDER
#define Assert(val)
Identity function.
bool DecodeBase64PSBT(PartiallySignedTransaction &psbt, const std::string &base64_tx, std::string &error)
Decode a base64ed PSBT into a PartiallySignedTransaction.
PartiallySignedTransaction()
bool Merge(const PartiallySignedTransaction &psbt)
Merge psbt into this.
An output of a transaction.
bool GetInputUTXO(CTxOut &utxo, int input_index) const
Finds the UTXO for a given input index.
std::vector< unsigned char > DecodeBase64(const char *p, bool *pf_invalid)
void Init(const T &tx, std::vector< CTxOut > &&spent_outputs, bool force=false)
Initialize this PrecomputedTransactionData with transaction data.
CScript redeem_script
The redeemScript (if any) for the input.
CScript scriptSig
The scriptSig of an input. Contains complete signatures or the traditional partial signatures format.
bool witness
Stores whether the input this SigData corresponds to is a witness input.
std::optional< CMutableTransaction > tx
std::map< CKeyID, SigPair > signatures
BIP 174 style partial signatures for the input. May contain all signatures necessary for producing a ...
void UpdatePSBTOutput(const SigningProvider &provider, PartiallySignedTransaction &psbt, int index)
Updates a PSBTOutput with information from provider.
std::vector< CKeyID > missing_sigs
KeyIDs of pubkeys for signatures which could not be found.
CScript witness_script
The witnessScript (if any) for the input. witnessScripts are used in P2WSH outputs.
A structure for PSBTs which contains per output information.
std::map< KeyOriginInfo, std::set< CExtPubKey > > m_xpubs
bool complete
Stores whether the scriptSig and scriptWitness are complete.
bool AddOutput(const CTxOut &txout, const PSBTOutput &psbtout)
std::string PSBTRoleName(PSBTRole role)
bool DecodeRawPSBT(PartiallySignedTransaction &psbt, const std::string &tx_data, std::string &error)
Decode a raw (binary blob) PSBT into a PartiallySignedTransaction.
size_t CountPSBTUnsignedInputs(const PartiallySignedTransaction &psbt)
Counts the unsigned inputs of a PSBT.
bool ProduceSignature(const SigningProvider &provider, const BaseSignatureCreator &creator, const CScript &fromPubKey, SignatureData &sigdata)
Produce a script signature using a generic signature creator.
std::vector< CKeyID > missing_pubkeys
KeyIDs of pubkeys which could not be found.
std::vector< CTxOut > vout
void Merge(const PSBTOutput &output)
std::map< CKeyID, std::pair< CPubKey, KeyOriginInfo > > misc_pubkeys
A version of CTransaction with the PSBT format.
std::vector< PSBTOutput > outputs
Double ended buffer combining vector and stream-like interfaces.
bool PSBTInputSigned(const PSBTInput &input)
Checks whether a PSBTInput is already signed.
An outpoint - a combination of a transaction hash and an index n into its vout.
uint256 missing_witness_script
SHA256 of the missing witnessScript (if any)
bool error(const char *fmt, const Args &... args)
A mutable version of CTransaction.
void FromSignatureData(const SignatureData &sigdata)
PrecomputedTransactionData PrecomputePSBTData(const PartiallySignedTransaction &psbt)
Compute a PrecomputedTransactionData object from a psbt.
std::map< CPubKey, KeyOriginInfo > hd_keypaths
std::map< std::vector< unsigned char >, std::vector< unsigned char > > unknown
std::map< std::vector< unsigned char >, std::vector< unsigned char > > unknown
static const int PROTOCOL_VERSION
network protocol versioning