Code Monkey home page Code Monkey logo

bitcoin_tools's Introduction

bitcoin_tools

Mentioned in Awesome tippin.me

bitcoin_tools is a Python library created for teaching and researching purposes. It's main objective is twofold. First it aims to ease the understanding of Bitcoin transaction creation, by using well-documented and easy to understand python code. Second, it aims to provide a tool able to create custom transactions / scripts. Either scriptSig and scriptPubKey can be built from human readable strings created using Script syntax. Finally, tools for accessing and analysing interesting data such as the utxo set are also provided, along with several examples.

bitcoin_tools allows you to:

  • Bitcoin keys creation and management.
  • Creation of Bitcoin transactions from scratch.
  • Customize any field of your transaction.
  • Transaction serialization / deserialization.
  • Creation of standard and custom scripts (scriptSig and scriptPubKey).
  • Transaction analysis from hex encoded transactions.

Additionally, bitcoin_tools contains STATUS an STatistical Analysis Tool for Utxo Set under analysis/status

Dependencies

Refer to DEPENCENCIES.md

Installation

Refer to INSTALL.md

Some trouble getting started with the repo?

Refer to FAQ.md

Still not working?

Feel free to open an issue.

Examples

Down below you can find some examples of how to use some of the library functions. More examples can be found in examples/

Key management and Bitcoin address generation

from bitcoin_tools.core.keys import generate_keys, store_keys
from bitcoin_tools.wallet import generate_wif, generate_btc_addr

# First of all the ECDSA keys are generated.
sk, pk = generate_keys()
# Then, the Bitcoin address is derived from the public key created above.
btc_addr = generate_btc_addr(pk)
# Both the public and private key are stored in disk in pem format. The Bitcoin address is used as an identifier in the
# name of the folder that contains both keys.
store_keys(sk.to_pem(), pk.to_pem(), btc_addr)
# Finally, the private key is encoded as WIF and also stored in disk, ready to be imported in a wallet.
generate_wif(btc_addr, sk)

Raw transaction building

from bitcoin_tools.core.keys import load_keys
from bitcoin_tools.core.transaction import TX

# Key loading
btc_addr = "miWdbNn9zDLnKpcNuCLdfRiJx59c93bT8t"
sk, pk = load_keys(btc_addr)

# Reference to the previous transaction output that will be used to redeem and spend the funds, consisting on an id and
# an output index.
prev_tx_id = "7767a9eb2c8adda3ffce86c06689007a903b6f7e78dbc049ef0dbaf9eeebe075"
prev_out_index = 0

# Amount to be spent, in Satoshis, and the fee to be deduced (should be calculated).
value = 6163910
fee = 230 * 240

# Destination Bitcoin address where the value in bitcoins will be sent and locked until the owner redeems it.
destination_btc_addr = "miWdbNn9zDLnKpcNuCLdfRiJx59c93bT8t"

# First, we  build our transaction from io (input/output) using the previous transaction references, the value, and the
# destination.
tx = TX.build_from_io(prev_tx_id, prev_out_index, value - fee, destination_btc_addr)
# Finally, the transaction is signed using the private key associated with the Bitcoin address from each input.
# Input 0 will be signed, since we have only created one.
tx.sign(sk, 0)

# Once created we can display the serialized transaction. Transaction is now ready to be broadcast.
print "hex: " + tx.serialize()

# Finally, we can analyze each field of the transaction.
tx.display()

Raw tx analysis

from bitcoin_tools.core.transaction import TX

# First a transaction object is created (through the deserialize constructor) by deserializing the hex transaction we
# have selected.
hex_tx = "01000000013ca58d2f6fac36602d831ee0cf2bc80031c7472e80a322b57f614c5ce9142b71000000006b483045022100f0331d85cb7f7ec1bedc41f50c695d654489458e88aec0076fbad5d8aeda1673022009e8ca2dda1d6a16bfd7133b0008720145dacccb35c0d5c9fc567e52f26ca5f7012103a164209a7c23227fcd6a71c51efc5b6eb25407f4faf06890f57908425255e42bffffffff0241a20000000000001976a914e44839239ab36f5bc67b2079de00ecf587233ebe88ac74630000000000001976a914dc7016484646168d99e49f907c86c271299441c088ac00000000"
tx = TX.deserialize(hex_tx)

