Skip to content

Commit

Permalink
Change method return type
Browse files Browse the repository at this point in the history
Both SignedAmount and Amount now have the same range.  That is, MIN/MAX
of both SignedAmount and Amount are the same.  Therefore conversion
between the two can no longer fail due to a difference in range.  This
change removes this range check since it's obsolete.
  • Loading branch information
yancyribbens committed Dec 14, 2024
1 parent 834010d commit 9d70d38
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 82 deletions.
17 changes: 6 additions & 11 deletions api/units/all-features.txt
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,11 @@ impl core::convert::TryFrom<alloc::string::String> for bitcoin_units::locktime::
impl core::convert::TryFrom<alloc::string::String> for bitcoin_units::locktime::relative::Height
impl core::convert::TryFrom<alloc::string::String> for bitcoin_units::locktime::relative::Time
impl core::convert::TryFrom<alloc::string::String> for bitcoin_units::weight::Weight
impl core::convert::TryFrom<bitcoin_units::Amount> for bitcoin_units::SignedAmount
impl core::convert::TryFrom<bitcoin_units::SignedAmount> for bitcoin_units::Amount
impl core::convert::TryFrom<bitcoin_units::block::BlockHeight> for bitcoin_units::locktime::absolute::Height
impl core::convert::TryFrom<bitcoin_units::block::BlockInterval> for bitcoin_units::locktime::relative::Height
impl core::default::Default for bitcoin_units::Amount
impl core::default::Default for bitcoin_units::SignedAmount
impl core::default::Default for bitcoin_units::block::BlockInterval
impl core::default::Default for bitcoin_units::locktime::relative::Height
impl core::default::Default for bitcoin_units::locktime::relative::Time
impl core::error::Error for bitcoin_units::amount::error::InputTooLargeError
Expand Down Expand Up @@ -737,7 +736,6 @@ pub const fn bitcoin_units::weight::Weight::from_vb_unchecked(vb: u64) -> Self
pub const fn bitcoin_units::weight::Weight::from_vb_unwrap(vb: u64) -> bitcoin_units::weight::Weight
pub const fn bitcoin_units::weight::Weight::from_witness_data_size(witness_size: u64) -> Self
pub const fn bitcoin_units::weight::Weight::from_wu(wu: u64) -> Self
pub const fn bitcoin_units::weight::Weight::from_wu_usize(wu: usize) -> Self
pub const fn bitcoin_units::weight::Weight::to_kwu_floor(self) -> u64
pub const fn bitcoin_units::weight::Weight::to_vbytes_ceil(self) -> u64
pub const fn bitcoin_units::weight::Weight::to_vbytes_floor(self) -> u64
Expand Down Expand Up @@ -788,10 +786,9 @@ pub fn bitcoin_units::Amount::sum<I: core::iter::traits::iterator::Iterator<Item
pub fn bitcoin_units::Amount::sum<I>(iter: I) -> Self where I: core::iter::traits::iterator::Iterator<Item = &'a bitcoin_units::Amount>
pub fn bitcoin_units::Amount::to_btc(self) -> f64
pub fn bitcoin_units::Amount::to_float_in(self, denom: bitcoin_units::amount::Denomination) -> f64
pub fn bitcoin_units::Amount::to_signed(self) -> core::result::Result<bitcoin_units::SignedAmount, bitcoin_units::amount::error::OutOfRangeError>
pub fn bitcoin_units::Amount::to_signed(self) -> bitcoin_units::SignedAmount
pub fn bitcoin_units::Amount::to_string_in(self, denom: bitcoin_units::amount::Denomination) -> alloc::string::String
pub fn bitcoin_units::Amount::to_string_with_denomination(self, denom: bitcoin_units::amount::Denomination) -> alloc::string::String
pub fn bitcoin_units::Amount::try_from(value: bitcoin_units::SignedAmount) -> core::result::Result<Self, Self::Error>
pub fn bitcoin_units::Amount::type_prefix(_: private::Token) -> &'static str
pub fn bitcoin_units::Amount::unchecked_add(self, rhs: bitcoin_units::Amount) -> bitcoin_units::Amount
pub fn bitcoin_units::Amount::unchecked_sub(self, rhs: bitcoin_units::Amount) -> bitcoin_units::Amount
Expand Down Expand Up @@ -842,8 +839,7 @@ pub fn bitcoin_units::SignedAmount::to_btc(self) -> f64
pub fn bitcoin_units::SignedAmount::to_float_in(self, denom: bitcoin_units::amount::Denomination) -> f64
pub fn bitcoin_units::SignedAmount::to_string_in(self, denom: bitcoin_units::amount::Denomination) -> alloc::string::String
pub fn bitcoin_units::SignedAmount::to_string_with_denomination(self, denom: bitcoin_units::amount::Denomination) -> alloc::string::String
pub fn bitcoin_units::SignedAmount::to_unsigned(self) -> core::result::Result<bitcoin_units::Amount, bitcoin_units::amount::error::OutOfRangeError>
pub fn bitcoin_units::SignedAmount::try_from(value: bitcoin_units::Amount) -> core::result::Result<Self, Self::Error>
pub fn bitcoin_units::SignedAmount::to_unsigned(self) -> bitcoin_units::Amount
pub fn bitcoin_units::SignedAmount::type_prefix(_: private::Token) -> &'static str
pub fn bitcoin_units::SignedAmount::unchecked_add(self, rhs: bitcoin_units::SignedAmount) -> bitcoin_units::SignedAmount
pub fn bitcoin_units::SignedAmount::unchecked_sub(self, rhs: bitcoin_units::SignedAmount) -> bitcoin_units::SignedAmount
Expand Down Expand Up @@ -956,6 +952,7 @@ pub fn bitcoin_units::block::BlockInterval::add(self, rhs: bitcoin_units::block:
pub fn bitcoin_units::block::BlockInterval::add_assign(&mut self, rhs: bitcoin_units::block::BlockInterval)
pub fn bitcoin_units::block::BlockInterval::clone(&self) -> bitcoin_units::block::BlockInterval
pub fn bitcoin_units::block::BlockInterval::cmp(&self, other: &bitcoin_units::block::BlockInterval) -> core::cmp::Ordering
pub fn bitcoin_units::block::BlockInterval::default() -> bitcoin_units::block::BlockInterval
pub fn bitcoin_units::block::BlockInterval::deserialize<__D>(__deserializer: __D) -> core::result::Result<Self, <__D as serde::de::Deserializer>::Error> where __D: serde::de::Deserializer<'de>
pub fn bitcoin_units::block::BlockInterval::eq(&self, other: &bitcoin_units::block::BlockInterval) -> bool
pub fn bitcoin_units::block::BlockInterval::fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result
Expand Down Expand Up @@ -1191,17 +1188,15 @@ pub struct bitcoin_units::locktime::relative::TimeOverflowError
pub struct bitcoin_units::parse::PrefixedHexError(_)
pub struct bitcoin_units::parse::UnprefixedHexError(_)
pub struct bitcoin_units::weight::Weight(_)
pub trait bitcoin_units::amount::CheckedSum<R>: private::SumSeal<R>
pub trait bitcoin_units::amount::CheckedSum<R>: sealed::Sealed<R>
pub trait bitcoin_units::amount::serde::SerdeAmount: core::marker::Copy + core::marker::Sized
pub trait bitcoin_units::amount::serde::SerdeAmountForOpt: core::marker::Copy + core::marker::Sized + bitcoin_units::amount::serde::SerdeAmount
pub trait bitcoin_units::parse::Integer: core::str::traits::FromStr<Err = core::num::error::ParseIntError> + core::convert::TryFrom<i8> + core::marker::Sized
pub trait bitcoin_units::parse::Integer: core::str::traits::FromStr<Err = core::num::error::ParseIntError> + core::convert::TryFrom<i8> + core::marker::Sized + sealed::Sealed
pub type &bitcoin_units::fee_rate::FeeRate::Output = bitcoin_units::fee_rate::FeeRate
pub type bitcoin_units::Amount::Err = bitcoin_units::amount::error::ParseError
pub type bitcoin_units::Amount::Error = bitcoin_units::amount::error::OutOfRangeError
pub type bitcoin_units::Amount::Output = bitcoin_units::Amount
pub type bitcoin_units::Amount::Output = bitcoin_units::fee_rate::FeeRate
pub type bitcoin_units::SignedAmount::Err = bitcoin_units::amount::error::ParseError
pub type bitcoin_units::SignedAmount::Error = bitcoin_units::amount::error::OutOfRangeError
pub type bitcoin_units::SignedAmount::Output = bitcoin_units::SignedAmount
pub type bitcoin_units::amount::Denomination::Err = bitcoin_units::amount::error::ParseDenominationError
pub type bitcoin_units::block::BlockHeight::Err = bitcoin_units::parse::ParseIntError
Expand Down
17 changes: 6 additions & 11 deletions api/units/alloc-only.txt
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,11 @@ impl core::convert::TryFrom<alloc::string::String> for bitcoin_units::locktime::
impl core::convert::TryFrom<alloc::string::String> for bitcoin_units::locktime::relative::Height
impl core::convert::TryFrom<alloc::string::String> for bitcoin_units::locktime::relative::Time
impl core::convert::TryFrom<alloc::string::String> for bitcoin_units::weight::Weight
impl core::convert::TryFrom<bitcoin_units::Amount> for bitcoin_units::SignedAmount
impl core::convert::TryFrom<bitcoin_units::SignedAmount> for bitcoin_units::Amount
impl core::convert::TryFrom<bitcoin_units::block::BlockHeight> for bitcoin_units::locktime::absolute::Height
impl core::convert::TryFrom<bitcoin_units::block::BlockInterval> for bitcoin_units::locktime::relative::Height
impl core::default::Default for bitcoin_units::Amount
impl core::default::Default for bitcoin_units::SignedAmount
impl core::default::Default for bitcoin_units::block::BlockInterval
impl core::default::Default for bitcoin_units::locktime::relative::Height
impl core::default::Default for bitcoin_units::locktime::relative::Time
impl core::fmt::Debug for bitcoin_units::Amount
Expand Down Expand Up @@ -695,7 +694,6 @@ pub const fn bitcoin_units::weight::Weight::from_vb_unchecked(vb: u64) -> Self
pub const fn bitcoin_units::weight::Weight::from_vb_unwrap(vb: u64) -> bitcoin_units::weight::Weight
pub const fn bitcoin_units::weight::Weight::from_witness_data_size(witness_size: u64) -> Self
pub const fn bitcoin_units::weight::Weight::from_wu(wu: u64) -> Self
pub const fn bitcoin_units::weight::Weight::from_wu_usize(wu: usize) -> Self
pub const fn bitcoin_units::weight::Weight::to_kwu_floor(self) -> u64
pub const fn bitcoin_units::weight::Weight::to_vbytes_ceil(self) -> u64
pub const fn bitcoin_units::weight::Weight::to_vbytes_floor(self) -> u64
Expand Down Expand Up @@ -736,10 +734,9 @@ pub fn bitcoin_units::Amount::sum<I: core::iter::traits::iterator::Iterator<Item
pub fn bitcoin_units::Amount::sum<I>(iter: I) -> Self where I: core::iter::traits::iterator::Iterator<Item = &'a bitcoin_units::Amount>
pub fn bitcoin_units::Amount::to_btc(self) -> f64
pub fn bitcoin_units::Amount::to_float_in(self, denom: bitcoin_units::amount::Denomination) -> f64
pub fn bitcoin_units::Amount::to_signed(self) -> core::result::Result<bitcoin_units::SignedAmount, bitcoin_units::amount::error::OutOfRangeError>
pub fn bitcoin_units::Amount::to_signed(self) -> bitcoin_units::SignedAmount
pub fn bitcoin_units::Amount::to_string_in(self, denom: bitcoin_units::amount::Denomination) -> alloc::string::String
pub fn bitcoin_units::Amount::to_string_with_denomination(self, denom: bitcoin_units::amount::Denomination) -> alloc::string::String
pub fn bitcoin_units::Amount::try_from(value: bitcoin_units::SignedAmount) -> core::result::Result<Self, Self::Error>
pub fn bitcoin_units::Amount::unchecked_add(self, rhs: bitcoin_units::Amount) -> bitcoin_units::Amount
pub fn bitcoin_units::Amount::unchecked_sub(self, rhs: bitcoin_units::Amount) -> bitcoin_units::Amount
pub fn bitcoin_units::SignedAmount::abs(self) -> bitcoin_units::SignedAmount
Expand Down Expand Up @@ -779,8 +776,7 @@ pub fn bitcoin_units::SignedAmount::to_btc(self) -> f64
pub fn bitcoin_units::SignedAmount::to_float_in(self, denom: bitcoin_units::amount::Denomination) -> f64
pub fn bitcoin_units::SignedAmount::to_string_in(self, denom: bitcoin_units::amount::Denomination) -> alloc::string::String
pub fn bitcoin_units::SignedAmount::to_string_with_denomination(self, denom: bitcoin_units::amount::Denomination) -> alloc::string::String
pub fn bitcoin_units::SignedAmount::to_unsigned(self) -> core::result::Result<bitcoin_units::Amount, bitcoin_units::amount::error::OutOfRangeError>
pub fn bitcoin_units::SignedAmount::try_from(value: bitcoin_units::Amount) -> core::result::Result<Self, Self::Error>
pub fn bitcoin_units::SignedAmount::to_unsigned(self) -> bitcoin_units::Amount
pub fn bitcoin_units::SignedAmount::unchecked_add(self, rhs: bitcoin_units::SignedAmount) -> bitcoin_units::SignedAmount
pub fn bitcoin_units::SignedAmount::unchecked_sub(self, rhs: bitcoin_units::SignedAmount) -> bitcoin_units::SignedAmount
pub fn bitcoin_units::SignedAmount::unsigned_abs(self) -> bitcoin_units::Amount
Expand Down Expand Up @@ -863,6 +859,7 @@ pub fn bitcoin_units::block::BlockInterval::add(self, rhs: bitcoin_units::block:
pub fn bitcoin_units::block::BlockInterval::add_assign(&mut self, rhs: bitcoin_units::block::BlockInterval)
pub fn bitcoin_units::block::BlockInterval::clone(&self) -> bitcoin_units::block::BlockInterval
pub fn bitcoin_units::block::BlockInterval::cmp(&self, other: &bitcoin_units::block::BlockInterval) -> core::cmp::Ordering
pub fn bitcoin_units::block::BlockInterval::default() -> bitcoin_units::block::BlockInterval
pub fn bitcoin_units::block::BlockInterval::eq(&self, other: &bitcoin_units::block::BlockInterval) -> bool
pub fn bitcoin_units::block::BlockInterval::fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result
pub fn bitcoin_units::block::BlockInterval::from(h: bitcoin_units::locktime::relative::Height) -> Self
Expand Down Expand Up @@ -1069,15 +1066,13 @@ pub struct bitcoin_units::locktime::relative::TimeOverflowError
pub struct bitcoin_units::parse::PrefixedHexError(_)
pub struct bitcoin_units::parse::UnprefixedHexError(_)
pub struct bitcoin_units::weight::Weight(_)
pub trait bitcoin_units::amount::CheckedSum<R>: private::SumSeal<R>
pub trait bitcoin_units::parse::Integer: core::str::traits::FromStr<Err = core::num::error::ParseIntError> + core::convert::TryFrom<i8> + core::marker::Sized
pub trait bitcoin_units::amount::CheckedSum<R>: sealed::Sealed<R>
pub trait bitcoin_units::parse::Integer: core::str::traits::FromStr<Err = core::num::error::ParseIntError> + core::convert::TryFrom<i8> + core::marker::Sized + sealed::Sealed
pub type &bitcoin_units::fee_rate::FeeRate::Output = bitcoin_units::fee_rate::FeeRate
pub type bitcoin_units::Amount::Err = bitcoin_units::amount::error::ParseError
pub type bitcoin_units::Amount::Error = bitcoin_units::amount::error::OutOfRangeError
pub type bitcoin_units::Amount::Output = bitcoin_units::Amount
pub type bitcoin_units::Amount::Output = bitcoin_units::fee_rate::FeeRate
pub type bitcoin_units::SignedAmount::Err = bitcoin_units::amount::error::ParseError
pub type bitcoin_units::SignedAmount::Error = bitcoin_units::amount::error::OutOfRangeError
pub type bitcoin_units::SignedAmount::Output = bitcoin_units::SignedAmount
pub type bitcoin_units::amount::Denomination::Err = bitcoin_units::amount::error::ParseDenominationError
pub type bitcoin_units::block::BlockHeight::Err = bitcoin_units::parse::ParseIntError
Expand Down
17 changes: 6 additions & 11 deletions api/units/no-features.txt
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,11 @@ impl core::convert::TryFrom<&str> for bitcoin_units::locktime::absolute::Time
impl core::convert::TryFrom<&str> for bitcoin_units::locktime::relative::Height
impl core::convert::TryFrom<&str> for bitcoin_units::locktime::relative::Time
impl core::convert::TryFrom<&str> for bitcoin_units::weight::Weight
impl core::convert::TryFrom<bitcoin_units::Amount> for bitcoin_units::SignedAmount
impl core::convert::TryFrom<bitcoin_units::SignedAmount> for bitcoin_units::Amount
impl core::convert::TryFrom<bitcoin_units::block::BlockHeight> for bitcoin_units::locktime::absolute::Height
impl core::convert::TryFrom<bitcoin_units::block::BlockInterval> for bitcoin_units::locktime::relative::Height
impl core::default::Default for bitcoin_units::Amount
impl core::default::Default for bitcoin_units::SignedAmount
impl core::default::Default for bitcoin_units::block::BlockInterval
impl core::default::Default for bitcoin_units::locktime::relative::Height
impl core::default::Default for bitcoin_units::locktime::relative::Time
impl core::fmt::Debug for bitcoin_units::Amount
Expand Down Expand Up @@ -677,7 +676,6 @@ pub const fn bitcoin_units::weight::Weight::from_vb_unchecked(vb: u64) -> Self
pub const fn bitcoin_units::weight::Weight::from_vb_unwrap(vb: u64) -> bitcoin_units::weight::Weight
pub const fn bitcoin_units::weight::Weight::from_witness_data_size(witness_size: u64) -> Self
pub const fn bitcoin_units::weight::Weight::from_wu(wu: u64) -> Self
pub const fn bitcoin_units::weight::Weight::from_wu_usize(wu: usize) -> Self
pub const fn bitcoin_units::weight::Weight::to_kwu_floor(self) -> u64
pub const fn bitcoin_units::weight::Weight::to_vbytes_ceil(self) -> u64
pub const fn bitcoin_units::weight::Weight::to_vbytes_floor(self) -> u64
Expand Down Expand Up @@ -714,8 +712,7 @@ pub fn bitcoin_units::Amount::sub(self, rhs: bitcoin_units::Amount) -> Self::Out
pub fn bitcoin_units::Amount::sub_assign(&mut self, other: bitcoin_units::Amount)
pub fn bitcoin_units::Amount::sum<I: core::iter::traits::iterator::Iterator<Item = Self>>(iter: I) -> Self
pub fn bitcoin_units::Amount::sum<I>(iter: I) -> Self where I: core::iter::traits::iterator::Iterator<Item = &'a bitcoin_units::Amount>
pub fn bitcoin_units::Amount::to_signed(self) -> core::result::Result<bitcoin_units::SignedAmount, bitcoin_units::amount::error::OutOfRangeError>
pub fn bitcoin_units::Amount::try_from(value: bitcoin_units::SignedAmount) -> core::result::Result<Self, Self::Error>
pub fn bitcoin_units::Amount::to_signed(self) -> bitcoin_units::SignedAmount
pub fn bitcoin_units::Amount::unchecked_add(self, rhs: bitcoin_units::Amount) -> bitcoin_units::Amount
pub fn bitcoin_units::Amount::unchecked_sub(self, rhs: bitcoin_units::Amount) -> bitcoin_units::Amount
pub fn bitcoin_units::SignedAmount::abs(self) -> bitcoin_units::SignedAmount
Expand Down Expand Up @@ -749,8 +746,7 @@ pub fn bitcoin_units::SignedAmount::sub(self, rhs: bitcoin_units::SignedAmount)
pub fn bitcoin_units::SignedAmount::sub_assign(&mut self, other: bitcoin_units::SignedAmount)
pub fn bitcoin_units::SignedAmount::sum<I: core::iter::traits::iterator::Iterator<Item = Self>>(iter: I) -> Self
pub fn bitcoin_units::SignedAmount::sum<I>(iter: I) -> Self where I: core::iter::traits::iterator::Iterator<Item = &'a bitcoin_units::SignedAmount>
pub fn bitcoin_units::SignedAmount::to_unsigned(self) -> core::result::Result<bitcoin_units::Amount, bitcoin_units::amount::error::OutOfRangeError>
pub fn bitcoin_units::SignedAmount::try_from(value: bitcoin_units::Amount) -> core::result::Result<Self, Self::Error>
pub fn bitcoin_units::SignedAmount::to_unsigned(self) -> bitcoin_units::Amount
pub fn bitcoin_units::SignedAmount::unchecked_add(self, rhs: bitcoin_units::SignedAmount) -> bitcoin_units::SignedAmount
pub fn bitcoin_units::SignedAmount::unchecked_sub(self, rhs: bitcoin_units::SignedAmount) -> bitcoin_units::SignedAmount
pub fn bitcoin_units::SignedAmount::unsigned_abs(self) -> bitcoin_units::Amount
Expand Down Expand Up @@ -831,6 +827,7 @@ pub fn bitcoin_units::block::BlockInterval::add(self, rhs: bitcoin_units::block:
pub fn bitcoin_units::block::BlockInterval::add_assign(&mut self, rhs: bitcoin_units::block::BlockInterval)
pub fn bitcoin_units::block::BlockInterval::clone(&self) -> bitcoin_units::block::BlockInterval
pub fn bitcoin_units::block::BlockInterval::cmp(&self, other: &bitcoin_units::block::BlockInterval) -> core::cmp::Ordering
pub fn bitcoin_units::block::BlockInterval::default() -> bitcoin_units::block::BlockInterval
pub fn bitcoin_units::block::BlockInterval::eq(&self, other: &bitcoin_units::block::BlockInterval) -> bool
pub fn bitcoin_units::block::BlockInterval::fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result
pub fn bitcoin_units::block::BlockInterval::from(h: bitcoin_units::locktime::relative::Height) -> Self
Expand Down Expand Up @@ -1023,15 +1020,13 @@ pub struct bitcoin_units::locktime::relative::TimeOverflowError
pub struct bitcoin_units::parse::PrefixedHexError(_)
pub struct bitcoin_units::parse::UnprefixedHexError(_)
pub struct bitcoin_units::weight::Weight(_)
pub trait bitcoin_units::amount::CheckedSum<R>: private::SumSeal<R>
pub trait bitcoin_units::parse::Integer: core::str::traits::FromStr<Err = core::num::error::ParseIntError> + core::convert::TryFrom<i8> + core::marker::Sized
pub trait bitcoin_units::amount::CheckedSum<R>: sealed::Sealed<R>
pub trait bitcoin_units::parse::Integer: core::str::traits::FromStr<Err = core::num::error::ParseIntError> + core::convert::TryFrom<i8> + core::marker::Sized + sealed::Sealed
pub type &bitcoin_units::fee_rate::FeeRate::Output = bitcoin_units::fee_rate::FeeRate
pub type bitcoin_units::Amount::Err = bitcoin_units::amount::error::ParseError
pub type bitcoin_units::Amount::Error = bitcoin_units::amount::error::OutOfRangeError
pub type bitcoin_units::Amount::Output = bitcoin_units::Amount
pub type bitcoin_units::Amount::Output = bitcoin_units::fee_rate::FeeRate
pub type bitcoin_units::SignedAmount::Err = bitcoin_units::amount::error::ParseError
pub type bitcoin_units::SignedAmount::Error = bitcoin_units::amount::error::OutOfRangeError
pub type bitcoin_units::SignedAmount::Output = bitcoin_units::SignedAmount
pub type bitcoin_units::amount::Denomination::Err = bitcoin_units::amount::error::ParseDenominationError
pub type bitcoin_units::block::BlockHeight::Err = bitcoin_units::parse::ParseIntError
Expand Down
Loading

0 comments on commit 9d70d38

Please sign in to comment.