Support for lossless BtcAmount comparison#36
Conversation
sstone
left a comment
There was a problem hiding this comment.
I think that this needs a description because "lossless comparison" is not specific enough. I'm also a bit wary of conversions: what happens if you convert msat to sat and back to msat ?
I'm also beginning to wonder if we should have a type for millisatoshis here or in eclair, because they realy are a special case (i.e in the bitcoin world why would 2001 msat be > than 2000 msat ?)
When I opened this PR I assumed we want to have a lossless comparison, where lossless means without losing precision, and to do that I had to use |
| def toBtc: Btc = millibtc2btc(toMilliBtc) | ||
| } | ||
|
|
||
| case class Satoshi(amount: Long) extends BtcAmount { |
There was a problem hiding this comment.
It's a bit unrelated but I think the amount field should be made private here, and has to be accessed with toLong. It's what we did for the UInt64 class and I find it cleaner.
| case class Satoshi(amount: Long) extends BtcAmount { | |
| case class Satoshi(private val amount: Long) extends BtcAmount { |
|
This is not needed anymore. |
This PR adds support for lossless comparison between different type of BtcAmount, the comparison uses MilliSatoshi (the smallest unit) to provide the most fine grained comparison without losing precision.