# Then, the transaction can be displayed using the display method to analyze how it's been constructed.
tx.display()

Using STATUS to dump the UTXOs LevelDB

from bitcoin_tools.analysis.status.data_dump import utxo_dump
from bitcoin_tools.analysis.status.utils import parse_ldb

# Set the version of the Bitcoin Core you are using (which defines the chainstate format)
# and the IO files.

f_utxos = "decoded_utxos.txt"
f_parsed_utxos = "parsed_utxos.txt"

# Set the coin we're working with
coin = 'bitcoin'

# Parse all the data in the chainstate.
parse_ldb(f_utxos)
# Parses transactions and utxos from the dumped data.
utxo_dump(f_utxos, f_parsed_utxos, coin)

# Data is stored in f_utxos and f_parsed_utxos files respectively

Support

If you find this repository useful, show us some love, give us a star!

Small Bitcoin donations to the following address are also welcome:

1srgi8sqPkCKq7gsVfhUZB7dvoi72UsqP

Disclaimer

This library allow you to modify any transaction field as you pleased. However, some modifications can make your transactions non-standard, or even non-spendable. We totally discourage the use of the library outside the testnet if you are not sure about what you are doing, specially when dealing with non-standard scripts. A bad use of the library can lead you to lose some of your bitcoins.

bitcoin_tools's People

Contributors

frstrtr avatar sr-gi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bitcoin_tools's Issues

Windows

Hello i m trying to use it on Windows but it seems donna work. Can you help? Thanx in advance. Regards

Not compatible with windows?

ValueError: path 'C:\Users\Administrator/bitcoin_tools/' cannot end with '/'


Failed building wheel for python-bitcoin-tools

utxo types

I was looking at utxo_dump function. I am trying to understand the utxo database.
Can you specify the 6 standard utxo types ?
# Standard UTXO types std_types = [0, 1, 2, 3, 4, 5]

I thought there are only like 4-5 of them ? P2PKH, P2PK, P2MS, P2SH ?
also, based on the output, is it correct that:

0 --> P2PKH
1 --> P2PK
2 --> P2SH

how about 3,4,5 ?
Thanks

Trying to use the new STATUS tools...

I cloned the project, switched to the dev branch and then when I tried to execute: python run_analysis.py I received:

ImportError: No module named bitcoin_tools.analysis.status.data_dump

Probably a noob python issue.

Develop a 'server version' of STATUS

STATUS was developed having in mind that any kind of computer may be able to run it (even low RAM laptops), since we wanted to allow any user to run analysis over the UTXO set, no matter their hardware capabilities.

However, such design decision makes STATUS work using temporary json files, which slow down the whole analysis process (due to I/O and having to dump/load from json). Therefore, a server version able to run storing all the intermediate values in memory will be quite useful to speed up analysis process.

No module named 'bitcoin_tools.core'

Hello,

I am installing all the packages using pip command but still i am facing the below error.

Traceback (most recent call last):
File "C:\Users\GSK\AppData\Local\Programs\Python\Python37-32\mybit.py", line 1, in
from bitcoin_tools.core.keys import generate_keys, store_keys
ModuleNotFoundError: No module named 'bitcoin_tools.core'

How can i overcome this error. Please guide me.

Litecoin

Donyou know if it s possible to use the tool to extract addresses from litecoin core?

Ujson requires python 3.6 or greater version

Hello,

I am trying to use python bitcoin tools 0.2.3 package but it shows errors while installing i got the below error.

But in the requirement package of source contains there packages - ecdsa
python-bitcoinlib
base58
qrcode
Pillow
plyvel
matplotlib
numpy
ujson

