Bitcoin Core  0.20.99
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 <optional.h>
11 #include <policy/feerate.h>
12 #include <primitives/transaction.h>
13 #include <pubkey.h>
14 #include <script/sign.h>
15 #include <script/signingprovider.h>
16 
17 // Magic bytes
18 static constexpr uint8_t PSBT_MAGIC_BYTES[5] = {'p', 's', 'b', 't', 0xff};
19 
20 // Global types
21 static constexpr uint8_t PSBT_GLOBAL_UNSIGNED_TX = 0x00;
22 
23 // Input types
24 static constexpr uint8_t PSBT_IN_NON_WITNESS_UTXO = 0x00;
25 static constexpr uint8_t PSBT_IN_WITNESS_UTXO = 0x01;
26 static constexpr uint8_t PSBT_IN_PARTIAL_SIG = 0x02;
27 static constexpr uint8_t PSBT_IN_SIGHASH = 0x03;
28 static constexpr uint8_t PSBT_IN_REDEEMSCRIPT = 0x04;
29 static constexpr uint8_t PSBT_IN_WITNESSSCRIPT = 0x05;
30 static constexpr uint8_t PSBT_IN_BIP32_DERIVATION = 0x06;
31 static constexpr uint8_t PSBT_IN_SCRIPTSIG = 0x07;
32 static constexpr uint8_t PSBT_IN_SCRIPTWITNESS = 0x08;
33 
34 // Output types
35 static constexpr uint8_t PSBT_OUT_REDEEMSCRIPT = 0x00;
36 static constexpr uint8_t PSBT_OUT_WITNESSSCRIPT = 0x01;
37 static constexpr uint8_t PSBT_OUT_BIP32_DERIVATION = 0x02;
38 
39 // The separator is 0x00. Reading this in means that the unserializer can interpret it
40 // as a 0 length key which indicates that this is the separator. The separator has no value.
41 static constexpr uint8_t PSBT_SEPARATOR = 0x00;
42 
43 // BIP 174 does not specify a maximum file size, but we set a limit anyway
44 // to prevent reading a stream indefinately and running out of memory.
45 const std::streamsize MAX_FILE_SIZE_PSBT = 100000000; // 100 MiB
46 
48 struct PSBTInput
49 {
56  std::map<CPubKey, KeyOriginInfo> hd_keypaths;
57  std::map<CKeyID, SigPair> partial_sigs;
58  std::map<std::vector<unsigned char>, std::vector<unsigned char>> unknown;
59  int sighash_type = 0;
60 
61  bool IsNull() const;
62  void FillSignatureData(SignatureData& sigdata) const;
63  void FromSignatureData(const SignatureData& sigdata);
64  void Merge(const PSBTInput& input);
65  bool IsSane() const;
66  PSBTInput() {}
67 
68  template <typename Stream>
69  inline void Serialize(Stream& s) const {
70  // Write the utxo
71  // If there is a non-witness utxo, then don't add the witness one.
72  if (non_witness_utxo) {
74  OverrideStream<Stream> os(&s, s.GetType(), s.GetVersion() | SERIALIZE_TRANSACTION_NO_WITNESS);
75  SerializeToVector(os, non_witness_utxo);
76  } else if (!witness_utxo.IsNull()) {
78  SerializeToVector(s, witness_utxo);
79  }
80 
81  if (final_script_sig.empty() && final_script_witness.IsNull()) {
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) {
91  SerializeToVector(s, sighash_type);
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()) {
118  SerializeToVector(s, final_script_witness.stack);
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);
164  UnserializeFromVector(os, non_witness_utxo);
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  }
173  UnserializeFromVector(s, witness_utxo);
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  }
204  UnserializeFromVector(s, sighash_type);
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  {
228  DeserializeHDKeypaths(s, key, hd_keypaths);
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  }
248  UnserializeFromVector(s, final_script_witness.stack);
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);
287  bool IsSane() const;
289 
290  template <typename Stream>
291  inline void Serialize(Stream& s) const {
292  // Write the redeem script
293  if (!redeem_script.empty()) {
295  s << redeem_script;
296  }
297 
298  // Write the witness script
299  if (!witness_script.empty()) {
301  s << witness_script;
302  }
303 
304  // Write any hd keypaths
306 
307  // Write unknown things
308  for (auto& entry : unknown) {
309  s << entry.first;
310  s << entry.second;
311  }
312 
313  s << PSBT_SEPARATOR;
314  }
315 
316 
317  template <typename Stream>
318  inline void Unserialize(Stream& s) {
319  // Used for duplicate key detection
320  std::set<std::vector<unsigned char>> key_lookup;
321 
322  // Read loop
323  bool found_sep = false;
324  while(!s.empty()) {
325  // Read
326  std::vector<unsigned char> key;
327  s >> key;
328 
329  // the key is empty if that was actually a separator byte
330  // This is a special case for key lengths 0 as those are not allowed (except for separator)
331  if (key.empty()) {
332  found_sep = true;
333  break;
334  }
335 
336  // First byte of key is the type
337  unsigned char type = key[0];
338 
339  // Do stuff based on type
340  switch(type) {
342  {
343  if (!key_lookup.emplace(key).second) {
344  throw std::ios_base::failure("Duplicate Key, output redeemScript already provided");
345  } else if (key.size() != 1) {
346  throw std::ios_base::failure("Output redeemScript key is more than one byte type");
347  }
348  s >> redeem_script;
349  break;
350  }
352  {
353  if (!key_lookup.emplace(key).second) {
354  throw std::ios_base::failure("Duplicate Key, output witnessScript already provided");
355  } else if (key.size() != 1) {
356  throw std::ios_base::failure("Output witnessScript key is more than one byte type");
357  }
358  s >> witness_script;
359  break;
360  }
362  {
363  DeserializeHDKeypaths(s, key, hd_keypaths);
364  break;
365  }
366  // Unknown stuff
367  default: {
368  if (unknown.count(key) > 0) {
369  throw std::ios_base::failure("Duplicate Key, key for unknown value already provided");
370  }
371  // Read in the value
372  std::vector<unsigned char> val_bytes;
373  s >> val_bytes;
374  unknown.emplace(std::move(key), std::move(val_bytes));
375  break;
376  }
377  }
378  }
379 
380  if (!found_sep) {
381  throw std::ios_base::failure("Separator is missing at the end of an output map");
382  }
383  }
384 
385  template <typename Stream>
387  Unserialize(s);
388  }
389 };
390 
393 {
395  std::vector<PSBTInput> inputs;
396  std::vector<PSBTOutput> outputs;
397  std::map<std::vector<unsigned char>, std::vector<unsigned char>> unknown;
398 
399  bool IsNull() const;
400 
403  NODISCARD bool Merge(const PartiallySignedTransaction& psbt);
404  bool IsSane() const;
405  bool AddInput(const CTxIn& txin, PSBTInput& psbtin);
406  bool AddOutput(const CTxOut& txout, const PSBTOutput& psbtout);
416  bool GetInputUTXO(CTxOut& utxo, int input_index) const;
417 
418  template <typename Stream>
419  inline void Serialize(Stream& s) const {
420 
421  // magic bytes
422  s << PSBT_MAGIC_BYTES;
423 
424  // unsigned tx flag
426 
427  // Write serialized tx to a stream
428  OverrideStream<Stream> os(&s, s.GetType(), s.GetVersion() | SERIALIZE_TRANSACTION_NO_WITNESS);
429  SerializeToVector(os, *tx);
430 
431  // Write the unknown things
432  for (auto& entry : unknown) {
433  s << entry.first;
434  s << entry.second;
435  }
436 
437  // Separator
438  s << PSBT_SEPARATOR;
439 
440  // Write inputs
441  for (const PSBTInput& input : inputs) {
442  s << input;
443  }
444  // Write outputs
445  for (const PSBTOutput& output : outputs) {
446  s << output;
447  }
448  }
449 
450 
451  template <typename Stream>
452  inline void Unserialize(Stream& s) {
453  // Read the magic bytes
454  uint8_t magic[5];
455  s >> magic;
456  if (!std::equal(magic, magic + 5, PSBT_MAGIC_BYTES)) {
457  throw std::ios_base::failure("Invalid PSBT magic bytes");
458  }
459 
460  // Used for duplicate key detection
461  std::set<std::vector<unsigned char>> key_lookup;
462 
463  // Read global data
464  bool found_sep = false;
465  while(!s.empty()) {
466  // Read
467  std::vector<unsigned char> key;
468  s >> key;
469 
470  // the key is empty if that was actually a separator byte
471  // This is a special case for key lengths 0 as those are not allowed (except for separator)
472  if (key.empty()) {
473  found_sep = true;
474  break;
475  }
476 
477  // First byte of key is the type
478  unsigned char type = key[0];
479 
480  // Do stuff based on type
481  switch(type) {
483  {
484  if (!key_lookup.emplace(key).second) {
485  throw std::ios_base::failure("Duplicate Key, unsigned tx already provided");
486  } else if (key.size() != 1) {
487  throw std::ios_base::failure("Global unsigned tx key is more than one byte type");
488  }
490  // Set the stream to serialize with non-witness since this should always be non-witness
491  OverrideStream<Stream> os(&s, s.GetType(), s.GetVersion() | SERIALIZE_TRANSACTION_NO_WITNESS);
492  UnserializeFromVector(os, mtx);
493  tx = std::move(mtx);
494  // Make sure that all scriptSigs and scriptWitnesses are empty
495  for (const CTxIn& txin : tx->vin) {
496  if (!txin.scriptSig.empty() || !txin.scriptWitness.IsNull()) {
497  throw std::ios_base::failure("Unsigned tx does not have empty scriptSigs and scriptWitnesses.");
498  }
499  }
500  break;
501  }
502  // Unknown stuff
503  default: {
504  if (unknown.count(key) > 0) {
505  throw std::ios_base::failure("Duplicate Key, key for unknown value already provided");
506  }
507  // Read in the value
508  std::vector<unsigned char> val_bytes;
509  s >> val_bytes;
510  unknown.emplace(std::move(key), std::move(val_bytes));
511  }
512  }
513  }
514 
515  if (!found_sep) {
516  throw std::ios_base::failure("Separator is missing at the end of the global map");
517  }
518 
519  // Make sure that we got an unsigned tx
520  if (!tx) {
521  throw std::ios_base::failure("No unsigned transcation was provided");
522  }
523 
524  // Read input data
525  unsigned int i = 0;
526  while (!s.empty() && i < tx->vin.size()) {
527  PSBTInput input;
528  s >> input;
529  inputs.push_back(input);
530 
531  // Make sure the non-witness utxo matches the outpoint
532  if (input.non_witness_utxo && input.non_witness_utxo->GetHash() != tx->vin[i].prevout.hash) {
533  throw std::ios_base::failure("Non-witness UTXO does not match outpoint hash");
534  }
535  ++i;
536  }
537  // Make sure that the number of inputs matches the number of inputs in the transaction
538  if (inputs.size() != tx->vin.size()) {
539  throw std::ios_base::failure("Inputs provided does not match the number of inputs in transaction.");
540  }
541 
542  // Read output data
543  i = 0;
544  while (!s.empty() && i < tx->vout.size()) {
545  PSBTOutput output;
546  s >> output;
547  outputs.push_back(output);
548  ++i;
549  }
550  // Make sure that the number of outputs matches the number of outputs in the transaction
551  if (outputs.size() != tx->vout.size()) {
552  throw std::ios_base::failure("Outputs provided does not match the number of outputs in transaction.");
553  }
554  // Sanity check
555  if (!IsSane()) {
556  throw std::ios_base::failure("PSBT is not sane.");
557  }
558  }
559 
560  template <typename Stream>
562  Unserialize(s);
563  }
564 };
565 
566 enum class PSBTRole {
567  CREATOR,
568  UPDATER,
569  SIGNER,
570  FINALIZER,
571  EXTRACTOR
572 };
573 
574 std::string PSBTRoleName(PSBTRole role);
575 
577 bool PSBTInputSigned(const PSBTInput& input);
578 
580 bool SignPSBTInput(const SigningProvider& provider, PartiallySignedTransaction& psbt, int index, int sighash = SIGHASH_ALL, SignatureData* out_sigdata = nullptr, bool use_dummy = false);
581 
586 void UpdatePSBTOutput(const SigningProvider& provider, PartiallySignedTransaction& psbt, int index);
587 
595 
604 
612 NODISCARD TransactionError CombinePSBTs(PartiallySignedTransaction& out, const std::vector<PartiallySignedTransaction>& psbtxs);
613 
615 NODISCARD bool DecodeBase64PSBT(PartiallySignedTransaction& decoded_psbt, const std::string& base64_psbt, std::string& error);
617 NODISCARD bool DecodeRawPSBT(PartiallySignedTransaction& decoded_psbt, const std::string& raw_psbt, std::string& error);
618 
619 #endif // BITCOIN_PSBT_H
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:387
static const int SERIALIZE_TRANSACTION_NO_WITNESS
Definition: transaction.h:15
static constexpr unsigned int SIZE
secp256k1:
Definition: pubkey.h:36
void SerializeToVector(Stream &s, const X &... args)
Definition: sign.h:81
static constexpr uint8_t PSBT_SEPARATOR
Definition: psbt.h:41
static constexpr uint8_t PSBT_OUT_REDEEMSCRIPT
Definition: psbt.h:35
Optional< CMutableTransaction > tx
Definition: psbt.h:394
std::vector< CTxIn > vin
Definition: transaction.h:347
CScriptWitness scriptWitness
Only serialized through CTransaction.
Definition: transaction.h:63
static constexpr uint8_t PSBT_IN_PARTIAL_SIG
Definition: psbt.h:26
static constexpr uint8_t PSBT_IN_SCRIPTWITNESS
Definition: psbt.h:32
PSBTInput(deserialize_type, Stream &s)
Definition: psbt.h:270
std::vector< std::vector< unsigned char > > stack
Definition: script.h:546
void Serialize(Stream &s) const
Definition: psbt.h:419
void FromSignatureData(const SignatureData &sigdata)
Definition: psbt.cpp:114
A version of CTransaction with the PSBT format.
Definition: psbt.h:392
CTxOut witness_utxo
Definition: psbt.h:51
bool IsNull() const
Definition: script.h:551
constexpr Span< A > MakeSpan(A(&a)[N])
Create a span to a container exposing data() and size().
Definition: span.h:77
void Serialize(Stream &s) const
Definition: psbt.h:291
void DeserializeHDKeypaths(Stream &s, const std::vector< unsigned char > &key, std::map< CPubKey, KeyOriginInfo > &hd_keypaths)
Definition: sign.h:102
NODISCARD 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:378
void Serialize(Stream &s) const
Definition: psbt.h:69
std::string PSBTRoleName(PSBTRole role)
Definition: psbt.cpp:355
CScript redeem_script
Definition: psbt.h:52
Dummy data type to identify deserializing constructors.
Definition: serialize.h:43
void UnserializeFromVector(Stream &s, X &... args)
Definition: sign.h:89
static constexpr uint8_t PSBT_IN_WITNESS_UTXO
Definition: psbt.h:25
void Merge(const PSBTInput &input)
Definition: psbt.cpp:143
static constexpr uint8_t PSBT_IN_BIP32_DERIVATION
Definition: psbt.h:30
bool IsNull() const
Definition: transaction.h:141
bool FinalizePSBT(PartiallySignedTransaction &psbtx)
Finalizes a PSBT if possible, combining partial signatures.
Definition: psbt.cpp:308
PSBTRole
Definition: psbt.h:566
A structure for PSBTs which contains per output information.
Definition: psbt.h:276
std::vector< PSBTOutput > outputs
Definition: psbt.h:396
std::map< CPubKey, KeyOriginInfo > hd_keypaths
Definition: psbt.h:280
static constexpr unsigned int COMPRESSED_SIZE
Definition: pubkey.h:37
NODISCARD bool DecodeBase64PSBT(PartiallySignedTransaction &decoded_psbt, const std::string &base64_psbt, std::string &error)
Decode a base64ed PSBT into a PartiallySignedTransaction.
Definition: psbt.cpp:367
An input of a transaction.
Definition: transaction.h:57
std::map< std::vector< unsigned char >, std::vector< unsigned char > > unknown
Definition: psbt.h:58
#define NODISCARD
Definition: attributes.h:18
static constexpr uint8_t PSBT_IN_SCRIPTSIG
Definition: psbt.h:31
std::map< CPubKey, KeyOriginInfo > hd_keypaths
Definition: psbt.h:56
std::map< CKeyID, SigPair > partial_sigs
Definition: psbt.h:57
An encapsulated public key.
Definition: pubkey.h:30
bool SignPSBTInput(const SigningProvider &provider, PartiallySignedTransaction &psbt, int index, int sighash=SIGHASH_ALL, SignatureData *out_sigdata=nullptr, bool use_dummy=false)
Signs a PSBTInput, verifying that all provided data matches what is being signed. ...
Definition: psbt.cpp:236
std::pair< CPubKey, std::vector< unsigned char > > SigPair
Definition: sign.h:54
CScriptWitness final_script_witness
Definition: psbt.h:55
std::map< std::vector< unsigned char >, std::vector< unsigned char > > unknown
Definition: psbt.h:281
const std::streamsize MAX_FILE_SIZE_PSBT
Definition: psbt.h:45
static constexpr uint8_t PSBT_IN_SIGHASH
Definition: psbt.h:27
A structure for PSBTs which contain per-input information.
Definition: psbt.h:48
bool PSBTInputSigned(const PSBTInput &input)
Checks whether a PSBTInput is already signed.
Definition: psbt.cpp:212
void Unserialize(Stream &s)
Definition: psbt.h:452
An output of a transaction.
Definition: transaction.h:120
static constexpr uint8_t PSBT_IN_REDEEMSCRIPT
Definition: psbt.h:28
static constexpr uint8_t PSBT_GLOBAL_UNSIGNED_TX
Definition: psbt.h:21
std::vector< CTxOut > vout
Definition: transaction.h:348
PSBTInput()
Definition: psbt.h:66
PSBTOutput()
Definition: psbt.h:288
std::vector< PSBTInput > inputs
Definition: psbt.h:395
void UpdatePSBTOutput(const SigningProvider &provider, PartiallySignedTransaction &psbt, int index)
Updates a PSBTOutput with information from provider.
Definition: psbt.cpp:217
int sighash_type
Definition: psbt.h:59
CScript scriptSig
Definition: transaction.h:61
static constexpr uint8_t PSBT_IN_WITNESSSCRIPT
Definition: psbt.h:29
bool IsSane() const
Definition: psbt.cpp:161
An interface to be implemented by keystores that support signing.
void SerializeHDKeypaths(Stream &s, const std::map< CPubKey, KeyOriginInfo > &hd_keypaths, uint8_t type)
Definition: sign.h:137
NODISCARD 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:338
CScript witness_script
Definition: psbt.h:279
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:390
CScript redeem_script
Definition: psbt.h:278
bool empty() const
Definition: prevector.h:286
CTransactionRef non_witness_utxo
Definition: psbt.h:50
TransactionError
Definition: error.h:22
void Unserialize(Stream &s)
Definition: psbt.h:318
void Unserialize(Stream &s)
Definition: psbt.h:132
static constexpr uint8_t PSBT_OUT_BIP32_DERIVATION
Definition: psbt.h:37
A mutable version of CTransaction.
Definition: transaction.h:345
PSBTOutput(deserialize_type, Stream &s)
Definition: psbt.h:386
static constexpr uint8_t PSBT_IN_NON_WITNESS_UTXO
Definition: psbt.h:24
CScript final_script_sig
Definition: psbt.h:54
boost::optional< T > Optional
Substitute for C++17 std::optional.
Definition: optional.h:14
static constexpr uint8_t PSBT_OUT_WITNESSSCRIPT
Definition: psbt.h:36
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:322
void FillSignatureData(SignatureData &sigdata) const
Definition: psbt.cpp:88
CScript witness_script
Definition: psbt.h:53
PartiallySignedTransaction(deserialize_type, Stream &s)
Definition: psbt.h:561
bool error(const char *fmt, const Args &... args)
Definition: system.h:49
std::map< std::vector< unsigned char >, std::vector< unsigned char > > unknown
Definition: psbt.h:397
static constexpr uint8_t PSBT_MAGIC_BYTES[5]
Definition: psbt.h:18
bool IsNull() const
Definition: psbt.cpp:83