]> Untitled Git - bdk/commit
refactor(coin_selection)!: use Amount and SignedAmount for API and internally
authorSteve Myers <steve@notmandatory.org>
Sun, 8 Dec 2024 01:28:24 +0000 (19:28 -0600)
committerSteve Myers <steve@notmandatory.org>
Wed, 11 Dec 2024 21:02:45 +0000 (15:02 -0600)
commit58a8435759ed06cb6841c5582abd97707e99706b
tree355e8a94c09c95ae199e2aaac59b0d402f9cda79
parent955593c358cd77c7da967d7c829361a1ec0cfdf9
refactor(coin_selection)!: use Amount and SignedAmount for API and internally

Using named types make the API and internal code easier to read and reason
about since it makes it clear that the values are bitcoin amounts. Also to
create these types the units (ie .from_sat()) must be specified.

Using Amount and SignedAmount also makes internal code safer against overflow
errors. In particular because these types will panic if an amount overflow
occurs. Using u64/i64 on the otherhand can silently rollover. See:
https://doc.rust-lang.org/book/ch03-02-data-types.html#integer-overflow
crates/wallet/src/wallet/coin_selection.rs
crates/wallet/src/wallet/mod.rs
crates/wallet/tests/wallet.rs