Closed APshenkin closed 6 years ago
String str? parseInt(str) % Math.pow(2,53)
(if your string is hex: parseInt(str, 16)
)
Buffer buf? buf.readUIntBE(0, buf.length) % Math.pow(2,53)
Bitcoin's max satoshi amount fits perfectly within JavaScripts maximum precision number set.
@junderw Thank you!
Uh, this won't help if your value is greater than 53bits....
Bitcoin's max satoshi amount fits perfectly within JavaScripts maximum precision number set.
(Implication: this only works within the limits of the maximum satoshi value of Bitcoin)
But for explicitness sake:
@APshenkin any amount over 9007199254740991 (53 bits)
will lose precision in JavaScript so is a no go. Also, any value over 2100000000000000 (21 * 1e6 * 1e8)
is impossible to send in Bitcoin (technically it's smaller than that) since it's the max amount of Bitcoins that will ever be created.
if you want to be super careful: % Math.pow(2,53)
at the end will chop of any bits over 53... you lose info, so maybe you might want to do something like import a BigInt library and check...
But tbh, for a simple sanity check, making sure the value is correct:
parseInt(val) === val
should be trueval >= 0
should be trueval <= (21 * 1e6 * 1e8)
should be true@junderw
I want to add outputs value that are not in UINT53.
He isn't worried about blowing the limit, he wants to. We don't provide support for that.
Hi!
Is it possible to pass values as strings or Buffers? I want to add outputs value that are not in UINT53.
I checked this issue https://github.com/bitcoinjs/bitcoinjs-lib/issues/562. There is a suggestion to set
valueBuffer
for outs, but it doesn't work. Any suggestions? Thanks!