Bitcoin Core  21.99.0
P2P Digital Currency
psbt.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2020 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #ifndef BITCOIN_PSBT_H
6 #define BITCOIN_PSBT_H
7 
8 #include <attributes.h>
9 #include <node/transaction.h>
10 #include <policy/feerate.h>
11 #include <primitives/transaction.h>
12 #include <pubkey.h>
13 #include <script/sign.h>
14 #include <script/signingprovider.h>
15 
16 #include <optional>
17 
18 // Magic bytes
19 static constexpr uint8_t PSBT_MAGIC_BYTES[5] = {'p', 's', 'b', 't', 0xff};
20 
21 // Global types
22 static constexpr uint8_t PSBT_GLOBAL_UNSIGNED_TX = 0x00;
23 
24 // Input types
25 static constexpr uint8_t PSBT_IN_NON_WITNESS_UTXO = 0x00;
26 static constexpr uint8_t PSBT_IN_WITNESS_UTXO = 0x01;
27 static constexpr uint8_t PSBT_IN_PARTIAL_SIG = 0x02;
28 static constexpr uint8_t PSBT_IN_SIGHASH = 0x03;
29 static constexpr uint8_t PSBT_IN_REDEEMSCRIPT = 0x04;
30 static constexpr uint8_t PSBT_IN_WITNESSSCRIPT = 0x05;
31 static constexpr uint8_t PSBT_IN_BIP32_DERIVATION = 0x06;
32 static constexpr uint8_t PSBT_IN_SCRIPTSIG = 0x07;
33 static constexpr uint8_t PSBT_IN_SCRIPTWITNESS = 0x08;
34 
35 // Output types
36 static constexpr uint8_t PSBT_OUT_REDEEMSCRIPT = 0x00;
37 static constexpr uint8_t PSBT_OUT_WITNESSSCRIPT = 0x01;
38 static constexpr uint8_t PSBT_OUT_BIP32_DERIVATION = 0x02;
39 
40 // The separator is 0x00. Reading this in means that the unserializer can interpret it
41 // as a 0 length key which indicates that this is the separator. The separator has no value.
42 static constexpr uint8_t PSBT_SEPARATOR = 0x00;
43 
44 // BIP 174 does not specify a maximum file size, but we set a limit anyway
45 // to prevent reading a stream indefinitely and running out of memory.
46 const std::streamsize MAX_FILE_SIZE_PSBT = 100000000; // 100 MiB
47 
49 struct PSBTInput
50 {
57  std::map<CPubKey, KeyOriginInfo> hd_keypaths;
58  std::map<CKeyID, SigPair> partial_sigs;
59  std::map<std::vector<unsigned char>, std::vector<unsigned char>> unknown;
60  int sighash_type = 0;
61 
62  bool IsNull() const;
63  void FillSignatureData(SignatureData& sigdata) const;
64  void FromSignatureData(const SignatureData& sigdata);
65  void Merge(const PSBTInput& input);
66  PSBTInput() {}
67 
68  template <typename Stream>
69  inline void Serialize(Stream& s) const {
70  // Write the utxo
71  if (non_witness_utxo) {
73  OverrideStream<Stream> os(&s, s.GetType(), s.GetVersion() | SERIALIZE_TRANSACTION_NO_WITNESS);
75  }
76  if (!witness_utxo.IsNull()) {
79  }
80 
82  // Write any partial signatures
83  for (auto sig_pair : partial_sigs) {
84  SerializeToVector(s, PSBT_IN_PARTIAL_SIG, MakeSpan(sig_pair.second.first));
85  s << sig_pair.second.second;
86  }
87 
88  // Write the sighash type
89  if (sighash_type > 0) {
92  }
93 
94  // Write the redeem script
95  if (!redeem_script.empty()) {
97  s << redeem_script;
98  }
99 
100  // Write the witness script
101  if (!witness_script.empty()) {
103  s << witness_script;
104  }
105 
106  // Write any hd keypaths
108  }
109 
110  // Write script sig
111  if (!final_script_sig.empty()) {
113  s << final_script_sig;
114  }
115  // write script witness
116  if (!final_script_witness.IsNull()) {
119  }
120 
121  // Write unknown things
122  for (auto& entry : unknown) {
123  s << entry.first;
124  s << entry.second;
125  }
126 
127  s << PSBT_SEPARATOR;
128  }
129 
130 
131  template <typename Stream>
132  inline void Unserialize(Stream& s) {
133  // Used for duplicate key detection
134  std::set<std::vector<unsigned char>> key_lookup;
135 
136  // Read loop
137  bool found_sep = false;
138  while(!s.empty()) {
139  // Read
140  std::vector<unsigned char> key;
141  s >> key;
142 
143  // the key is empty if that was actually a separator byte
144  // This is a special case for key lengths 0 as those are not allowed (except for separator)
145  if (key.empty()) {
146  found_sep = true;
147  break;
148  }
149 
150  // First byte of key is the type
151  unsigned char type = key[0];
152 
153  // Do stuff based on type
154  switch(type) {
156  {
157  if (!key_lookup.emplace(key).second) {
158  throw std::ios_base::failure("Duplicate Key, input non-witness utxo already provided");
159  } else if (key.size() != 1) {
160  throw std::ios_base::failure("Non-witness utxo key is more than one byte type");
161  }
162  // Set the stream to unserialize with witness since this is always a valid network transaction
163  OverrideStream<Stream> os(&s, s.GetType(), s.GetVersion() & ~SERIALIZE_TRANSACTION_NO_WITNESS);
165  break;
166  }
168  if (!key_lookup.emplace(key).second) {
169  throw std::ios_base::failure("Duplicate Key, input witness utxo already provided");
170  } else if (key.size() != 1) {
171  throw std::ios_base::failure("Witness utxo key is more than one byte type");
172  }
174  break;
175  case PSBT_IN_PARTIAL_SIG:
176  {
177  // Make sure that the key is the size of pubkey + 1
178  if (key.size() != CPubKey::SIZE + 1 && key.size() != CPubKey::COMPRESSED_SIZE + 1) {
179  throw std::ios_base::failure("Size of key was not the expected size for the type partial signature pubkey");
180  }
181  // Read in the pubkey from key
182  CPubKey pubkey(key.begin() + 1, key.end());
183  if (!pubkey.IsFullyValid()) {
184  throw std::ios_base::failure("Invalid pubkey");
185  }
186  if (partial_sigs.count(pubkey.GetID()) > 0) {
187  throw std::ios_base::failure("Duplicate Key, input partial signature for pubkey already provided");
188  }
189 
190  // Read in the signature from value
191  std::vector<unsigned char> sig;
192  s >> sig;
193 
194  // Add to list
195  partial_sigs.emplace(pubkey.GetID(), SigPair(pubkey, std::move(sig)));
196  break;
197  }
198  case PSBT_IN_SIGHASH:
199  if (!key_lookup.emplace(key).second) {
200  throw std::ios_base::failure("Duplicate Key, input sighash type already provided");
201  } else if (key.size() != 1) {
202  throw std::ios_base::failure("Sighash type key is more than one byte type");
203  }
205  break;
207  {
208  if (!key_lookup.emplace(key).second) {
209  throw std::ios_base::failure("Duplicate Key, input redeemScript already provided");
210  } else if (key.size() != 1) {
211  throw std::ios_base::failure("Input redeemScript key is more than one byte type");
212  }
213  s >> redeem_script;
214  break;
215  }
217  {
218  if (!key_lookup.emplace(key).second) {
219  throw std::ios_base::failure("Duplicate Key, input witnessScript already provided");
220  } else if (key.size() != 1) {
221  throw std::ios_base::failure("Input witnessScript key is more than one byte type");
222  }
223  s >> witness_script;
224  break;
225  }
227  {
229  break;
230  }
231  case PSBT_IN_SCRIPTSIG:
232  {
233  if (!key_lookup.emplace(key).second) {
234  throw std::ios_base::failure("Duplicate Key, input final scriptSig already provided");
235  } else if (key.size() != 1) {
236  throw std::ios_base::failure("Final scriptSig key is more than one byte type");
237  }
238  s >> final_script_sig;
239  break;
240  }
242  {
243  if (!key_lookup.emplace(key).second) {
244  throw std::ios_base::failure("Duplicate Key, input final scriptWitness already provided");
245  } else if (key.size() != 1) {
246  throw std::ios_base::failure("Final scriptWitness key is more than one byte type");
247  }
249  break;
250  }
251  // Unknown stuff
252  default:
253  if (unknown.count(key) > 0) {
254  throw std::ios_base::failure("Duplicate Key, key for unknown value already provided");
255  }
256  // Read in the value
257  std::vector<unsigned char> val_bytes;
258  s >> val_bytes;
259  unknown.emplace(std::move(key), std::move(val_bytes));
260  break;
261  }
262  }
263 
264  if (!found_sep) {
265  throw std::ios_base::failure("Separator is missing at the end of an input map");
266  }
267  }
268 
269  template <typename Stream>
271  Unserialize(s);
272  }
273 };
274 
277 {
280  std::map<CPubKey, KeyOriginInfo> hd_keypaths;
281  std::map<std::vector<unsigned char>, std::vector<unsigned char>> unknown;
282 
283  bool IsNull() const;
284  void FillSignatureData(SignatureData& sigdata) const;
285  void FromSignatureData(const SignatureData& sigdata);
286  void Merge(const PSBTOutput& output);
288 
289  template <typename Stream>
290  inline void Serialize(Stream& s) const {
291  // Write the redeem script
292  if (!redeem_script.empty()) {
294  s << redeem_script;
295  }
296 
297  // Write the witness script
298  if (!witness_script.empty()) {
300  s << witness_script;
301  }
302 
303  // Write any hd keypaths
305 
306  // Write unknown things
307  for (auto& entry : unknown) {
308  s << entry.first;
309  s << entry.second;
310  }
311 
312  s << PSBT_SEPARATOR;
313  }
314 
315 
316  template <typename Stream>
317  inline void Unserialize(Stream& s) {
318  // Used for duplicate key detection
319  std::set<std::vector<unsigned char>> key_lookup;
320 
321  // Read loop
322  bool found_sep = false;
323  while(!s.empty()) {
324  // Read
325  std::vector<unsigned char> key;
326  s >> key;
327 
328  // the key is empty if that was actually a separator byte
329  // This is a special case for key lengths 0 as those are not allowed (except for separator)
330  if (key.empty()) {
331  found_sep = true;
332  break;
333  }
334 
335  // First byte of key is the type
336  unsigned char type = key[0];
337 
338  // Do stuff based on type
339  switch(type) {
341  {
342  if (!key_lookup.emplace(key).second) {
343  throw std::ios_base::failure("Duplicate Key, output redeemScript already provided");
344  } else if (key.size() != 1) {
345  throw std::ios_base::failure("Output redeemScript key is more than one byte type");
346  }
347  s >> redeem_script;
348  break;
349  }
351  {
352  if (!key_lookup.emplace(key).second) {
353  throw std::ios_base::failure("Duplicate Key, output witnessScript already provided");
354  } else if (key.size() != 1) {
355  throw std::ios_base::failure("Output witnessScript key is more than one byte type");
356  }
357  s >> witness_script;
358  break;
359  }
361  {
363  break;
364  }
365  // Unknown stuff
366  default: {
367  if (unknown.count(key) > 0) {
368  throw std::ios_base::failure("Duplicate Key, key for unknown value already provided");
369  }
370  // Read in the value
371  std::vector<unsigned char> val_bytes;
372  s >> val_bytes;
373  unknown.emplace(std::move(key), std::move(val_bytes));
374  break;
375  }
376  }
377  }
378 
379  if (!found_sep) {
380  throw std::ios_base::failure("Separator is missing at the end of an output map");
381  }
382  }
383 
384  template <typename Stream>
386  Unserialize(s);
387  }
388 };
389 
392 {
393  std::optional<CMutableTransaction> tx;
394  std::vector<PSBTInput> inputs;
395  std::vector<PSBTOutput> outputs;
396  std::map<std::vector<unsigned char>, std::vector<unsigned char>> unknown;
397 
398  bool IsNull() const;
399 
402  [[nodiscard]] bool Merge(const PartiallySignedTransaction& psbt);
403  bool AddInput(const CTxIn& txin, PSBTInput& psbtin);
404  bool AddOutput(const CTxOut& txout, const PSBTOutput& psbtout);
414  bool GetInputUTXO(CTxOut& utxo, int input_index) const;
415 
416  template <typename Stream>
417  inline void Serialize(Stream& s) const {
418 
419  // magic bytes
420  s << PSBT_MAGIC_BYTES;
421 
422  // unsigned tx flag
424 
425  // Write serialized tx to a stream
426  OverrideStream<Stream> os(&s, s.GetType(), s.GetVersion() | SERIALIZE_TRANSACTION_NO_WITNESS);
427  SerializeToVector(os, *tx);
428 
429  // Write the unknown things
430  for (auto& entry : unknown) {
431  s << entry.first;
432  s << entry.second;
433  }
434 
435  // Separator
436  s << PSBT_SEPARATOR;
437 
438  // Write inputs
439  for (const PSBTInput& input : inputs) {
440  s << input;
441  }
442  // Write outputs
443  for (const PSBTOutput& output : outputs) {
444  s << output;
445  }
446  }
447 
448 
449  template <typename Stream>
450  inline void Unserialize(Stream& s) {
451  // Read the magic bytes
452  uint8_t magic[5];
453  s >> magic;
454  if (!std::equal(magic, magic + 5, PSBT_MAGIC_BYTES)) {
455  throw std::ios_base::failure("Invalid PSBT magic bytes");
456  }
457 
458  // Used for duplicate key detection
459  std::set<std::vector<unsigned char>> key_lookup;
460 
461  // Read global data
462  bool found_sep = false;
463  while(!s.empty()) {
464  // Read
465  std::vector<unsigned char> key;
466  s >> key;
467 
468  // the key is empty if that was actually a separator byte
469  // This is a special case for key lengths 0 as those are not allowed (except for separator)
470  if (key.empty()) {
471  found_sep = true;
472  break;
473  }
474 
475  // First byte of key is the type
476  unsigned char type = key[0];
477 
478  // Do stuff based on type
479  switch(type) {
481  {
482  if (!key_lookup.emplace(key).second) {
483  throw std::ios_base::failure("Duplicate Key, unsigned tx already provided");
484  } else if (key.size() != 1) {
485  throw std::ios_base::failure("Global unsigned tx key is more than one byte type");
486  }
488  // Set the stream to serialize with non-witness since this should always be non-witness
489  OverrideStream<Stream> os(&s, s.GetType(), s.GetVersion() | SERIALIZE_TRANSACTION_NO_WITNESS);
490  UnserializeFromVector(os, mtx);
491  tx = std::move(mtx);
492  // Make sure that all scriptSigs and scriptWitnesses are empty
493  for (const CTxIn& txin : tx->vin) {
494  if (!txin.scriptSig.empty() || !txin.scriptWitness.IsNull()) {
495  throw std::ios_base::failure("Unsigned tx does not have empty scriptSigs and scriptWitnesses.");
496  }
497  }
498  break;
499  }
500  // Unknown stuff
501  default: {
502  if (unknown.count(key) > 0) {
503  throw std::ios_base::failure("Duplicate Key, key for unknown value already provided");
504  }
505  // Read in the value
506  std::vector<unsigned char> val_bytes;
507  s >> val_bytes;
508  unknown.emplace(std::move(key), std::move(val_bytes));
509  }
510  }
511  }
512 
513  if (!found_sep) {
514  throw std::ios_base::failure("Separator is missing at the end of the global map");
515  }
516 
517  // Make sure that we got an unsigned tx
518  if (!tx) {
519  throw std::ios_base::failure("No unsigned transcation was provided");
520  }
521 
522  // Read input data
523  unsigned int i = 0;
524  while (!s.empty() && i < tx->vin.size()) {
525  PSBTInput input;
526  s >> input;
527  inputs.push_back(input);
528 
529  // Make sure the non-witness utxo matches the outpoint
530  if (input.non_witness_utxo && input.non_witness_utxo->GetHash() != tx->vin[i].prevout.hash) {
531  throw std::ios_base::failure("Non-witness UTXO does not match outpoint hash");
532  }
533  ++i;
534  }
535  // Make sure that the number of inputs matches the number of inputs in the transaction
536  if (inputs.size() != tx->vin.size()) {
537  throw std::ios_base::failure("Inputs provided does not match the number of inputs in transaction.");
538  }
539 
540  // Read output data
541  i = 0;
542  while (!s.empty() && i < tx->vout.size()) {
543  PSBTOutput output;
544  s >> output;
545  outputs.push_back(output);
546  ++i;
547  }
548  // Make sure that the number of outputs matches the number of outputs in the transaction
549  if (outputs.size() != tx->vout.size()) {
550  throw std::ios_base::failure("Outputs provided does not match the number of outputs in transaction.");
551  }
552  }
553 
554  template <typename Stream>
556  Unserialize(s);
557  }
558 };
559 
560 enum class PSBTRole {
561  CREATOR,
562  UPDATER,
563  SIGNER,
564  FINALIZER,
565  EXTRACTOR
566 };
567 
568 std::string PSBTRoleName(PSBTRole role);
569 
572 
574 bool PSBTInputSigned(const PSBTInput& input);
575 
581 bool SignPSBTInput(const SigningProvider& provider, PartiallySignedTransaction& psbt, int index, const PrecomputedTransactionData* txdata, int sighash = SIGHASH_ALL, SignatureData* out_sigdata = nullptr);
582 
585 
590 void UpdatePSBTOutput(const SigningProvider& provider, PartiallySignedTransaction& psbt, int index);
591 
599 
608 
616 [[nodiscard]] TransactionError CombinePSBTs(PartiallySignedTransaction& out, const std::vector<PartiallySignedTransaction>& psbtxs);
617 
619 [[nodiscard]] bool DecodeBase64PSBT(PartiallySignedTransaction& decoded_psbt, const std::string& base64_psbt, std::string& error);
621 [[nodiscard]] bool DecodeRawPSBT(PartiallySignedTransaction& decoded_psbt, const std::string& raw_psbt, std::string& error);
622 
623 #endif // BITCOIN_PSBT_H
CTxIn
An input of a transaction.
Definition: transaction.h:65
deserialize_type
Dummy data type to identify deserializing constructors.
Definition: serialize.h:47
CScriptWitness::IsNull
bool IsNull() const
Definition: script.h:565
feerate.h
PSBTInput::non_witness_utxo
CTransactionRef non_witness_utxo
Definition: psbt.h:51
PSBT_IN_SCRIPTWITNESS
static constexpr uint8_t PSBT_IN_SCRIPTWITNESS
Definition: psbt.h:33
DecodeRawPSBT
bool DecodeRawPSBT(PartiallySignedTransaction &decoded_psbt, const std::string &raw_psbt, std::string &error)
Decode a raw (binary blob) PSBT into a PartiallySignedTransaction.
Definition: psbt.cpp:385
PSBTInput::partial_sigs
std::map< CKeyID, SigPair > partial_sigs
Definition: psbt.h:58
FinalizePSBT
bool FinalizePSBT(PartiallySignedTransaction &psbtx)
Finalizes a PSBT if possible, combining partial signatures.
Definition: psbt.cpp:318
PSBTInput::PSBTInput
PSBTInput()
Definition: psbt.h:66
PartiallySignedTransaction::IsNull
bool IsNull() const
Definition: psbt.cpp:17
transaction.h
PSBTOutput::PSBTOutput
PSBTOutput()
Definition: psbt.h:287
PSBTOutput::FillSignatureData
void FillSignatureData(SignatureData &sigdata) const
Definition: psbt.cpp:158
CombinePSBTs
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...
Definition: psbt.cpp:349
CPubKey::SIZE
static constexpr unsigned int SIZE
secp256k1:
Definition: pubkey.h:38
PSBT_IN_REDEEMSCRIPT
static constexpr uint8_t PSBT_IN_REDEEMSCRIPT
Definition: psbt.h:29
PSBTRole::UPDATER
@ UPDATER
PartiallySignedTransaction::inputs
std::vector< PSBTInput > inputs
Definition: psbt.h:394
PSBTInput::witness_script
CScript witness_script
Definition: psbt.h:54
PartiallySignedTransaction::AddInput
bool AddInput(const CTxIn &txin, PSBTInput &psbtin)
Definition: psbt.cpp:40
PSBT_GLOBAL_UNSIGNED_TX
static constexpr uint8_t PSBT_GLOBAL_UNSIGNED_TX
Definition: psbt.h:22
SigningProvider
An interface to be implemented by keystores that support signing.
Definition: signingprovider.h:18
PSBTOutput::redeem_script
CScript redeem_script
Definition: psbt.h:278
PSBTOutput::Unserialize
void Unserialize(Stream &s)
Definition: psbt.h:317
PSBT_IN_NON_WITNESS_UTXO
static constexpr uint8_t PSBT_IN_NON_WITNESS_UTXO
Definition: psbt.h:25
PSBTInputSigned
bool PSBTInputSigned(const PSBTInput &input)
Checks whether a PSBTInput is already signed.
Definition: psbt.cpp:197
pubkey.h
CTransactionRef
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:386
PSBTOutput::witness_script
CScript witness_script
Definition: psbt.h:279
PSBTOutput::PSBTOutput
PSBTOutput(deserialize_type, Stream &s)
Definition: psbt.h:385
PSBT_IN_SIGHASH
static constexpr uint8_t PSBT_IN_SIGHASH
Definition: psbt.h:28
UpdatePSBTOutput
void UpdatePSBTOutput(const SigningProvider &provider, PartiallySignedTransaction &psbt, int index)
Updates a PSBTOutput with information from provider.
Definition: psbt.cpp:213
CScriptWitness
Definition: script.h:556
DecodeBase64PSBT
bool DecodeBase64PSBT(PartiallySignedTransaction &decoded_psbt, const std::string &base64_psbt, std::string &error)
Decode a base64ed PSBT into a PartiallySignedTransaction.
Definition: psbt.cpp:374
transaction.h
CTxIn::scriptWitness
CScriptWitness scriptWitness
Only serialized through CTransaction.
Definition: transaction.h:71
signingprovider.h
SigPair
std::pair< CPubKey, std::vector< unsigned char > > SigPair
Definition: sign.h:59
CTxOut::IsNull
bool IsNull() const
Definition: transaction.h:149
PSBT_MAGIC_BYTES
static constexpr uint8_t PSBT_MAGIC_BYTES[5]
Definition: psbt.h:19
TransactionError
TransactionError
Definition: error.h:22
PartiallySignedTransaction::PartiallySignedTransaction
PartiallySignedTransaction()
Definition: psbt.h:405
PSBTInput::final_script_sig
CScript final_script_sig
Definition: psbt.h:55
SignatureData
Definition: sign.h:64
PartiallySignedTransaction::Merge
bool Merge(const PartiallySignedTransaction &psbt)
Merge psbt into this.
Definition: psbt.cpp:22
PSBTInput::hd_keypaths
std::map< CPubKey, KeyOriginInfo > hd_keypaths
Definition: psbt.h:57
CTxOut
An output of a transaction.
Definition: transaction.h:128
PartiallySignedTransaction::Unserialize
void Unserialize(Stream &s)
Definition: psbt.h:450
PSBTInput::Unserialize
void Unserialize(Stream &s)
Definition: psbt.h:132
PSBTRole::SIGNER
@ SIGNER
PSBT_IN_PARTIAL_SIG
static constexpr uint8_t PSBT_IN_PARTIAL_SIG
Definition: psbt.h:27
PartiallySignedTransaction::GetInputUTXO
bool GetInputUTXO(CTxOut &utxo, int input_index) const
Finds the UTXO for a given input index.
Definition: psbt.cpp:60
PSBTInput::final_script_witness
CScriptWitness final_script_witness
Definition: psbt.h:56
PSBTRole::CREATOR
@ CREATOR
PSBTRoleName
std::string PSBTRoleName(PSBTRole role)
Definition: psbt.cpp:362
PSBTOutput::IsNull
bool IsNull() const
Definition: psbt.cpp:184
UnserializeFromVector
void UnserializeFromVector(Stream &s, X &... args)
Definition: sign.h:97
PSBT_IN_WITNESS_UTXO
static constexpr uint8_t PSBT_IN_WITNESS_UTXO
Definition: psbt.h:26
sign.h
PartiallySignedTransaction::tx
std::optional< CMutableTransaction > tx
Definition: psbt.h:393
PSBTInput::Merge
void Merge(const PSBTInput &input)
Definition: psbt.cpp:140
SERIALIZE_TRANSACTION_NO_WITNESS
static const int SERIALIZE_TRANSACTION_NO_WITNESS
A flag that is ORed into the protocol version to designate that a transaction should be (un)serialize...
Definition: transaction.h:23
PSBTOutput
A structure for PSBTs which contains per output information.
Definition: psbt.h:276
PrecomputedTransactionData
Definition: interpreter.h:147
CPubKey::COMPRESSED_SIZE
static constexpr unsigned int COMPRESSED_SIZE
Definition: pubkey.h:39
PSBTInput::unknown
std::map< std::vector< unsigned char >, std::vector< unsigned char > > unknown
Definition: psbt.h:59
PSBT_OUT_BIP32_DERIVATION
static constexpr uint8_t PSBT_OUT_BIP32_DERIVATION
Definition: psbt.h:38
CScript
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:404
PartiallySignedTransaction::AddOutput
bool AddOutput(const CTxOut &txout, const PSBTOutput &psbtout)
Definition: psbt.cpp:53
PSBT_IN_BIP32_DERIVATION
static constexpr uint8_t PSBT_IN_BIP32_DERIVATION
Definition: psbt.h:31
CountPSBTUnsignedInputs
size_t CountPSBTUnsignedInputs(const PartiallySignedTransaction &psbt)
Counts the unsigned inputs of a PSBT.
Definition: psbt.cpp:202
DeserializeHDKeypaths
void DeserializeHDKeypaths(Stream &s, const std::vector< unsigned char > &key, std::map< CPubKey, KeyOriginInfo > &hd_keypaths)
Definition: sign.h:110
PSBTRole::EXTRACTOR
@ EXTRACTOR
FinalizeAndExtractPSBT
bool FinalizeAndExtractPSBT(PartiallySignedTransaction &psbtx, CMutableTransaction &result)
Finalizes a PSBT if possible, and extracts it to a CMutableTransaction if it could be finalized.
Definition: psbt.cpp:333
attributes.h
OverrideStream
Definition: streams.h:26
SignPSBTInput
bool SignPSBTInput(const SigningProvider &provider, PartiallySignedTransaction &psbt, int index, const PrecomputedTransactionData *txdata, int sighash=SIGHASH_ALL, SignatureData *out_sigdata=nullptr)
Signs a PSBTInput, verifying that all provided data matches what is being signed.
Definition: psbt.cpp:250
PSBT_IN_SCRIPTSIG
static constexpr uint8_t PSBT_IN_SCRIPTSIG
Definition: psbt.h:32
PSBTInput::FillSignatureData
void FillSignatureData(SignatureData &sigdata) const
Definition: psbt.cpp:85
PSBTOutput::Merge
void Merge(const PSBTOutput &output)
Definition: psbt.cpp:189
SIGHASH_ALL
@ SIGHASH_ALL
Definition: interpreter.h:27
CPubKey
An encapsulated public key.
Definition: pubkey.h:32
PSBTInput
A structure for PSBTs which contain per-input information.
Definition: psbt.h:49
PSBTRole::FINALIZER
@ FINALIZER
PSBTInput::FromSignatureData
void FromSignatureData(const SignatureData &sigdata)
Definition: psbt.cpp:111
PSBT_OUT_WITNESSSCRIPT
static constexpr uint8_t PSBT_OUT_WITNESSSCRIPT
Definition: psbt.h:37
PartiallySignedTransaction
A version of CTransaction with the PSBT format.
Definition: psbt.h:391
PSBTOutput::Serialize
void Serialize(Stream &s) const
Definition: psbt.h:290
PSBT_OUT_REDEEMSCRIPT
static constexpr uint8_t PSBT_OUT_REDEEMSCRIPT
Definition: psbt.h:36
PSBTInput::PSBTInput
PSBTInput(deserialize_type, Stream &s)
Definition: psbt.h:270
PSBTRole
PSBTRole
Definition: psbt.h:560
CTxIn::scriptSig
CScript scriptSig
Definition: transaction.h:69
PartiallySignedTransaction::outputs
std::vector< PSBTOutput > outputs
Definition: psbt.h:395
CPubKey::IsFullyValid
bool IsFullyValid() const
fully validate whether this is a valid public key (more expensive than IsValid())
Definition: pubkey.cpp:275
PSBTInput::Serialize
void Serialize(Stream &s) const
Definition: psbt.h:69
prevector::empty
bool empty() const
Definition: prevector.h:286
PartiallySignedTransaction::PartiallySignedTransaction
PartiallySignedTransaction(deserialize_type, Stream &s)
Definition: psbt.h:555
MAX_FILE_SIZE_PSBT
const std::streamsize MAX_FILE_SIZE_PSBT
Definition: psbt.h:46
PSBT_SEPARATOR
static constexpr uint8_t PSBT_SEPARATOR
Definition: psbt.h:42
PSBTInput::redeem_script
CScript redeem_script
Definition: psbt.h:53
SerializeToVector
void SerializeToVector(Stream &s, const X &... args)
Definition: sign.h:89
error
bool error(const char *fmt, const Args &... args)
Definition: system.h:49
PrecomputePSBTData
PrecomputedTransactionData PrecomputePSBTData(const PartiallySignedTransaction &psbt)
Compute a PrecomputedTransactionData object from a psbt.
Definition: psbt.cpp:233
PSBTInput::IsNull
bool IsNull() const
Definition: psbt.cpp:80
CMutableTransaction
A mutable version of CTransaction.
Definition: transaction.h:344
PSBTOutput::FromSignatureData
void FromSignatureData(const SignatureData &sigdata)
Definition: psbt.cpp:171
PSBTInput::witness_utxo
CTxOut witness_utxo
Definition: psbt.h:52
MakeSpan
constexpr Span< A > MakeSpan(A(&a)[N])
MakeSpan for arrays:
Definition: span.h:222
PSBTInput::sighash_type
int sighash_type
Definition: psbt.h:60
PSBTOutput::hd_keypaths
std::map< CPubKey, KeyOriginInfo > hd_keypaths
Definition: psbt.h:280
PartiallySignedTransaction::Serialize
void Serialize(Stream &s) const
Definition: psbt.h:417
CScriptWitness::stack
std::vector< std::vector< unsigned char > > stack
Definition: script.h:560
PSBT_IN_WITNESSSCRIPT
static constexpr uint8_t PSBT_IN_WITNESSSCRIPT
Definition: psbt.h:30
CPubKey::GetID
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
Definition: pubkey.h:160
PartiallySignedTransaction::unknown
std::map< std::vector< unsigned char >, std::vector< unsigned char > > unknown
Definition: psbt.h:396
PSBTOutput::unknown
std::map< std::vector< unsigned char >, std::vector< unsigned char > > unknown
Definition: psbt.h:281
SerializeHDKeypaths
void SerializeHDKeypaths(Stream &s, const std::map< CPubKey, KeyOriginInfo > &hd_keypaths, uint8_t type)
Definition: sign.h:145