add msat support for strike backend (#755)

This commit is contained in:
callebtc
2025-05-18 15:48:15 +02:00
committed by GitHub
parent 53126456a5
commit 3e32dc40e3
5 changed files with 33 additions and 10 deletions

View File

@@ -605,15 +605,19 @@ class Amount:
return self.cents_to_usd()
elif self.unit == Unit.sat:
return self.sat_to_btc()
elif self.unit == Unit.msat:
return self.msat_to_btc()
else:
raise Exception("Amount must be in satoshis or cents")
@classmethod
def from_float(cls, amount: float, unit: Unit) -> "Amount":
if unit == Unit.usd or unit == Unit.eur:
return cls(unit, int(amount * 100))
return cls(unit, int(round(amount * 100)))
elif unit == Unit.sat:
return cls(unit, int(amount * 1e8))
return cls(unit, int(round(amount * 1e8)))
elif unit == Unit.msat:
return cls(unit, int(round(amount * 1e11)))
else:
raise Exception("Amount must be in satoshis or cents")
@@ -622,6 +626,12 @@ class Amount:
raise Exception("Amount must be in satoshis")
return f"{self.amount/1e8:.8f}"
def msat_to_btc(self) -> str:
if self.unit != Unit.msat:
raise Exception("Amount must be in msat")
sat_amount = Amount(Unit.msat, self.amount).to(Unit.sat, round="up")
return f"{sat_amount.amount/1e8:.8f}"
def cents_to_usd(self) -> str:
if self.unit != Unit.usd and self.unit != Unit.eur:
raise Exception("Amount must be in cents")