54 std::map<std::vector<unsigned char>, std::vector<unsigned char>>
unknown;
64 template <
typename Stream>
81 s << sig_pair.second.second;
127 template <
typename Stream>
130 bool found_sep =
false;
133 std::vector<unsigned char>
key;
144 unsigned char type =
key[0];
151 throw std::ios_base::failure(
"Duplicate Key, input non-witness utxo already provided");
152 }
else if (
key.size() != 1) {
153 throw std::ios_base::failure(
"Non-witness utxo key is more than one byte type");
162 throw std::ios_base::failure(
"Duplicate Key, input witness utxo already provided");
163 }
else if (
key.size() != 1) {
164 throw std::ios_base::failure(
"Witness utxo key is more than one byte type");
172 throw std::ios_base::failure(
"Size of key was not the expected size for the type partial signature pubkey");
176 if (!pubkey.IsFullyValid()) {
177 throw std::ios_base::failure(
"Invalid pubkey");
180 throw std::ios_base::failure(
"Duplicate Key, input partial signature for pubkey already provided");
184 std::vector<unsigned char> sig;
193 throw std::ios_base::failure(
"Duplicate Key, input sighash type already provided");
194 }
else if (
key.size() != 1) {
195 throw std::ios_base::failure(
"Sighash type key is more than one byte type");
202 throw std::ios_base::failure(
"Duplicate Key, input redeemScript already provided");
203 }
else if (
key.size() != 1) {
204 throw std::ios_base::failure(
"Input redeemScript key is more than one byte type");
212 throw std::ios_base::failure(
"Duplicate Key, input witnessScript already provided");
213 }
else if (
key.size() != 1) {
214 throw std::ios_base::failure(
"Input witnessScript key is more than one byte type");
227 throw std::ios_base::failure(
"Duplicate Key, input final scriptSig already provided");
228 }
else if (
key.size() != 1) {
229 throw std::ios_base::failure(
"Final scriptSig key is more than one byte type");
237 throw std::ios_base::failure(
"Duplicate Key, input final scriptWitness already provided");
238 }
else if (
key.size() != 1) {
239 throw std::ios_base::failure(
"Final scriptWitness key is more than one byte type");
247 throw std::ios_base::failure(
"Duplicate Key, key for unknown value already provided");
250 std::vector<unsigned char> val_bytes;
252 unknown.emplace(std::move(
key), std::move(val_bytes));
258 throw std::ios_base::failure(
"Separator is missing at the end of an input map");
262 template <
typename Stream>
274 std::map<std::vector<unsigned char>, std::vector<unsigned char>>
unknown;
283 template <
typename Stream>
310 template <
typename Stream>
313 bool found_sep =
false;
316 std::vector<unsigned char>
key;
327 unsigned char type =
key[0];
334 throw std::ios_base::failure(
"Duplicate Key, output redeemScript already provided");
335 }
else if (
key.size() != 1) {
336 throw std::ios_base::failure(
"Output redeemScript key is more than one byte type");
344 throw std::ios_base::failure(
"Duplicate Key, output witnessScript already provided");
345 }
else if (
key.size() != 1) {
346 throw std::ios_base::failure(
"Output witnessScript key is more than one byte type");
359 throw std::ios_base::failure(
"Duplicate Key, key for unknown value already provided");
362 std::vector<unsigned char> val_bytes;
364 unknown.emplace(std::move(
key), std::move(val_bytes));
371 throw std::ios_base::failure(
"Separator is missing at the end of an output map");
375 template <
typename Stream>
384 boost::optional<CMutableTransaction>
tx;
387 std::map<std::vector<unsigned char>, std::vector<unsigned char>>
unknown;
409 template <
typename Stream>
442 template <
typename Stream>
448 throw std::ios_base::failure(
"Invalid PSBT magic bytes");
452 bool found_sep =
false;
455 std::vector<unsigned char>
key;
466 unsigned char type =
key[0];
473 throw std::ios_base::failure(
"Duplicate Key, unsigned tx already provided");
474 }
else if (
key.size() != 1) {
475 throw std::ios_base::failure(
"Global unsigned tx key is more than one byte type");
483 for (
const CTxIn& txin :
tx->vin) {
485 throw std::ios_base::failure(
"Unsigned tx does not have empty scriptSigs and scriptWitnesses.");
493 throw std::ios_base::failure(
"Duplicate Key, key for unknown value already provided");
496 std::vector<unsigned char> val_bytes;
498 unknown.emplace(std::move(
key), std::move(val_bytes));
504 throw std::ios_base::failure(
"Separator is missing at the end of the global map");
509 throw std::ios_base::failure(
"No unsigned transcation was provided");
514 while (!s.empty() && i <
tx->vin.size()) {
520 if (input.non_witness_utxo && input.non_witness_utxo->GetHash() !=
tx->vin[i].prevout.hash) {
521 throw std::ios_base::failure(
"Non-witness UTXO does not match outpoint hash");
526 if (
inputs.size() !=
tx->vin.size()) {
527 throw std::ios_base::failure(
"Inputs provided does not match the number of inputs in transaction.");
532 while (!s.empty() && i <
tx->vout.size()) {
540 throw std::ios_base::failure(
"Outputs provided does not match the number of outputs in transaction.");
544 throw std::ios_base::failure(
"PSBT is not sane.");
548 template <
typename Stream>
606 #endif // BITCOIN_PSBT_H std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:408
bool IsNull() const
Definition: psbt.cpp:16
std::vector< PSBTInput > inputs
Definition: psbt.h:385
PartiallySignedTransaction()
Definition: psbt.h:397
Definition: transaction.h:366
static const int SERIALIZE_TRANSACTION_NO_WITNESS
Definition: transaction.h:15
Definition: transaction.h:63
void SerializeToVector(Stream &s, const X &... args)
Definition: sign.h:81
void Merge(const PSBTOutput &output)
Definition: psbt.cpp:202
PSBTOutput()
Definition: psbt.h:281
static constexpr uint8_t PSBT_SEPARATOR
Definition: psbt.h:41
static constexpr uint8_t PSBT_OUT_REDEEMSCRIPT
Definition: psbt.h:35
std::map< CPubKey, KeyOriginInfo > hd_keypaths
Definition: psbt.h:273
static constexpr uint8_t PSBT_IN_PARTIAL_SIG
Definition: psbt.h:26
bool IsNull() const
Definition: transaction.h:160
bool IsNull() const
Definition: script.h:579
static constexpr uint8_t PSBT_IN_SCRIPTWITNESS
Definition: psbt.h:32
Definition: interpreter.h:24
CScript redeem_script
Definition: psbt.h:271
CScript witness_script
Definition: psbt.h:272
std::map< std::vector< unsigned char >, std::vector< unsigned char > > unknown
Definition: psbt.h:387
NODISCARD bool Merge(const PartiallySignedTransaction &psbt)
Definition: psbt.cpp:21
static constexpr unsigned int COMPRESSED_PUBLIC_KEY_SIZE
Definition: pubkey.h:37
unsigned char uint8_t
Definition: stdint.h:19
constexpr Span< A > MakeSpan(A(&a)[N])
Definition: span.h:55
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:372
std::string PSBTRoleName(PSBTRole role)
Definition: psbt.cpp:350
Definition: serialize.h:40
void UnserializeFromVector(Stream &s, X &... args)
Definition: sign.h:89
static constexpr uint8_t PSBT_IN_WITNESS_UTXO
Definition: psbt.h:25
static constexpr uint8_t PSBT_IN_BIP32_DERIVATION
Definition: psbt.h:30
void FromSignatureData(const SignatureData &sigdata)
Definition: psbt.cpp:184
PSBTOutput(deserialize_type, Stream &s)
Definition: psbt.h:376
bool FinalizePSBT(PartiallySignedTransaction &psbtx)
Definition: psbt.cpp:303
CScript scriptSig
Definition: transaction.h:67
PSBTRole
Definition: psbt.h:554
void Unserialize(Stream &s)
Definition: psbt.h:311
static constexpr unsigned int PUBLIC_KEY_SIZE
Definition: pubkey.h:36
Definition: signingprovider.h:18
NODISCARD bool DecodeBase64PSBT(PartiallySignedTransaction &decoded_psbt, const std::string &base64_psbt, std::string &error)
Decode a base64ed PSBT into a PartiallySignedTransaction.
Definition: psbt.cpp:361
#define NODISCARD
Definition: attributes.h:18
std::vector< std::vector< unsigned char > > stack
Definition: script.h:574
static constexpr uint8_t PSBT_IN_SCRIPTSIG
Definition: psbt.h:31
std::map< std::vector< unsigned char >, std::vector< unsigned char > > unknown
Definition: psbt.h:274
bool SignPSBTInput(const SigningProvider &provider, PartiallySignedTransaction &psbt, int index, int sighash=SIGHASH_ALL, SignatureData *out_sigdata=nullptr, bool use_dummy=false)
Definition: psbt.cpp:234
std::pair< CPubKey, std::vector< unsigned char > > SigPair
Definition: sign.h:54
static constexpr uint8_t PSBT_IN_SIGHASH
Definition: psbt.h:27
bool PSBTInputSigned(const PSBTInput &input)
Definition: psbt.cpp:210
static constexpr uint8_t PSBT_IN_REDEEMSCRIPT
Definition: psbt.h:28
bool IsNull() const
Definition: psbt.cpp:197
static constexpr uint8_t PSBT_GLOBAL_UNSIGNED_TX
Definition: psbt.h:21
void UpdatePSBTOutput(const SigningProvider &provider, PartiallySignedTransaction &psbt, int index)
Definition: psbt.cpp:215
PartiallySignedTransaction(deserialize_type, Stream &s)
Definition: psbt.h:549
bool AddOutput(const CTxOut &txout, const PSBTOutput &psbtout)
Definition: psbt.cpp:60
bool GetInputUTXO(CTxOut &utxo, int input_index) const
Definition: psbt.cpp:67
static constexpr uint8_t PSBT_IN_WITNESSSCRIPT
Definition: psbt.h:29
CScriptWitness scriptWitness
Only serialized through CTransaction.
Definition: transaction.h:69
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)
Definition: psbt.cpp:333
void Serialize(Stream &s) const
Definition: psbt.h:410
bool IsSane() const
Definition: psbt.cpp:39
bool empty() const
Definition: prevector.h:281
boost::optional< CMutableTransaction > tx
Definition: psbt.h:384
TransactionError
Definition: error.h:20
static constexpr uint8_t PSBT_OUT_BIP32_DERIVATION
Definition: psbt.h:37
static constexpr uint8_t PSBT_IN_NON_WITNESS_UTXO
Definition: psbt.h:24
void Serialize(Stream &s) const
Definition: psbt.h:284
void Unserialize(Stream &s)
Definition: psbt.h:443
static constexpr uint8_t PSBT_OUT_WITNESSSCRIPT
Definition: psbt.h:36
bool FinalizeAndExtractPSBT(PartiallySignedTransaction &psbtx, CMutableTransaction &result)
Definition: psbt.cpp:317
void FillSignatureData(SignatureData &sigdata) const
Definition: psbt.cpp:171
std::vector< PSBTOutput > outputs
Definition: psbt.h:386
bool AddInput(const CTxIn &txin, PSBTInput &psbtin)
Definition: psbt.cpp:47
bool error(const char *fmt, const Args &... args)
Definition: system.h:59
static constexpr uint8_t PSBT_MAGIC_BYTES[5]
Definition: psbt.h:18
PartiallySignedTransaction(const PartiallySignedTransaction &psbt_in)
Definition: psbt.h:398
Definition: transaction.h:133