Error:
C:\Users\rvst sateesh\Downloads>pip install python-bitcoin-tools
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please
upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop s
upport for Python 2.7 in January 2021. More details about Python 2 support in pi
p can be found at https://pip.pypa.io/en/latest/development/release-process/#pyt
hon-2-support pip 21.0 will remove support for this functionality.
Collecting python-bitcoin-tools
Using cached python_bitcoin_tools-0.2.3-py2-none-any.whl (54 kB)
Requirement already satisfied: ecdsa in c:\python27\lib\site-packages (from pyth
on-bitcoin-tools) (0.13.3)
Requirement already satisfied: Pillow in c:\python27\lib\site-packages (from pyt
hon-bitcoin-tools) (6.2.2)
Requirement already satisfied: qrcode in c:\python27\lib\site-packages (from pyt
hon-bitcoin-tools) (6.1)
Requirement already satisfied: base58 in c:\python27\lib\site-packages (from pyt
hon-bitcoin-tools) (1.0.3)
Collecting matplotlib
Using cached matplotlib-2.2.5-cp27-cp27m-win_amd64.whl (8.7 MB)
Collecting python-bitcoinlib
Using cached python-bitcoinlib-0.11.0.tar.gz (150 kB)
Requirement already satisfied: numpy in c:\python27\lib\site-packages (from pyth
on-bitcoin-tools) (1.16.6)
Collecting plyvel
Using cached plyvel-1.3.0.tar.gz (149 kB)
Collecting ujson
Using cached ujson-2.0.3.tar.gz (7.1 MB)
Installing build dependencies ... done
Getting requirements to build wheel ... done
Installing backend dependencies ... done
Preparing wheel metadata ... done
Requirement already satisfied: six in c:\python27\lib\site-packages (from qrcode
->python-bitcoin-tools) (1.15.0)
Requirement already satisfied: colorama; platform_system == "Windows" in c:\pyth
on27\lib\site-packages (from qrcode->python-bitcoin-tools) (0.4.4)
Collecting cycler>=0.10
Using cached cycler-0.10.0-py2.py3-none-any.whl (6.5 kB)
Requirement already satisfied: pytz in c:\python27\lib\site-packages (from matpl
otlib->python-bitcoin-tools) (2020.5)
Collecting kiwisolver>=1.0.1
Using cached kiwisolver-1.1.0-cp27-none-win_amd64.whl (64 kB)
Requirement already satisfied: python-dateutil>=2.1 in c:\python27\lib\site-pack
ages (from matplotlib->python-bitcoin-tools) (2.8.0)
Requirement already satisfied: backports.functools-lru-cache in c:\python27\lib
site-packages (from matplotlib->python-bitcoin-tools) (1.6.1)
Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in c:\py
thon27\lib\site-packages (from matplotlib->python-bitcoin-tools) (2.4.7)
Requirement already satisfied: setuptools in c:\python27\lib\site-packages (from
kiwisolver>=1.0.1->matplotlib->python-bitcoin-tools) (41.2.0)
Using legacy 'setup.py install' for python-bitcoinlib, since package 'wheel' is
not installed.
Using legacy 'setup.py install' for plyvel, since package 'wheel' is not install
ed.
Building wheels for collected packages: ujson
Building wheel for ujson (PEP 517) ... error
ERROR: Command errored out with exit status 1:
command: 'c:\python27\python.exe' 'c:\python27\lib\site-packages\pip_vendor
pep517_in_process.py' build_wheel 'c:\users\rvstsa1\appdata\local\temp\tmpok2q
zs'
cwd: c:\users\rvstsa
1\appdata\local\temp\pip-install-kryqze\ujson
Complete output (42 lines):
running bdist_wheel
running build
running build_ext
building 'ujson' extension
creating build
creating build\temp.win-amd64-2.7
creating build\temp.win-amd64-2.7\Release
creating build\temp.win-amd64-2.7\Release\deps
creating build\temp.win-amd64-2.7\Release\deps\double-conversion
creating build\temp.win-amd64-2.7\Release\deps\double-conversion\double-conver
sion
creating build\temp.win-amd64-2.7\Release\lib
creating build\temp.win-amd64-2.7\Release\python
C:\Users\rvst sateesh\AppData\Local\Programs\Common\Microsoft\Visual C++ for P
ython\9.0\VC\Bin\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -I./python -I
./lib -I./deps/double-conversion/double-conversion -Ic:\python27\include -Ic:\py
thon27\PC /Tp./deps/double-conversion/double-conversion\bignum-dtoa.cc /Fobuild
temp.win-amd64-2.7\Release./deps/double-conversion/double-conversion\bignum-dto
a.obj -D_GNU_SOURCE
bignum-dtoa.cc
C:\Users\rvst sateesh\AppData\Local\Programs\Common\Microsoft\Visual C++ for P
ython\9.0\VC\Bin\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -I./python -I
./lib -I./deps/double-conversion/double-conversion -Ic:\python27\include -Ic:\py
thon27\PC /Tp./deps/double-conversion/double-conversion\bignum.cc /Fobuild\temp.
win-amd64-2.7\Release./deps/double-conversion/double-conversion\bignum.obj -D_G
NU_SOURCE
bignum.cc
C:\Users\rvst sateesh\AppData\Local\Programs\Common\Microsoft\Visual C++ for P
ython\9.0\VC\Bin\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -I./python -I
./lib -I./deps/double-conversion/double-conversion -Ic:\python27\include -Ic:\py
thon27\PC /Tp./deps/double-conversion/double-conversion\cached-powers.cc /Fobuil
d\temp.win-amd64-2.7\Release./deps/double-conversion/double-conversion\cached-p
owers.obj -D_GNU_SOURCE
cached-powers.cc
C:\Users\rvst sateesh\AppData\Local\Programs\Common\Microsoft\Visual C++ for P
ython\9.0\VC\Bin\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -I./python -I
./lib -I./deps/double-conversion/double-conversion -Ic:\python27\include -Ic:\py
thon27\PC /Tp./deps/double-conversion/double-conversion\diy-fp.cc /Fobuild\temp.
win-amd64-2.7\Release./deps/double-conversion/double-conversion\diy-fp.obj -D_G
NU_SOURCE
diy-fp.cc
C:\Users\rvst sateesh\AppData\Local\Programs\Common\Microsoft\Visual C++ for P
ython\9.0\VC\Bin\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -I./python -I
./lib -I./deps/double-conversion/double-conversion -Ic:\python27\include -Ic:\py
thon27\PC /Tp./deps/double-conversion/double-conversion\double-conversion.cc /Fo
build\temp.win-amd64-2.7\Release./deps/double-conversion/double-conversion\doub
le-conversion.obj -D_GNU_SOURCE
double-conversion.cc
C:\Users\rvst sateesh\AppData\Local\Programs\Common\Microsoft\Visual C++ for P
ython\9.0\VC\Bin\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -I./python -I
./lib -I./deps/double-conversion/double-conversion -Ic:\python27\include -Ic:\py
thon27\PC /Tp./deps/double-conversion/double-conversion\fast-dtoa.cc /Fobuild\te
mp.win-amd64-2.7\Release./deps/double-conversion/double-conversion\fast-dtoa.ob
j -D_GNU_SOURCE
fast-dtoa.cc
C:\Users\rvst sateesh\AppData\Local\Programs\Common\Microsoft\Visual C++ for P
ython\9.0\VC\Bin\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -I./python -I
./lib -I./deps/double-conversion/double-conversion -Ic:\python27\include -Ic:\py
thon27\PC /Tp./deps/double-conversion/double-conversion\fixed-dtoa.cc /Fobuild\t
emp.win-amd64-2.7\Release./deps/double-conversion/double-conversion\fixed-dtoa.
obj -D_GNU_SOURCE
fixed-dtoa.cc
C:\Users\rvst sateesh\AppData\Local\Programs\Common\Microsoft\Visual C++ for P
ython\9.0\VC\Bin\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -I./python -I
./lib -I./deps/double-conversion/double-conversion -Ic:\python27\include -Ic:\py
thon27\PC /Tp./deps/double-conversion/double-conversion\strtod.cc /Fobuild\temp.
win-amd64-2.7\Release./deps/double-conversion/double-conversion\strtod.obj -D_G
NU_SOURCE
strtod.cc
C:\Users\rvst sateesh\AppData\Local\Programs\Common\Microsoft\Visual C++ for P
ython\9.0\VC\Bin\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -I./python -I
./lib -I./deps/double-conversion/double-conversion -Ic:\python27\include -Ic:\py
thon27\PC /Tp./lib/dconv_wrapper.cc /Fobuild\temp.win-amd64-2.7\Release./lib/dc
onv_wrapper.obj -D_GNU_SOURCE
dconv_wrapper.cc
C:\Users\rvst sateesh\AppData\Local\Programs\Common\Microsoft\Visual C++ for P
ython\9.0\VC\Bin\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -I./python -I
./lib -I./deps/double-conversion/double-conversion -Ic:\python27\include -Ic:\py
thon27\PC /Tc./python/ujson.c /Fobuild\temp.win-amd64-2.7\Release./python/ujson
.obj -D_GNU_SOURCE
ujson.c
C:\Users\rvst sateesh\AppData\Local\Programs\Common\Microsoft\Visual C++ for P
ython\9.0\VC\Bin\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -I./python -I
./lib -I./deps/double-conversion/double-conversion -Ic:\python27\include -Ic:\py
thon27\PC /Tc./python/objToJSON.c /Fobuild\temp.win-amd64-2.7\Release./python/o
bjToJSON.obj -D_GNU_SOURCE
objToJSON.c
C:\Users\rvst sateesh\AppData\Local\Programs\Common\Microsoft\Visual C++ for P
ython\9.0\VC\Bin\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -I./python -I
./lib -I./deps/double-conversion/double-conversion -Ic:\python27\include -Ic:\py
thon27\PC /Tc./python/JSONtoObj.c /Fobuild\temp.win-amd64-2.7\Release./python/J
SONtoObj.obj -D_GNU_SOURCE
JSONtoObj.c
C:\Users\rvst sateesh\AppData\Local\Programs\Common\Microsoft\Visual C++ for P
ython\9.0\VC\Bin\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -I./python -I
./lib -I./deps/double-conversion/double-conversion -Ic:\python27\include -Ic:\py
thon27\PC /Tc./lib/ultrajsonenc.c /Fobuild\temp.win-amd64-2.7\Release./lib/ultr
ajsonenc.obj -D_GNU_SOURCE
ultrajsonenc.c
C:\Users\rvst sateesh\AppData\Local\Programs\Common\Microsoft\Visual C++ for P
ython\9.0\VC\Bin\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -I./python -I
./lib -I./deps/double-conversion/double-conversion -Ic:\python27\include -Ic:\py
thon27\PC /Tc./lib/ultrajsondec.c /Fobuild\temp.win-amd64-2.7\Release./lib/ultr
ajsondec.obj -D_GNU_SOURCE
ultrajsondec.c
./lib/ultrajsondec.c(47) : fatal error C1083: Cannot open include file: 'stdin
t.h': No such file or directory
error: command 'C:\Users\rvst sateesh\AppData\Local\Programs\Common\Mic
rosoft\Visual C++ for Python\9.0\VC\Bin\amd64\cl.exe' failed with exit sta
tus 2

