Add segwit serialization constants

One of our stated aims is to make it possible to learn bitcoin by using
our library. To help with this aim add to private consts for the segwit
transaction marker and flag serialization fields.
This commit is contained in:
Tobin C. Harding 2023-09-18 03:54:49 +10:00
parent 141d805ddc
commit 29f20c1d0b
No known key found for this signature in database
GPG Key ID: 40BF9E4C269D6607
1 changed files with 7 additions and 2 deletions

View File

@ -36,6 +36,11 @@ use crate::sighash::{EcdsaSighashType, TapSighashType};
use crate::string::FromHexStr; use crate::string::FromHexStr;
use crate::{io, Amount, VarInt}; use crate::{io, Amount, VarInt};
/// The marker MUST be a 1-byte zero value: 0x00. (BIP-141)
const SEGWIT_MARKER: u8 = 0x00;
/// The flag MUST be a 1-byte non-zero value. Currently, 0x01 MUST be used. (BIP-141)
const SEGWIT_FLAG: u8 = 0x01;
/// A reference to a transaction output. /// A reference to a transaction output.
/// ///
/// ### Bitcoin Core References /// ### Bitcoin Core References
@ -1021,8 +1026,8 @@ impl Encodable for Transaction {
len += self.input.consensus_encode(w)?; len += self.input.consensus_encode(w)?;
len += self.output.consensus_encode(w)?; len += self.output.consensus_encode(w)?;
} else { } else {
len += 0u8.consensus_encode(w)?; len += SEGWIT_MARKER.consensus_encode(w)?;
len += 1u8.consensus_encode(w)?; len += SEGWIT_FLAG.consensus_encode(w)?;
len += self.input.consensus_encode(w)?; len += self.input.consensus_encode(w)?;
len += self.output.consensus_encode(w)?; len += self.output.consensus_encode(w)?;
for input in &self.input { for input in &self.input {