Skip to content

Commit 807fd9f

Browse files
docs: add API docs for Amount type
1 parent d5cafb9 commit 807fd9f

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

bdk-ffi/src/bitcoin.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,26 +93,35 @@ impl FeeRate {
9393
impl_from_core_type!(BdkFeeRate, FeeRate);
9494
impl_into_core_type!(FeeRate, BdkFeeRate);
9595

96+
/// The Amount type can be used to express Bitcoin amounts that support arithmetic and conversion
97+
/// to various denominations. The operations that Amount implements will panic when overflow or
98+
/// underflow occurs. Also note that since the internal representation of amounts is unsigned,
99+
/// subtracting below zero is considered an underflow and will cause a panic.
96100
#[derive(Debug, Clone, PartialEq, Eq, uniffi::Object)]
97101
pub struct Amount(pub BdkAmount);
98102

99103
#[uniffi::export]
100104
impl Amount {
105+
/// Create an Amount with satoshi precision and the given number of satoshis.
101106
#[uniffi::constructor]
102107
pub fn from_sat(satoshi: u64) -> Self {
103108
Amount(BdkAmount::from_sat(satoshi))
104109
}
105110

111+
/// Convert from a value expressing bitcoins to an Amount.
106112
#[uniffi::constructor]
107113
pub fn from_btc(btc: f64) -> Result<Self, ParseAmountError> {
108114
let bitcoin_amount = BdkAmount::from_btc(btc).map_err(ParseAmountError::from)?;
109115
Ok(Amount(bitcoin_amount))
110116
}
111117

118+
/// Get the number of satoshis in this Amount.
112119
pub fn to_sat(&self) -> u64 {
113120
self.0.to_sat()
114121
}
115122

123+
/// Express this Amount as a floating-point value in Bitcoin. Please be aware of the risk of
124+
/// using floating-point numbers.
116125
pub fn to_btc(&self) -> f64 {
117126
self.0.to_btc()
118127
}

0 commit comments

Comments
 (0)