ERROR: Failed building wheel for ujson
Failed to build ujson
ERROR: Could not build wheels for ujson which use PEP 517 and cannot be installed directly.

Every package which are mentioned in the requirement is installed properly except ujson and plyvel. Ujson rewuired greater version How to overcome these errors.

Error in get_chainstate_lastblock / deobfuscate_value

Hi,

getting the last block from the chainstate fails for several chainstate heights. One example is height 176760 with the block hash 0000000000000a9569c34dd2f69d39b9763706991418b6ea3836c2b66fb57700. get_chainstate_lastblock calls deobfuscate_value where the check "assert len(value) == len(r)" fails.

I think the if statement above this check is wrong, as an arbitary number of leading zeros could be dropped and not only one.

Steps to replicate this issue:

  1. Start bitcoind and synchronize blockchain until at least block 176760
  2. Revert bitcoind to block 176760 by issuing bitcoin-cli invalidateblock 0000000000000056c50dbea31d9ad6f429aaad61ca313e72e4c00b53fd9fb3fb (invalidate block 176761)
  3. Stop bitcoind and call get_chainstate_lastblock on the current chainstate

PS: Thanks a lot for the bitcoin tools, they helped me a lot!

STATUS won't breathe

# python run_analysis.py 
Traceback (most recent call last):
  File "run_analysis.py", line 1, in <module>
    from bitcoin_tools.analysis.status.data_dump import transaction_dump, utxo_dump
  File "/usr/lib64/python2.7/bitcoin_tools/analysis/status/data_dump.py", line 3, in <module>
    from bitcoin_tools.analysis.status.utils import check_multisig, get_min_input_size, roundup_rate, check_multisig_type, \
  File "/usr/lib64/python2.7/bitcoin_tools/analysis/status/utils.py", line 3, in <module>
    import ujson
