From e9f1f11c2ce6512aae7f9b5918179e48970f6542 Mon Sep 17 00:00:00 2001 From: Braydon Fuller Date: Mon, 17 Aug 2020 10:28:33 -0700 Subject: [PATCH] Transaction and header version is signed int --- src/blockdata/block.rs | 3 +-- src/blockdata/transaction.rs | 7 +++---- src/util/bip143.rs | 2 +- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/blockdata/block.rs b/src/blockdata/block.rs index 5a415594..989201db 100644 --- a/src/blockdata/block.rs +++ b/src/blockdata/block.rs @@ -37,7 +37,7 @@ use VarInt; #[derive(Copy, PartialEq, Eq, Clone, Debug)] pub struct BlockHeader { /// The protocol version. Should always be 1. - pub version: u32, + pub version: i32, /// Reference to the previous block in the chain pub prev_blockhash: BlockHash, /// The root hash of the merkle tree of transactions in the block @@ -320,4 +320,3 @@ mod tests { assert_eq!(header.bits, BlockHeader::compact_target_from_u256(&header.target())); } } - diff --git a/src/blockdata/transaction.rs b/src/blockdata/transaction.rs index 6b091f82..bc9cd2fb 100644 --- a/src/blockdata/transaction.rs +++ b/src/blockdata/transaction.rs @@ -260,7 +260,7 @@ impl Default for TxOut { #[derive(Clone, PartialEq, Eq, Debug, Hash)] pub struct Transaction { /// The protocol version, is currently expected to be 1 or 2 (BIP 68). - pub version: u32, + pub version: i32, /// Block number before which this transaction is valid, or 0 for /// valid immediately. pub lock_time: u32, @@ -531,7 +531,7 @@ impl Encodable for Transaction { impl Decodable for Transaction { fn consensus_decode(mut d: D) -> Result { - let version = u32::consensus_decode(&mut d)?; + let version = i32::consensus_decode(&mut d)?; let input = Vec::::consensus_decode(&mut d)?; // segwit if input.is_empty() { @@ -662,7 +662,7 @@ mod tests { Err(ParseOutPointError::Txid(Txid::from_hex("5df6e0e2761359d30a8275058e299fcc0381534545f55cf43e41983f5d4c945X").unwrap_err()))); assert_eq!(OutPoint::from_str("5df6e0e2761359d30a8275058e299fcc0381534545f55cf43e41983f5d4c9456:lol"), Err(ParseOutPointError::Vout(u32::from_str("lol").unwrap_err()))); - + assert_eq!(OutPoint::from_str("5df6e0e2761359d30a8275058e299fcc0381534545f55cf43e41983f5d4c9456:42"), Ok(OutPoint{ txid: Txid::from_hex("5df6e0e2761359d30a8275058e299fcc0381534545f55cf43e41983f5d4c9456").unwrap(), @@ -1229,4 +1229,3 @@ mod tests { } } } - diff --git a/src/util/bip143.rs b/src/util/bip143.rs index 8b805e61..59e36961 100644 --- a/src/util/bip143.rs +++ b/src/util/bip143.rs @@ -30,7 +30,7 @@ use consensus::encode::Encodable; #[derive(Clone, PartialEq, Eq, Debug)] #[deprecated(since="0.24.0", note="please use `SigHashCache` instead")] pub struct SighashComponents { - tx_version: u32, + tx_version: i32, tx_locktime: u32, /// Hash of all the previous outputs pub hash_prevouts: SigHash,