mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-09 10:43:19 -05:00
Serialize non-witness utxo as a non-witness tx but always deserialize as witness
Strip out the witnesses when serializing the non-witness utxo. However witness serializations are allowed, so make sure we always deserialize as witness.
This commit is contained in:
parent
43811e6338
commit
bd19cc78cf
1 changed files with 7 additions and 2 deletions
|
@ -223,7 +223,8 @@ struct PSBTInput
|
||||||
// If there is a non-witness utxo, then don't add the witness one.
|
// If there is a non-witness utxo, then don't add the witness one.
|
||||||
if (non_witness_utxo) {
|
if (non_witness_utxo) {
|
||||||
SerializeToVector(s, PSBT_IN_NON_WITNESS_UTXO);
|
SerializeToVector(s, PSBT_IN_NON_WITNESS_UTXO);
|
||||||
SerializeToVector(s, non_witness_utxo);
|
OverrideStream<Stream> os(&s, s.GetType(), s.GetVersion() | SERIALIZE_TRANSACTION_NO_WITNESS);
|
||||||
|
SerializeToVector(os, non_witness_utxo);
|
||||||
} else if (!witness_utxo.IsNull()) {
|
} else if (!witness_utxo.IsNull()) {
|
||||||
SerializeToVector(s, PSBT_IN_WITNESS_UTXO);
|
SerializeToVector(s, PSBT_IN_WITNESS_UTXO);
|
||||||
SerializeToVector(s, witness_utxo);
|
SerializeToVector(s, witness_utxo);
|
||||||
|
@ -297,13 +298,17 @@ struct PSBTInput
|
||||||
// Do stuff based on type
|
// Do stuff based on type
|
||||||
switch(type) {
|
switch(type) {
|
||||||
case PSBT_IN_NON_WITNESS_UTXO:
|
case PSBT_IN_NON_WITNESS_UTXO:
|
||||||
|
{
|
||||||
if (non_witness_utxo) {
|
if (non_witness_utxo) {
|
||||||
throw std::ios_base::failure("Duplicate Key, input non-witness utxo already provided");
|
throw std::ios_base::failure("Duplicate Key, input non-witness utxo already provided");
|
||||||
} else if (key.size() != 1) {
|
} else if (key.size() != 1) {
|
||||||
throw std::ios_base::failure("Non-witness utxo key is more than one byte type");
|
throw std::ios_base::failure("Non-witness utxo key is more than one byte type");
|
||||||
}
|
}
|
||||||
UnserializeFromVector(s, non_witness_utxo);
|
// Set the stream to unserialize with witness since this is always a valid network transaction
|
||||||
|
OverrideStream<Stream> os(&s, s.GetType(), s.GetVersion() & ~SERIALIZE_TRANSACTION_NO_WITNESS);
|
||||||
|
UnserializeFromVector(os, non_witness_utxo);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case PSBT_IN_WITNESS_UTXO:
|
case PSBT_IN_WITNESS_UTXO:
|
||||||
if (!witness_utxo.IsNull()) {
|
if (!witness_utxo.IsNull()) {
|
||||||
throw std::ios_base::failure("Duplicate Key, input witness utxo already provided");
|
throw std::ios_base::failure("Duplicate Key, input witness utxo already provided");
|
||||||
|
|
Loading…
Add table
Reference in a new issue