ImportError: /root/.local/lib64/python2.7/site-packages/ujson.so: undefined symbol: Buffer_AppendShortHexUnchecked

What am I doing wrong?

support segwit?

does this library support segwit transaction? I mean can I create a segwit trx using this library?

output of utxo_dump/parse_ldb

Looking at the output of these chainstate tools, I see that the "data" key is the hash160 of the utxo.

I'm curious about the key/tx_id value, e.g. "000000f03ecc02c029184f5dbab0051d1820ecab35b4c8b62a11272bd4dccfea". It's not a transaction id.

Is it just the leveldb key for that utxo?

Is there a way to get the utxo's actual blockchain transaction id (w/o parsing all the blockfiles)?

Find an alternative way to arrange outputs when parsing leveldb data

When parsing the leveldb both the tx_id and the the utxo key are stored in the parsed_utxos.json file. key is stored to allow reordering the file when performing the tx_based_analysis in order to aggregate all the data related to each transaction (since all data can not be loaded in memory due to how much RAM is required). A more optimal way should be found to do so, since the current way has a significant overhead both in terms of data storage and time of execution.

ZeroDivisionError: float division by zero

Hello there. I am trying to dump the UTXOs using the example code in the README.md:

from bitcoin_tools.analysis.status.data_dump import utxo_dump
from bitcoin_tools.analysis.status.utils import parse_ldb

