Closed dcousens closed 6 years ago
@junderw it might be useful to make an isolate bolt-utils
module that handles the unit conversions?
Or maybe we make a general-purpose module for going between:
etc?
I'll re-open this at a later date after some more review and tests
Yeah, we should separate it out to a different function.
However, this PR is making a huge misunderstanding about mSats.
The lightning payment request specifies milli, micro, nano, and pico as valid multipliers, BUT the lowest possible unit in ln payments is milliSatoshis. 1 milliSatoshi == 10 picoBitcoin
So any value less than 10p (10 picoBitcoin) is invalid.
@dabura667 is there any reason to support the other units?
I'd think mSats and Sats are all that should matter.
@dabura667 oh, sorry, I did not knew about this, probably I should read paper before 😆
BOLT11 doesn’t define a satoshi or millisatoshi multiplier.
It also says that you need to use the largest multiplier possible to eliminate trailing zeroes and keep the human readable part an integer.
Aka, use the lowest common denominator?
Aka, mSats
unless Sats
is an integer?
ie. 1 satoshi == 10n 1 mSat == 10p 1 bit == 1u 1 mBTC == 1m 0.1 BTC == 100m 54.321 BTC == 54321m
@dabura667 I think we should be looking at it like:
1 millisatoshi = 1
1 satoshi = 1e3 millisatoshi
1 mBTC = 1e8 * 1e3 * satoshis
1 BTC = 1e8 satoshis
Aka, satoshi
, unless millisatoshi
is required if satoshi
isn't an integer denomination.
Yea, I think having the amount be in milliSatoshis will confuse developers... so I think the amount should be handled in satoshis and allow for 3 decimal places by basically multiplying satoshis by 1000 from the get go and checking if the result is an integer, if not, throw an error.
satoshisToHrp And hrpToSatoshis
Would be good functions to add imo.
will confuse developers... so I think the amount should be handled in satoshis and allow for 3 decimal places
Developers will learn.
Everyone said satoshis
was confusing, but it is the unit for development (until millisatoshi, anyway).
Any "wrappers" we make around it will only serve to confuse. You literally just outlined an error case, where there should be no Error.
satoshisToHrp
Human-readable-prefix? Reads as if it is related to Bech32.
New users wonder why transaction.addOutput(..., 0.12)
isn't 0.12 Bitcoin
... its because the internals don't work with Bitcoin.
The same here.
I think this is an important consideration in how we make our API's sane.
Great work @fanatid :1st_place_medal: