-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Description
If this library is intended to be used for all rust-bitcoin crates (which I think it should for interoperability reasons) then it should be capable of representing sub-satoshi amounts (e.g. for lightning payments). But unfortunately the smallest amount needed for lightning is pico BTC which leads to a storage requirement of 64.2 bits if we want to represent up to 21*10^6 BTC with that precision.
My proposal would be to add a type parameter to Amount which optionally extends the precision:
trait Precision : Default {}
struct Satoshi ();
struct PicoBtc (u32); // Additional space to represent sub-satoshi amounts
impl Precision for Satoshi;
impl Precision for PicoBtc;
struct Amount<P = Satoshi> where P: Precision (Inner, P);
impl Amount<PicoBtc> {
pub fn to_satoshi(&self) -> Amount<Satoshi> {...}
}The default empty Satoshi type would be completely optimized away by the compiler, so this feature should incur no performance penalties if not used.
What do you think about this approach?
Metadata
Metadata
Assignees
Labels
No labels