Skip to content

Commit

Permalink
Rename AssetMetadata functions
Browse files Browse the repository at this point in the history
  • Loading branch information
dangeross committed Jan 24, 2025
1 parent b5a3372 commit b92d1ef
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/core/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1480,11 +1480,11 @@ pub struct AssetMetadata {
}

impl AssetMetadata {
pub fn to_sat(&self, amount: f64) -> u64 {
pub fn amount_to_sat(&self, amount: f64) -> u64 {
(amount * (10_u64.pow(self.precision.into()) as f64)) as u64
}

pub fn from_sat(&self, amount_sat: u64) -> f64 {
pub fn amount_from_sat(&self, amount_sat: u64) -> f64 {
amount_sat as f64 / (10_u64.pow(self.precision.into()) as f64)
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/core/src/persist/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ impl Persister {
Some(AssetInfo {
name,
ticker,
amount: asset_metadata.from_sat(amount),
amount: asset_metadata.amount_from_sat(amount),
})
}
_ => None,
Expand Down
6 changes: 3 additions & 3 deletions lib/core/src/sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,7 @@ impl LiquidSdk {
err: format!("Asset {asset_id} is not supported"),
},
)?;
let receiver_amount_sat = asset_metadata.to_sat(receiver_amount);
let receiver_amount_sat = asset_metadata.amount_to_sat(receiver_amount);
let fees_sat = self
.estimate_onchain_tx_or_drain_tx_fee(
receiver_amount_sat,
Expand Down Expand Up @@ -1378,7 +1378,7 @@ impl LiquidSdk {
.map(|ref am| AssetInfo {
name: am.name.clone(),
ticker: am.ticker.clone(),
amount: am.from_sat(receiver_amount_sat),
amount: am.amount_from_sat(receiver_amount_sat),
});
let payment_details = PaymentDetails::Liquid {
asset_id,
Expand Down Expand Up @@ -2746,7 +2746,7 @@ impl LiquidSdk {
balance_sat,
name: maybe_asset_metadata.map(|am| am.name.clone()),
ticker: maybe_asset_metadata.map(|am| am.ticker.clone()),
balance: maybe_asset_metadata.map(|am| am.from_sat(balance_sat)),
balance: maybe_asset_metadata.map(|am| am.amount_from_sat(balance_sat)),
}
})
.collect::<Vec<AssetBalance>>();
Expand Down

0 comments on commit b92d1ef

Please sign in to comment.