 |
Bitcoin Core
21.99.0
P2P Digital Currency
|
Go to the documentation of this file.
59 std::map<std::vector<unsigned char>, std::vector<unsigned char>>
unknown;
68 template <
typename Stream>
85 s << sig_pair.second.second;
131 template <
typename Stream>
134 std::set<std::vector<unsigned char>> key_lookup;
137 bool found_sep =
false;
140 std::vector<unsigned char> key;
151 unsigned char type = key[0];
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");
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");
179 throw std::ios_base::failure(
"Size of key was not the expected size for the type partial signature pubkey");
182 CPubKey pubkey(key.begin() + 1, key.end());
184 throw std::ios_base::failure(
"Invalid pubkey");
187 throw std::ios_base::failure(
"Duplicate Key, input partial signature for pubkey already provided");
191 std::vector<unsigned char> sig;
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");
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");
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");
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");
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");
254 throw std::ios_base::failure(
"Duplicate Key, key for unknown value already provided");
257 std::vector<unsigned char> val_bytes;
259 unknown.emplace(std::move(key), std::move(val_bytes));
265 throw std::ios_base::failure(
"Separator is missing at the end of an input map");
269 template <
typename Stream>
281 std::map<std::vector<unsigned char>, std::vector<unsigned char>>
unknown;
289 template <
typename Stream>
316 template <
typename Stream>
319 std::set<std::vector<unsigned char>> key_lookup;
322 bool found_sep =
false;
325 std::vector<unsigned char> key;
336 unsigned char type = key[0];
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");
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");
368 throw std::ios_base::failure(
"Duplicate Key, key for unknown value already provided");
371 std::vector<unsigned char> val_bytes;
373 unknown.emplace(std::move(key), std::move(val_bytes));
380 throw std::ios_base::failure(
"Separator is missing at the end of an output map");
384 template <
typename Stream>
393 std::optional<CMutableTransaction>
tx;
396 std::map<std::vector<unsigned char>, std::vector<unsigned char>>
unknown;
416 template <
typename Stream>
449 template <
typename Stream>
455 throw std::ios_base::failure(
"Invalid PSBT magic bytes");
459 std::set<std::vector<unsigned char>> key_lookup;
462 bool found_sep =
false;
465 std::vector<unsigned char> key;
476 unsigned char type = key[0];
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");
493 for (
const CTxIn& txin :
tx->vin) {
495 throw std::ios_base::failure(
"Unsigned tx does not have empty scriptSigs and scriptWitnesses.");
503 throw std::ios_base::failure(
"Duplicate Key, key for unknown value already provided");
506 std::vector<unsigned char> val_bytes;
508 unknown.emplace(std::move(key), std::move(val_bytes));
514 throw std::ios_base::failure(
"Separator is missing at the end of the global map");
519 throw std::ios_base::failure(
"No unsigned transcation was provided");
524 while (!s.empty() && i < tx->vin.size()) {
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");
536 if (
inputs.size() !=
tx->vin.size()) {
537 throw std::ios_base::failure(
"Inputs provided does not match the number of inputs in transaction.");
542 while (!s.empty() && i < tx->vout.size()) {
550 throw std::ios_base::failure(
"Outputs provided does not match the number of outputs in transaction.");
554 template <
typename Stream>
616 #endif // BITCOIN_PSBT_H
An input of a transaction.
Dummy data type to identify deserializing constructors.
static constexpr uint8_t PSBT_IN_SCRIPTWITNESS
bool DecodeRawPSBT(PartiallySignedTransaction &decoded_psbt, const std::string &raw_psbt, std::string &error)
Decode a raw (binary blob) PSBT into a PartiallySignedTransaction.
bool FinalizePSBT(PartiallySignedTransaction &psbtx)
Finalizes a PSBT if possible, combining partial signatures.
void FillSignatureData(SignatureData &sigdata) 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...
static constexpr unsigned int SIZE
secp256k1:
static constexpr uint8_t PSBT_IN_REDEEMSCRIPT
std::vector< PSBTInput > inputs
bool AddInput(const CTxIn &txin, PSBTInput &psbtin)
static constexpr uint8_t PSBT_GLOBAL_UNSIGNED_TX
An interface to be implemented by keystores that support signing.
void Unserialize(Stream &s)
static constexpr uint8_t PSBT_IN_NON_WITNESS_UTXO
bool PSBTInputSigned(const PSBTInput &input)
Checks whether a PSBTInput is already signed.
std::shared_ptr< const CTransaction > CTransactionRef
PSBTOutput(deserialize_type, Stream &s)
static constexpr uint8_t PSBT_IN_SIGHASH
void UpdatePSBTOutput(const SigningProvider &provider, PartiallySignedTransaction &psbt, int index)
Updates a PSBTOutput with information from provider.
bool DecodeBase64PSBT(PartiallySignedTransaction &decoded_psbt, const std::string &base64_psbt, std::string &error)
Decode a base64ed PSBT into a PartiallySignedTransaction.
CScriptWitness scriptWitness
Only serialized through CTransaction.
std::pair< CPubKey, std::vector< unsigned char > > SigPair
static constexpr uint8_t PSBT_MAGIC_BYTES[5]
PartiallySignedTransaction()
bool Merge(const PartiallySignedTransaction &psbt)
Merge psbt into this.
An output of a transaction.
void Unserialize(Stream &s)
static constexpr uint8_t PSBT_IN_PARTIAL_SIG
bool GetInputUTXO(CTxOut &utxo, int input_index) const
Finds the UTXO for a given input index.
std::string PSBTRoleName(PSBTRole role)
void UnserializeFromVector(Stream &s, X &... args)
static constexpr uint8_t PSBT_IN_WITNESS_UTXO
std::optional< CMutableTransaction > tx
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...
A structure for PSBTs which contains per output information.
static constexpr unsigned int COMPRESSED_SIZE
static constexpr uint8_t PSBT_OUT_BIP32_DERIVATION
Serialized script, used inside transaction inputs and outputs.
bool AddOutput(const CTxOut &txout, const PSBTOutput &psbtout)
static constexpr uint8_t PSBT_IN_BIP32_DERIVATION
size_t CountPSBTUnsignedInputs(const PartiallySignedTransaction &psbt)
Counts the unsigned inputs of a PSBT.
void DeserializeHDKeypaths(Stream &s, const std::vector< unsigned char > &key, std::map< CPubKey, KeyOriginInfo > &hd_keypaths)
bool FinalizeAndExtractPSBT(PartiallySignedTransaction &psbtx, CMutableTransaction &result)
Finalizes a PSBT if possible, and extracts it to a CMutableTransaction if it could be finalized.
static constexpr uint8_t PSBT_IN_SCRIPTSIG
void Merge(const PSBTOutput &output)
An encapsulated public key.
static constexpr uint8_t PSBT_OUT_WITNESSSCRIPT
A version of CTransaction with the PSBT format.
void Serialize(Stream &s) const
static constexpr uint8_t PSBT_OUT_REDEEMSCRIPT
std::vector< PSBTOutput > outputs
bool IsFullyValid() const
fully validate whether this is a valid public key (more expensive than IsValid())
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.
PartiallySignedTransaction(deserialize_type, Stream &s)
const std::streamsize MAX_FILE_SIZE_PSBT
static constexpr uint8_t PSBT_SEPARATOR
void SerializeToVector(Stream &s, const X &... args)
bool error(const char *fmt, const Args &... args)
A mutable version of CTransaction.
void FromSignatureData(const SignatureData &sigdata)
constexpr Span< A > MakeSpan(A(&a)[N])
MakeSpan for arrays:
std::map< CPubKey, KeyOriginInfo > hd_keypaths
void Serialize(Stream &s) const
std::vector< std::vector< unsigned char > > stack
static constexpr uint8_t PSBT_IN_WITNESSSCRIPT
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
std::map< std::vector< unsigned char >, std::vector< unsigned char > > unknown
std::map< std::vector< unsigned char >, std::vector< unsigned char > > unknown
void SerializeHDKeypaths(Stream &s, const std::map< CPubKey, KeyOriginInfo > &hd_keypaths, uint8_t type)