# Set the version of the Bitcoin Core you are using (which defines the chainstate format)
# and the IO files.

f_utxos = "decoded_utxos.txt"
f_parsed_utxos = "parsed_utxos.txt"

# Parse all the data in the chainstate.
parse_ldb(f_utxos)
# Parses transactions and utxos from the dumped data.
utxo_dump(f_utxos, f_parsed_utxos)

# Data is stored in f_utxos and f_parsed_utxos files respectively

When it gets to the utxo_dump() function, the script exits with the following error:

Traceback (most recent call last):
  File "utxodump.py", line 14, in <module>
    utxo_dump(f_utxos, f_parsed_utxos, "bitcoin")
  File "/usr/lib/python2.7/bitcoin_tools/analysis/status/data_dump.py", line 101, in utxo_dump
    raw_np = out["amount"] / float(min_size)
ZeroDivisionError: float division by zero

I've been able to get around this by hard-coding this in data_dump.py to try and avoid an error:

# min_size = get_min_input_size(out, utxo["height"], count_p2sh, coin)
min_size = 0.00000001 # my edit

This is just a hack though, and was wondering if there was another reason why I might be getting this error?

Need help to parse chainstate

Hi, and thanks for creating the tool.
I am trying to run the example shown on the readme page to parse the UTXO database.
Unfortunately, I was getting empty files as results. I was only able to get something in the file utxos.txt after changing prefix=b'c' to prefix=b'C' in this line in utils.py

