in3rsha / bitcoin-utxo-dump

Get a list of UTXOs (unspent transaction outputs) from your Bitcoin Core client.
MIT License
241 stars 103 forks source link

Dumped amount is wrong #13

Closed lamengao closed 4 years ago

lamengao commented 4 years ago

I sorted utxodump.txt by amount and find the maximum amount is 2147483647 and minimum is negative number.

count,txid,vout,amount,type,address,script
9999824,4f4d5fbae8e4032e04dfe4efb8b7c30d849e2bf4c71eeac6b0f9fbd3bef3fc27,0,2147483647,p2sh,3PSvFA2ooWccdBuJNJAUDunzZBefN344h3,eea833ff2bd9f433a24e9bfbaaf2efed4b8013c7
9999479,36983a7a2bc5b7e197f6c64e40b078a17adffe98e1d9157245f742876d8bfc27,1,2147483647,p2sh,39A8qzNqin9Pb9sBJ1aV8ahTatmtx1m4As,51e9e3a40f69fca7922518272496be878bb99934
9999478,36983a7a2bc5b7e197f6c64e40b078a17adffe98e1d9157245f742876d8bfc27,0,2147483647,p2sh,3FsTxDgQsUj65SxX4611tzPD6HW41QE5CZ,9b8ba5fe8221c8fa22f16c6e2ef52022bca07768
...
21107494,65fb37015b1ae9e3842c34c9da9a6533dd9ac0b88dad303b1e180a8b68ecfd53,0,-238313366,p2sh,3BtaVbiGaZgUVrE5JsK872nFUeq497q8T3,6fe1057bc8d00bca4835ec28675a151bf95a181e
43986610,a93d8cad6698aa2f6c8f8ff4424a9d090befaaf002ef7f60fa74f9256b7852ae,0,-238315865,p2pkh,14mNifRxUzLEt8RanX7BPff9NhVoQm5zUv,294ccf28748923d84f26f54122d5fbe050d23514
20112100,596442355e77fa75d14800750609673e9405f7e96df12bfef5c39bd1a6351150,0,-238415907,p2sh,3NJYSp765xpjo2rFpxzfk6Hc6hiuffGdt2,e21a8d7f42597de1187ddbb3db636a4db9e1389c
in3rsha commented 4 years ago

Interesting. I've just tested the script and I'm not getting the same results for those UTXOs as you are.

  1. What command are you using to sort the file?
  2. What operating system are you using?
lamengao commented 4 years ago

I run bitcoin-utxo-dump on a "raspberry pi 4" and sort the file using sort -k4 -n -r -t, utxodump.txt. I guess the reason is my cpu is 32 bits. Change the amount type from int to int64 can fix the problem.

in3rsha commented 4 years ago

I guess the reason is my cpu is 32 bits. Change the amount type from int to int64 can fix the problem.

Ah yes, thank you, I didn't think of that.

I have changed the code to use int64 instead of int when working out the amount. Could you update and check that it's working:

go get -u github.com/in3rsha/bitcoin-utxo-dump

To speed up the test you can just ask for the amounts (which saves time on having to work out the addresses for each UTXO):

bitcoin-utxo-dump -f count,txid,vout,amount

You should be getting the following amounts for the UTXOs you listed above:

count,txid,vout,amount
9999824,4f4d5fbae8e4032e04dfe4efb8b7c30d849e2bf4c71eeac6b0f9fbd3bef3fc27,0,1985523766
9999479,36983a7a2bc5b7e197f6c64e40b078a17adffe98e1d9157245f742876d8bfc27,1,46308954412
9999478,36983a7a2bc5b7e197f6c64e40b078a17adffe98e1d9157245f742876d8bfc27,0,9000000000
...
21107494,65fb37015b1ae9e3842c34c9da9a6533dd9ac0b88dad303b1e180a8b68ecfd53,0,2147779575
43986610,a93d8cad6698aa2f6c8f8ff4424a9d090befaaf002ef7f60fa74f9256b7852ae,0,28394799441
20112100,596442355e77fa75d14800750609673e9405f7e96df12bfef5c39bd1a6351150,0,2147677034

I don't have a 32-bit system so I would be grateful for the testing.

lamengao commented 4 years ago

I update bitcoin-utxo-dump and run it again. Right now the amount is all right.

in3rsha commented 4 years ago

Thank you for your help.