pub struct FeeRate(/* private fields */);Expand description
Fee rate.
This is an integer newtype representing fee rate. It provides protection against mixing up the types, conversion functions, and basic formatting.
NOTE: FeeRate explicitly does not have any format/display trait implementations, as it
doesn’t have a standard unit for measure. Users are expected to format it on their own by
extracting values in desired units with from_sat_per* functions.
Implementations§
Source§impl FeeRate
impl FeeRate
Sourcepub const ZERO: Self
pub const ZERO: Self
The zero fee rate.
Equivalent to MIN, may better express intent in some contexts.
Sourcepub const MIN: Self = Self::ZERO
pub const MIN: Self = Self::ZERO
The minimum possible value.
Equivalent to ZERO, may better express intent in some contexts.
Sourcepub const BROADCAST_MIN: Self
pub const BROADCAST_MIN: Self
The minimum fee rate required to broadcast a transaction.
The value matches the default Bitcoin Core policy at the time of library release.
Sourcepub const fn from_sat_per_kwu(sat_kwu: u32) -> Self
pub const fn from_sat_per_kwu(sat_kwu: u32) -> Self
Constructs a new FeeRate from satoshis per 1000 weight units.
Sourcepub const fn from_per_kwu(rate: Amount) -> NumOpResult<Self>
pub const fn from_per_kwu(rate: Amount) -> NumOpResult<Self>
Constructs a new FeeRate from amount per 1000 weight units.
Sourcepub const fn from_sat_per_vb(sat_vb: u32) -> Self
pub const fn from_sat_per_vb(sat_vb: u32) -> Self
Constructs a new FeeRate from satoshis per virtual byte.
Sourcepub const fn from_per_vb(rate: Amount) -> NumOpResult<Self>
pub const fn from_per_vb(rate: Amount) -> NumOpResult<Self>
Constructs a new FeeRate from amount per virtual byte.
Sourcepub const fn from_sat_per_kvb(sat_kvb: u32) -> Self
pub const fn from_sat_per_kvb(sat_kvb: u32) -> Self
Constructs a new FeeRate from satoshis per kilo virtual bytes (1,000 vbytes).
Sourcepub const fn from_per_kvb(rate: Amount) -> NumOpResult<Self>
pub const fn from_per_kvb(rate: Amount) -> NumOpResult<Self>
Constructs a new FeeRate from satoshis per kilo virtual bytes (1,000 vbytes).
Sourcepub const fn to_sat_per_kwu_floor(self) -> u64
pub const fn to_sat_per_kwu_floor(self) -> u64
Converts to sat/kwu rounding down.
Sourcepub const fn to_sat_per_kwu_ceil(self) -> u64
pub const fn to_sat_per_kwu_ceil(self) -> u64
Converts to sat/kwu rounding up.
Sourcepub const fn to_sat_per_vb_floor(self) -> u64
pub const fn to_sat_per_vb_floor(self) -> u64
Converts to sat/vB rounding down.
Sourcepub const fn to_sat_per_vb_ceil(self) -> u64
pub const fn to_sat_per_vb_ceil(self) -> u64
Converts to sat/vB rounding up.
Sourcepub const fn to_sat_per_kvb_floor(self) -> u64
pub const fn to_sat_per_kvb_floor(self) -> u64
Converts to sat/kvb rounding down.
Sourcepub const fn to_sat_per_kvb_ceil(self) -> u64
pub const fn to_sat_per_kvb_ceil(self) -> u64
Converts to sat/kvb rounding up.
Sourcepub const fn checked_mul(self, rhs: u64) -> Option<Self>
pub const fn checked_mul(self, rhs: u64) -> Option<Self>
Checked multiplication.
Computes self * rhs, returning None if overflow occurred.
Sourcepub const fn checked_div(self, rhs: u64) -> Option<Self>
pub const fn checked_div(self, rhs: u64) -> Option<Self>
Checked division.
Computes self / rhs returning None if rhs == 0.
Sourcepub const fn checked_add(self, rhs: Self) -> Option<Self>
pub const fn checked_add(self, rhs: Self) -> Option<Self>
Checked addition.
Computes self + rhs returning None in case of overflow.
Sourcepub const fn checked_sub(self, rhs: Self) -> Option<Self>
pub const fn checked_sub(self, rhs: Self) -> Option<Self>
Checked subtraction.
Computes self - rhs, returning None if overflow occurred.
Sourcepub const fn to_fee(self, weight: Weight) -> Amount
pub const fn to_fee(self, weight: Weight) -> Amount
Calculates the fee by multiplying this fee rate by weight.
Computes the absolute fee amount for a given Weight at this fee rate. When the resulting
fee is a non-integer amount, the amount is rounded up, ensuring that the transaction fee is
enough instead of falling short if rounded down.
If the calculation would overflow we saturate to Amount::MAX. Since such a fee can never
be paid this is meaningful as an error case while still removing the possibility of silently
wrapping.
Sourcepub fn fee_wu(self, weight: Weight) -> Option<Amount>
👎Deprecated since 1.0.0-rc.0: use to_fee() instead
pub fn fee_wu(self, weight: Weight) -> Option<Amount>
to_fee() insteadCalculates the fee by multiplying this fee rate by weight, in weight units, returning None
if an overflow occurred.
This is equivalent to Self::mul_by_weight(weight).ok().
Sourcepub fn fee_vb(self, vb: u64) -> Option<Amount>
👎Deprecated since 1.0.0-rc.0: use Weight::from_vb and then to_fee() instead
pub fn fee_vb(self, vb: u64) -> Option<Amount>
to_fee() insteadCalculates the fee by multiplying this fee rate by weight, in virtual bytes, returning None
if vb cannot be represented as Weight.
This is equivalent to converting vb to Weight using Weight::from_vb and then calling
Self::to_fee.
Sourcepub const fn mul_by_weight(self, weight: Weight) -> NumOpResult<Amount>
pub const fn mul_by_weight(self, weight: Weight) -> NumOpResult<Amount>
Checked weight multiplication.
Computes the absolute fee amount for a given Weight at this fee rate. When the resulting
fee is a non-integer amount, the amount is rounded up, ensuring that the transaction fee is
enough instead of falling short if rounded down.
Trait Implementations§
Source§impl AddAssign<&FeeRate> for FeeRate
impl AddAssign<&FeeRate> for FeeRate
Source§fn add_assign(&mut self, rhs: &FeeRate)
fn add_assign(&mut self, rhs: &FeeRate)
+= operation. Read moreSource§impl AddAssign for FeeRate
impl AddAssign for FeeRate
Source§fn add_assign(&mut self, rhs: FeeRate)
fn add_assign(&mut self, rhs: FeeRate)
+= operation. Read moreSource§impl<'a> Arbitrary<'a> for FeeRate
Available on crate feature arbitrary only.
impl<'a> Arbitrary<'a> for FeeRate
arbitrary only.Source§fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>
Self from the given unstructured data. Read moreSource§fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
Self from the entirety of the given
unstructured data. Read moreSource§fn size_hint(depth: usize) -> (usize, Option<usize>)
fn size_hint(depth: usize) -> (usize, Option<usize>)
Unstructured this type
needs to construct itself. Read moreSource§fn try_size_hint(
depth: usize,
) -> Result<(usize, Option<usize>), MaxRecursionReached>
fn try_size_hint( depth: usize, ) -> Result<(usize, Option<usize>), MaxRecursionReached>
Unstructured this type
needs to construct itself. Read moreSource§impl Ord for FeeRate
impl Ord for FeeRate
Source§impl PartialOrd for FeeRate
impl PartialOrd for FeeRate
Source§impl SubAssign<&FeeRate> for FeeRate
impl SubAssign<&FeeRate> for FeeRate
Source§fn sub_assign(&mut self, rhs: &FeeRate)
fn sub_assign(&mut self, rhs: &FeeRate)
-= operation. Read moreSource§impl SubAssign for FeeRate
impl SubAssign for FeeRate
Source§fn sub_assign(&mut self, rhs: FeeRate)
fn sub_assign(&mut self, rhs: FeeRate)
-= operation. Read more