After that, the file utxos.txt looks like this:

{"value": "81e14332003bf58224ccd41bd4c94bf0d4a711fc4e1187887c", "key": "4300000136ea56f3b0ee8fbb13059cbd4521ba38074fd9832a86f4335cd7d2267c00"}
{"value": "bf8d427b007ce9617e10685f9aa2f11d19272b0692c425bc83", "key": "43000007608f08c437696f0e12bc50927ac343e48c51f4b9c4a52a484998ad188902"}
{"value": "efd20680e52900df59f7cfb19c60b7e7d4087b15ca5612523d5c53", "key": "43000009c5d6812fe6fd011c921e566bc396d840293efc1c570777d95359fca78400"}
{"value": "d7ae4807016afa6ce4bcea3bfdb9cdcc1818fdf272e695854f", "key": "4300000b99fb3d107e8573bfad3d28b52087e6fb685b156777c73157fa452ba96000"}
{"value": "989160808027000b4d2d0c2252ede24fd76f0d242903d5758697b8", "key": "430000104fbfb34ef6c699cf1ec1f0f8e8da9c6bb71d81ca1c2e449529c86b815c00"}

Does this make sense?

When I later try to run utxo_dump(f_utxos, f_parsed_utxos) on this file, I get the error:

Traceback (most recent call last):
  File "leveldb_dump.py", line 10, in <module>
    utxo_dump(f_utxos, f_parsed_utxos)
  File "/home/amanusk/Code/bitcoin_tools/bitcoin_tools/analysis/leveldb/data_dump.py", line 48, in utxo_dump
    utxo = decode_utxo(data["value"])
  File "/home/amanusk/Code/bitcoin_tools/bitcoin_tools/analysis/leveldb/utils.py", line 201, in decode_utxo
    data, offset = parse_b128(utxo, offset)
  File "/home/amanusk/Code/bitcoin_tools/bitcoin_tools/analysis/leveldb/utils.py", line 112, in parse_b128
    more_bytes = int(data, 16) & 0x80  # MSB b128 Varints have set the bit 128 for every byte but the last one,
ValueError: invalid literal for int() with base 16: ''

This happens even if I try to parse a single line of the file

I am running the latest version of bitcoin-core (Perhaps an older version is needed for the tools to work?). Is there anything special that needs to be done when starting bitcoind?
Any help is appreciated.

Sum of all utxo's is greater then current supply

Problem is that if you dump utxo set with unspent amounts and sum unspent amounts up it appears that currently it is around 20.600.000 BTC. But according to Glassnode and other blockchain parsing companies it should be around 19.200.000 BTC. I have tried to dump utxo's at different block heights, but bitcoin_tools is constantly giving me higher values.

It would be nice to understand what is cousing this increase in unspent amounts.

EDIT:
I can see that if I dump utxo for 01.03.2009 then majority of utxo have 59 btc balance. But it should be 50, same as block reward.

Which linux distribution?

I've tried installing on a couple of distros (including my usual ubuntu environment and a reasonable-looking centos), but keep running into strange build/architecture issues.

An odd question maybe, but: which linux distribution are you using with this project? I'd like to tinker with the tools a bit, and it seems easier at this point to just use whatever OS you're using than work further on debugging the build/installation problems…

Thanks! ❤️

Litecoin

I tried to parse utxo of litecoin. But apparently the prefix is different, do you happen to know the prefix of litecoin?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.