Author

Topic: Best data type for Bitcoin in go (Read 146 times)

legendary
Activity: 2870
Merit: 7490
Crypto Swap Exchange
October 24, 2018, 01:32:46 PM
#7
I just remember BIP70 about Payment Protocol (or usually referred as Payment Request) uses uint64. Almost all wallet these days recognize it, so IMO it's safe option.
But you can choose any data type for storing amount/balance, as long as it's not overflow. Even custom decimal configuration (if programming language or SQL database support it) such as decimal(7,8) would work.

That's the issue, what if a conversion goes bad and a user gets in his balance 1000's of bitcoin?

If you get the amount from another nodes/server, you simply need to find out data type they uses. For example, JSON-RPC used by Bitcoin core uses double.
If you get the amount from input from user, just specify default Bitcoin unit (BTC, mBTC or Satoshi) and there won't be any problem.


I never learn golang, but yes since i (and perhaps you) don't know standard that bitcoin and golang uses.
newbie
Activity: 92
Merit: 0
October 24, 2018, 01:12:53 PM
#5
savage
legendary
Activity: 4326
Merit: 3041
Vile Vixen and Miss Bitcointalk 2021-2023
October 24, 2018, 01:11:25 PM
#4
That's the issue, what if a conversion goes bad and a user gets in his balance 1000's of bitcoin?
Computers only do what they're programmed to do; if "a conversion goes bad", it's because it was incompetently written and you should quit voodoo programming and hire someone who knows what they're doing for your project, especially if it involves handling other people's money. Undecided
newbie
Activity: 92
Merit: 0
October 24, 2018, 12:51:30 PM
#3
As FoxPup mentioned, int64 is best choice since it's enough even to specify total Bitcoin supply (in Satoshi).

Additionally, it's easier to use/implement since not all software uses same double/float64 standard and AFAIK int64 is faster.

That's the issue, what if a conversion goes bad and a user gets in his balance 1000's of bitcoin?
is that what you mean?
https://play.golang.org/p/rJncvBvqyEP
legendary
Activity: 4326
Merit: 3041
Vile Vixen and Miss Bitcointalk 2021-2023
October 24, 2018, 12:11:47 PM
#2
What's wrong with int64? Huh
newbie
Activity: 92
Merit: 0
October 24, 2018, 11:07:59 AM
#1
Hey everybody, I was wondering what would be the best data type to use for bitcoin.
Both float32 and float64 are not recommended to use for money representation, what can be a valid solution?
Jump to: