ruimarinho / bitcoin-core

A modern Bitcoin Core REST and RPC client.
480 stars 188 forks source link

Parse REST big numbers as string #41

Closed pedrobranco closed 6 years ago

pedrobranco commented 6 years ago

This PR adds support for parsing big numbers as string to prevent losing precision due to Javascript number precision problem.

Fixes #35 .

pedrobranco commented 6 years ago

@pedrobranco I am unable to reproduce this issue and don't actually see the originally reported issue anymore (nor a test preventing a regression). I also fail to understand what exactly this PR does as there is no BigInt returned on the verificationprogress field, nor one stored as a string as it was supposed to. Can you clarify a bit the changes?

Actually, when syncing the blockchain in mainnet (or testnet) the value returned by bitcoind is a double, which will loss precision on its JS interpretation:

> cli.getBlockchainInfo().then(data => console.log(data.verificationprogress)).catch(console.err)

0.01725915139476017
ruimarinho commented 6 years ago

@pedrobranco in that case, shouldn't that be returned as a string?

pedrobranco commented 6 years ago

@pedrobranco in that case, shouldn't that be returned as a string?

JSONBitInt only converts numeric values that will lose precision when parsing as JS object.

ruimarinho commented 6 years ago

@pedrobranco: me and @joaopaulofonseca took a look at this PR and there are a couple of things we feel important to be part of a general improvement to response handling, in which this change is included. Therefor, please refer to https://github.com/ruimarinho/bitcoin-core/pull/50 for further progress on this.