Everything That Changed in bitcoin-units 1.0
EN AI Assisted Writing · Claude 3 min read
The public API delta of bitcoin-units from the 0.32 era to 1.0, type by type.
Table of Contents
Every public API change between the bitcoin 0.32 era units and bitcoin-units 1.0, grouped by type. Use it as a checklist when migrating a crate.
Generated with cargo public-api on bitcoin-units 0.1.101 (the 0.32.xxx compat branch) against bitcoin-units 1.0.0, default features. Types marked “moved in” lived in bitcoin or primitives during 0.32, so for those the old side is the bitcoin 0.32 type.
Crate wide
- Checked arithmetic between typed values goes through
NumOpResult<T>(newresultmodule withNumOpErrorandMathOp). CheckedSumis gone. Sum withiter.map(NumOpResult::from).sum::<NumOpResult<T>>().*Assignoperator impls onAmountandSignedAmountare gone.FeeRateandWeightgained theirs.- Every error type moved into a per-module
errorsubmodule, implementssource(), and lost ad hoc constructors (TimeOverflowError::new,ParseIntError::input()). - Most integer newtypes gained
from_hex(0x prefixed) andfrom_unprefixed_hex. Theparsemodule grewhex_u16throughhex_u128with prefixed and unprefixed variants.
Amount
from_sat(u64)returnsResult<_, OutOfRangeError>, capped atMAX_MONEY. The infallible constructors arefrom_sat_u32(u32)andfrom_btc_u16(u16).from_int_btctakesimpl Into<u16>instead ofu64.to_signedis infallible, since every cappedAmountfits.unchecked_add/unchecked_subremoved.div_by_weight_floor/div_by_weight_ceilreturnNumOpResult<FeeRate>(wereOption). Newdiv_by_fee_rate_floor/_ceilreturningNumOpResult<Weight>.- New
signed_sub,from_sat_hex,from_sat_unprefixed_hex, constFIFTY_BTC. Divalso acceptsFeeRate,WeightandNonZeroU64divisors.
SignedAmount
- Mirrors
Amount. Falliblefrom_sat(i64)capped at plus or minusMAX_MONEY, newfrom_sat_i32,from_btc_i16,from_int_btc(impl Into<i16>), hex constructors,FIFTY_BTC. Unchecked and assign ops removed. - New infallible
From<Amount> for SignedAmount. positive_substill returnsOption.
FeeRate
- Precision changed and constructors take
u32.from_sat_per_kwu(u32)andfrom_sat_per_vb(u32)are infallible (wereu64 -> Option).from_sat_per_vb_u32andfrom_sat_per_vb_uncheckedare gone. Newfrom_sat_per_kvb(u32). to_sat_per_kwusplit into_floorand_ceil. Newto_sat_per_kvb_floor/_ceil.fee_vb,fee_wuandchecked_mul_by_weightremoved. Useto_fee(Weight) -> Amountormul_by_weight(Weight) -> NumOpResult<Amount>.- New
from_per_kwu,from_per_vb,from_per_kvb, each taking anAmountand returningNumOpResult<Self>. FromStrandTryFrom<&str>removed.- Gained
Add/Subwith assign variants,checked_add/checked_sub,Sum.
Weight
- Removed
from_vb_unwrap,from_wu_usize,from_non_witness_data_size,from_witness_data_size,scale_by_witness_factor. - New
mul_by_fee_rate(FeeRate) -> NumOpResult<Amount>,to_kwu_ceil,Remops, hex constructors.
Absolute locktime
TimerenamedMedianTimePast. OnLockTime,from_timeis nowfrom_mtp,is_satisfied_by_timereturnsResult<bool, IncompatibleTimeError>andis_satisfied_by_heightreturnsResult<bool, IncompatibleHeightError>.- On
HeightandMedianTimePast,from_consensusis renamedfrom_u32andto_consensus_u32is renamedto_u32. Newis_satisfied_by(self, Self)andfrom_unprefixed_hex. - New
MedianTimePast::new([BlockTime; 11])computes MTP from the last eleven block timestamps. absolute::LockTimemoved in frombitcoin.is_satisfied_bytakes(Height, MedianTimePast).
Relative locktime
relative::HeightrenamedNumberOfBlocks,relative::TimerenamedNumberOf512Seconds. The oldvalue()getters are gone.relative::LockTimemoved in frombitcoin.from_consensusis fallible withDisabledLockTimeError. Newto_sequence/from_sequence.is_satisfied_bytakes four arguments (chain tip height and MTP, plus the height and MTP the UTXO was mined at) and returnsResult<bool, IsSatisfiedByError>. The_heightand_timevariants takeBlockHeightorBlockMtppairs and return their own error enums.
Sequence (moved in)
- The inner field is private.
Sequence(n)no longer compiles, usefrom_consensus. In tests,Sequence(1000)becamerelative::LockTime::from_consensus(1000).unwrap(). to_relative_lock_timereturns the stablerelative::LockTime.- Gained
FromStr,TryFrom<&str>, hex constructors. All predicates (is_final,is_rbf,is_height_locked, …) and consts (MAX,ZERO,FINAL, …) are present.
Pow types (moved in)
Target,WorkandCompactTargetare units types with byte conversions,to_compact_lossy,to_work/to_target,CompactTarget::from_consensus/to_consensus, and theMAX_ATTAINABLE_*consts. Difficulty calculations that need chain params stayed inbitcoin.
Block module (new)
BlockHeight,BlockHeightInterval,BlockMtp,BlockMtpInterval,BlockTime. Point minus point gives an interval, point plus interval gives a point, withchecked_andsaturating_variants andFromconversions to and from the locktime types. These are the argument types of the new relativeis_satisfied_byfamily.
Removed with no direct replacement
trait CheckedSum, useNumOpResultsums.absolute::Timeand the old relativeHeight/Timenames, all renamed.FeeRate: FromStr.