Merge rust-bitcoin/rust-bitcoin#3711: primitives: Reduce alloc requirements
6ae35be0db
primitives: Reduce alloc requirements (Tobin C. Harding)
Pull request description:
Recently we reduced the `alloc` requirements in `units` but we did not propagate these changes up to `primitives`.
Remove a bunch of `alloc` feature gating from `primitives`.
ACKs for top commit:
apoelstra:
ACK 6ae35be0db84d2bf79ffe0cd63d616a55c036b12; successfully ran local tests; nice!
Tree-SHA512: a49076a72b81a68f7e0e03c452eb5490dcc69136b15834577ba10ec71767080cf74fd443e2668f008814ed677d4ee6b45972f6f52b78b8eb793e05780d10a2ec
This commit is contained in:
commit
e7efdd7c42
|
@ -31,7 +31,6 @@ extern crate std;
|
||||||
extern crate serde;
|
extern crate serde;
|
||||||
|
|
||||||
pub mod block;
|
pub mod block;
|
||||||
#[cfg(feature = "alloc")]
|
|
||||||
pub mod locktime;
|
pub mod locktime;
|
||||||
pub mod merkle_tree;
|
pub mod merkle_tree;
|
||||||
pub mod opcodes;
|
pub mod opcodes;
|
||||||
|
@ -45,10 +44,8 @@ pub mod transaction;
|
||||||
pub mod witness;
|
pub mod witness;
|
||||||
|
|
||||||
#[doc(inline)]
|
#[doc(inline)]
|
||||||
pub use units::amount::{self, Amount, SignedAmount};
|
|
||||||
#[doc(inline)]
|
|
||||||
#[cfg(feature = "alloc")]
|
|
||||||
pub use units::{
|
pub use units::{
|
||||||
|
amount::{self, Amount, SignedAmount},
|
||||||
block::{BlockHeight, BlockInterval},
|
block::{BlockHeight, BlockInterval},
|
||||||
fee_rate::{self, FeeRate},
|
fee_rate::{self, FeeRate},
|
||||||
weight::{self, Weight},
|
weight::{self, Weight},
|
||||||
|
@ -60,13 +57,13 @@ pub use self::{
|
||||||
block::{
|
block::{
|
||||||
Block, Checked as BlockChecked, Unchecked as BlockUnchecked, Validation as BlockValidation,
|
Block, Checked as BlockChecked, Unchecked as BlockUnchecked, Validation as BlockValidation,
|
||||||
},
|
},
|
||||||
locktime::{absolute, relative},
|
|
||||||
transaction::{Transaction, TxIn, TxOut},
|
transaction::{Transaction, TxIn, TxOut},
|
||||||
witness::Witness,
|
witness::Witness,
|
||||||
};
|
};
|
||||||
#[doc(inline)]
|
#[doc(inline)]
|
||||||
pub use self::{
|
pub use self::{
|
||||||
block::{BlockHash, Header as BlockHeader, WitnessCommitment},
|
block::{BlockHash, Header as BlockHeader, WitnessCommitment},
|
||||||
|
locktime::{absolute, relative},
|
||||||
merkle_tree::{TxMerkleNode, WitnessMerkleNode},
|
merkle_tree::{TxMerkleNode, WitnessMerkleNode},
|
||||||
pow::CompactTarget,
|
pow::CompactTarget,
|
||||||
sequence::Sequence,
|
sequence::Sequence,
|
||||||
|
|
|
@ -20,12 +20,9 @@ use core::fmt;
|
||||||
use arbitrary::{Arbitrary, Unstructured};
|
use arbitrary::{Arbitrary, Unstructured};
|
||||||
#[cfg(feature = "serde")]
|
#[cfg(feature = "serde")]
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
#[cfg(feature = "alloc")]
|
|
||||||
use units::locktime::relative::TimeOverflowError;
|
use units::locktime::relative::TimeOverflowError;
|
||||||
#[cfg(feature = "alloc")]
|
|
||||||
use units::parse::{self, PrefixedHexError, UnprefixedHexError};
|
use units::parse::{self, PrefixedHexError, UnprefixedHexError};
|
||||||
|
|
||||||
#[cfg(feature = "alloc")]
|
|
||||||
use crate::locktime::relative;
|
use crate::locktime::relative;
|
||||||
#[cfg(all(doc, feature = "alloc"))]
|
#[cfg(all(doc, feature = "alloc"))]
|
||||||
use crate::transaction::Transaction;
|
use crate::transaction::Transaction;
|
||||||
|
@ -127,14 +124,12 @@ impl Sequence {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Constructs a new `Sequence` from a prefixed hex string.
|
/// Constructs a new `Sequence` from a prefixed hex string.
|
||||||
#[cfg(feature = "alloc")]
|
|
||||||
pub fn from_hex(s: &str) -> Result<Self, PrefixedHexError> {
|
pub fn from_hex(s: &str) -> Result<Self, PrefixedHexError> {
|
||||||
let lock_time = parse::hex_u32_prefixed(s)?;
|
let lock_time = parse::hex_u32_prefixed(s)?;
|
||||||
Ok(Self::from_consensus(lock_time))
|
Ok(Self::from_consensus(lock_time))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Constructs a new `Sequence` from an unprefixed hex string.
|
/// Constructs a new `Sequence` from an unprefixed hex string.
|
||||||
#[cfg(feature = "alloc")]
|
|
||||||
pub fn from_unprefixed_hex(s: &str) -> Result<Self, UnprefixedHexError> {
|
pub fn from_unprefixed_hex(s: &str) -> Result<Self, UnprefixedHexError> {
|
||||||
let lock_time = parse::hex_u32_unprefixed(s)?;
|
let lock_time = parse::hex_u32_unprefixed(s)?;
|
||||||
Ok(Self::from_consensus(lock_time))
|
Ok(Self::from_consensus(lock_time))
|
||||||
|
@ -158,7 +153,6 @@ impl Sequence {
|
||||||
///
|
///
|
||||||
/// Will return an error if the input cannot be encoded in 16 bits.
|
/// Will return an error if the input cannot be encoded in 16 bits.
|
||||||
#[inline]
|
#[inline]
|
||||||
#[cfg(feature = "alloc")]
|
|
||||||
pub fn from_seconds_floor(seconds: u32) -> Result<Self, TimeOverflowError> {
|
pub fn from_seconds_floor(seconds: u32) -> Result<Self, TimeOverflowError> {
|
||||||
if let Ok(interval) = u16::try_from(seconds / 512) {
|
if let Ok(interval) = u16::try_from(seconds / 512) {
|
||||||
Ok(Sequence::from_512_second_intervals(interval))
|
Ok(Sequence::from_512_second_intervals(interval))
|
||||||
|
@ -172,7 +166,6 @@ impl Sequence {
|
||||||
///
|
///
|
||||||
/// Will return an error if the input cannot be encoded in 16 bits.
|
/// Will return an error if the input cannot be encoded in 16 bits.
|
||||||
#[inline]
|
#[inline]
|
||||||
#[cfg(feature = "alloc")]
|
|
||||||
pub fn from_seconds_ceil(seconds: u32) -> Result<Self, TimeOverflowError> {
|
pub fn from_seconds_ceil(seconds: u32) -> Result<Self, TimeOverflowError> {
|
||||||
if let Ok(interval) = u16::try_from((seconds + 511) / 512) {
|
if let Ok(interval) = u16::try_from((seconds + 511) / 512) {
|
||||||
Ok(Sequence::from_512_second_intervals(interval))
|
Ok(Sequence::from_512_second_intervals(interval))
|
||||||
|
@ -191,7 +184,6 @@ impl Sequence {
|
||||||
|
|
||||||
/// Constructs a new [`relative::LockTime`] from this [`Sequence`] number.
|
/// Constructs a new [`relative::LockTime`] from this [`Sequence`] number.
|
||||||
#[inline]
|
#[inline]
|
||||||
#[cfg(feature = "alloc")]
|
|
||||||
pub fn to_relative_lock_time(&self) -> Option<relative::LockTime> {
|
pub fn to_relative_lock_time(&self) -> Option<relative::LockTime> {
|
||||||
use crate::locktime::relative::{Height, LockTime, Time};
|
use crate::locktime::relative::{Height, LockTime, Time};
|
||||||
|
|
||||||
|
@ -211,7 +203,6 @@ impl Sequence {
|
||||||
/// Returns the low 16 bits from sequence number.
|
/// Returns the low 16 bits from sequence number.
|
||||||
///
|
///
|
||||||
/// BIP-68 only uses the low 16 bits for relative lock value.
|
/// BIP-68 only uses the low 16 bits for relative lock value.
|
||||||
#[cfg(feature = "alloc")]
|
|
||||||
fn low_u16(&self) -> u16 { self.0 as u16 }
|
fn low_u16(&self) -> u16 { self.0 as u16 }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue