aboutsummaryrefslogtreecommitdiff
path: root/src/psbt.h
diff options
context:
space:
mode:
authorAndrew Chow <achow101-github@achow101.com>2019-10-02 15:49:33 -0400
committerAndrew Chow <achow101-github@achow101.com>2021-12-10 08:29:24 -0500
commit3235847473e36070cbe9b0e9deacdd8d8d9428fe (patch)
treef3ce3a785b7d5f147e35a2ec8005fcb1adf301b4 /src/psbt.h
parent65b49f60a4cf521889297b2006f66efa11d769c5 (diff)
downloadbitcoin-3235847473e36070cbe9b0e9deacdd8d8d9428fe.tar.xz
Types are compact size uints
Diffstat (limited to 'src/psbt.h')
-rw-r--r--src/psbt.h41
1 files changed, 22 insertions, 19 deletions
diff --git a/src/psbt.h b/src/psbt.h
index 21daa050ea..a752e99e74 100644
--- a/src/psbt.h
+++ b/src/psbt.h
@@ -69,52 +69,52 @@ struct PSBTInput
inline void Serialize(Stream& s) const {
// Write the utxo
if (non_witness_utxo) {
- SerializeToVector(s, PSBT_IN_NON_WITNESS_UTXO);
+ SerializeToVector(s, CompactSizeWriter(PSBT_IN_NON_WITNESS_UTXO));
OverrideStream<Stream> os(&s, s.GetType(), s.GetVersion() | SERIALIZE_TRANSACTION_NO_WITNESS);
SerializeToVector(os, non_witness_utxo);
}
if (!witness_utxo.IsNull()) {
- SerializeToVector(s, PSBT_IN_WITNESS_UTXO);
+ SerializeToVector(s, CompactSizeWriter(PSBT_IN_WITNESS_UTXO));
SerializeToVector(s, witness_utxo);
}
if (final_script_sig.empty() && final_script_witness.IsNull()) {
// Write any partial signatures
for (auto sig_pair : partial_sigs) {
- SerializeToVector(s, PSBT_IN_PARTIAL_SIG, Span{sig_pair.second.first});
+ SerializeToVector(s, CompactSizeWriter(PSBT_IN_PARTIAL_SIG), Span{sig_pair.second.first});
s << sig_pair.second.second;
}
// Write the sighash type
if (sighash_type != std::nullopt) {
- SerializeToVector(s, PSBT_IN_SIGHASH);
+ SerializeToVector(s, CompactSizeWriter(PSBT_IN_SIGHASH));
SerializeToVector(s, *sighash_type);
}
// Write the redeem script
if (!redeem_script.empty()) {
- SerializeToVector(s, PSBT_IN_REDEEMSCRIPT);
+ SerializeToVector(s, CompactSizeWriter(PSBT_IN_REDEEMSCRIPT));
s << redeem_script;
}
// Write the witness script
if (!witness_script.empty()) {
- SerializeToVector(s, PSBT_IN_WITNESSSCRIPT);
+ SerializeToVector(s, CompactSizeWriter(PSBT_IN_WITNESSSCRIPT));
s << witness_script;
}
// Write any hd keypaths
- SerializeHDKeypaths(s, hd_keypaths, PSBT_IN_BIP32_DERIVATION);
+ SerializeHDKeypaths(s, hd_keypaths, CompactSizeWriter(PSBT_IN_BIP32_DERIVATION));
}
// Write script sig
if (!final_script_sig.empty()) {
- SerializeToVector(s, PSBT_IN_SCRIPTSIG);
+ SerializeToVector(s, CompactSizeWriter(PSBT_IN_SCRIPTSIG));
s << final_script_sig;
}
// write script witness
if (!final_script_witness.IsNull()) {
- SerializeToVector(s, PSBT_IN_SCRIPTWITNESS);
+ SerializeToVector(s, CompactSizeWriter(PSBT_IN_SCRIPTWITNESS));
SerializeToVector(s, final_script_witness.stack);
}
@@ -147,8 +147,9 @@ struct PSBTInput
break;
}
- // First byte of key is the type
- unsigned char type = key[0];
+ // Type is compact size uint at beginning of key
+ SpanReader skey(s.GetType(), s.GetVersion(), key);
+ uint64_t type = ReadCompactSize(skey);
// Do stuff based on type
switch(type) {
@@ -292,18 +293,18 @@ struct PSBTOutput
inline void Serialize(Stream& s) const {
// Write the redeem script
if (!redeem_script.empty()) {
- SerializeToVector(s, PSBT_OUT_REDEEMSCRIPT);
+ SerializeToVector(s, CompactSizeWriter(PSBT_OUT_REDEEMSCRIPT));
s << redeem_script;
}
// Write the witness script
if (!witness_script.empty()) {
- SerializeToVector(s, PSBT_OUT_WITNESSSCRIPT);
+ SerializeToVector(s, CompactSizeWriter(PSBT_OUT_WITNESSSCRIPT));
s << witness_script;
}
// Write any hd keypaths
- SerializeHDKeypaths(s, hd_keypaths, PSBT_OUT_BIP32_DERIVATION);
+ SerializeHDKeypaths(s, hd_keypaths, CompactSizeWriter(PSBT_OUT_BIP32_DERIVATION));
// Write unknown things
for (auto& entry : unknown) {
@@ -334,8 +335,9 @@ struct PSBTOutput
break;
}
- // First byte of key is the type
- unsigned char type = key[0];
+ // Type is compact size uint at beginning of key
+ SpanReader skey(s.GetType(), s.GetVersion(), key);
+ uint64_t type = ReadCompactSize(skey);
// Do stuff based on type
switch(type) {
@@ -422,7 +424,7 @@ struct PartiallySignedTransaction
s << PSBT_MAGIC_BYTES;
// unsigned tx flag
- SerializeToVector(s, PSBT_GLOBAL_UNSIGNED_TX);
+ SerializeToVector(s, CompactSizeWriter(PSBT_GLOBAL_UNSIGNED_TX));
// Write serialized tx to a stream
OverrideStream<Stream> os(&s, s.GetType(), s.GetVersion() | SERIALIZE_TRANSACTION_NO_WITNESS);
@@ -474,8 +476,9 @@ struct PartiallySignedTransaction
break;
}
- // First byte of key is the type
- unsigned char type = key[0];
+ // Type is compact size uint at beginning of key
+ SpanReader skey(s.GetType(), s.GetVersion(), key);
+ uint64_t type = ReadCompactSize(skey);
// Do stuff based on type
switch(type) {