Add to/from_consensus methods to Version type
The `Version` type uses a signed 32 bit integer inner type but we bit twiddle as if it was a `u32`. We recently made the inner type private to hide the data type because of this oddness. Add methods `from_consensus` and `to_consensus` to facilitate any possible thing users may want to do with a consensus version value.
This commit is contained in:
parent
24984f095f
commit
832169eb8d
|
@ -132,6 +132,20 @@ impl Version {
|
||||||
/// The value has the top three bits `001` which enables the use of version bits to signal for soft forks.
|
/// The value has the top three bits `001` which enables the use of version bits to signal for soft forks.
|
||||||
const USE_VERSION_BITS: u32 = 0x2000_0000;
|
const USE_VERSION_BITS: u32 = 0x2000_0000;
|
||||||
|
|
||||||
|
/// Creates a [`Version`] from a signed 32 bit integer value.
|
||||||
|
///
|
||||||
|
/// This is the data type used in consensus code in Bitcoin Core.
|
||||||
|
pub fn from_consensus(v: i32) -> Self {
|
||||||
|
Version(v)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns the inner `i32` value.
|
||||||
|
///
|
||||||
|
/// This is the data type used in consensus code in Bitcoin Core.
|
||||||
|
pub fn to_consensus(self) -> i32 {
|
||||||
|
self.0
|
||||||
|
}
|
||||||
|
|
||||||
/// Check whether the version number is signalling a soft fork at the given bit.
|
/// Check whether the version number is signalling a soft fork at the given bit.
|
||||||
///
|
///
|
||||||
/// A block is signalling for a soft fork under BIP-9 if the first 3 bits are `001` and
|
/// A block is signalling for a soft fork under BIP-9 if the first 3 bits are `001` and
|
||||||
|
|
Loading…
Reference in New Issue