Merge rust-bitcoin/rust-bitcoin#4040: primitives: store transaction::Version as u32 instead of i32

0acd2b5e89 primitives: store transaction::Version as u32 instead of i32 (Andrew Toth)

Pull request description:

  Closes #4039.

ACKs for top commit:
  Kixunil:
    ACK 0acd2b5e89
  apoelstra:
    ACK 0acd2b5e894246d0b0cf7f78bb820a8940c41c26; successfully ran local tests

Tree-SHA512: 8e207c77eec3db3ab85de842ab03ac8692ac66f0359121fbc736068b8f7ce66ef3049ad0be53a534cba08d32ea62e76a624ca2713dd5b8b6f115fd51826a81ce
This commit is contained in:
merge-script 2025-02-12 20:36:23 +00:00
commit 58bb2b1200
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
2 changed files with 5 additions and 11 deletions

View File

@ -631,7 +631,7 @@ crate::internal_macros::define_extension_trait! {
/// Extension functionality for the [`Version`] type. /// Extension functionality for the [`Version`] type.
pub trait VersionExt impl for Version { pub trait VersionExt impl for Version {
/// Constructs a new non-standard transaction version. /// Constructs a new non-standard transaction version.
fn non_standard(version: i32) -> Version { Self(version) } fn non_standard(version: u32) -> Version { Self(version) }
/// Returns true if this transaction version number is considered standard. /// Returns true if this transaction version number is considered standard.
fn is_standard(&self) -> bool { *self == Version::ONE || *self == Version::TWO || *self == Version::THREE } fn is_standard(&self) -> bool { *self == Version::ONE || *self == Version::TWO || *self == Version::THREE }
@ -1369,17 +1369,11 @@ mod tests {
#[test] #[test]
fn transaction_version() { fn transaction_version() {
let tx_bytes = hex!("ffffff7f0100000000000000000000000000000000000000000000000000000000000000000000000000ffffffff0100f2052a01000000434104678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5fac00000000"); let tx_bytes = hex!("ffffffff0100000000000000000000000000000000000000000000000000000000000000000000000000ffffffff0100f2052a01000000434104678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5fac00000000");
let tx: Result<Transaction, _> = deserialize(&tx_bytes); let tx: Result<Transaction, _> = deserialize(&tx_bytes);
assert!(tx.is_ok()); assert!(tx.is_ok());
let realtx = tx.unwrap(); let realtx = tx.unwrap();
assert_eq!(realtx.version, Version::non_standard(2147483647)); assert_eq!(realtx.version, Version::non_standard(u32::MAX));
let tx2_bytes = hex!("000000800100000000000000000000000000000000000000000000000000000000000000000000000000ffffffff0100f2052a01000000434104678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5fac00000000");
let tx2: Result<Transaction, _> = deserialize(&tx2_bytes);
assert!(tx2.is_ok());
let realtx2 = tx2.unwrap();
assert_eq!(realtx2.version, Version::non_standard(-2147483648));
} }
#[test] #[test]

View File

@ -510,7 +510,7 @@ impl Wtxid {
/// ///
/// Currently, as specified by [BIP-68] and [BIP-431], version 1, 2, and 3 are considered standard. /// Currently, as specified by [BIP-68] and [BIP-431], version 1, 2, and 3 are considered standard.
/// ///
/// Standardness of the inner `i32` is not an invariant because you are free to create transactions /// Standardness of the inner `u32` is not an invariant because you are free to create transactions
/// of any version, transactions with non-standard version numbers will not be relayed by the /// of any version, transactions with non-standard version numbers will not be relayed by the
/// Bitcoin network. /// Bitcoin network.
/// ///
@ -518,7 +518,7 @@ impl Wtxid {
/// [BIP-431]: https://github.com/bitcoin/bips/blob/master/bip-0431.mediawiki /// [BIP-431]: https://github.com/bitcoin/bips/blob/master/bip-0431.mediawiki
#[derive(Copy, PartialEq, Eq, Clone, Debug, PartialOrd, Ord, Hash)] #[derive(Copy, PartialEq, Eq, Clone, Debug, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Version(pub i32); pub struct Version(pub u32);
impl Version { impl Version {
/// The original Bitcoin transaction version (pre-BIP-68). /// The original Bitcoin transaction version (pre-BIP-68).