High Performance Blockchain Deserializer

Overview

bitcoin-explorer

CI PyPI

bitcoin_explorer is an efficient library for reading bitcoin-core binary blockchain file as a database (utilising multi-threading).

This package is ported using pyO3 from rust library bitcoin-explorer

Installation

MacOS, Windows, and Linux wheels are provided.

Use pip install bitcoin-explorer to install.

Documentation

This library has a Rust version, go to Rust Documentation

For python documentation, go to Documentation.

Compatibility Note

This package deals with the binary file of another software Bitcoin Core. It might not be compatible with older Bitcoin Core versions.

Currently, it is compatible with Bitcoin Core version Bitcoin Core version v0.21.1.0-g194b9b8792d9b0798fdb570b79fa51f1d1f5ebaf Copyright (C) 2009-2020 The Bitcoin Core developers.

Examples

It contains one class BitcoinDB.

import bitcoin_explorer as bex

# parse the same path as `--datadir` argument for `bitcoind`.
db = bex.BitcoinDB("~/Bitcoin")

# get the length of the longest chain currently on disk.
db.get_max_height()

# get block of a certain height
db.get_block(1000)

# to retrieve the connected outputs of each inputs as well.
# note that this is inefficient.
# Use `get_block_iter_range(end, connected=True)` for better performance.
db.get_block(1000, connected=True)

# get block hash of a certain height.
db.get_hash_from_height(1000)

# a fast method for getting just the header.
# in memory query, no disk access
db.get_block_header(1000)

# get block of height 1000.
db.get_height_from_hash("some hash")

# get transaction from txid.
# This queries the `levelDB` each time, thus it is relatively slow.
db.get_transaction("some txid")

# get the height of the block which this transaction belongs.
db.get_height_from_txid("some txid")

# get the script type and addresses from a script public key
db.parse_script("some hex script pubic key")

# use iterator
for block in db.get_block_iter_range(start=1000, end=2000):
    do_something_with(block)

# use iterator, iterate over heights
for block in db.get_block_iter_array(heights=[1, 3, 5, 7, 9]):
    do_something_with(block)
    
# use iterator, connect outpoints
# !! This requires a minimal amount of 32GB memory. 
for block in db.get_block_iter_range(end=700000, connected=True):
    do_something_with(block)
You might also like...
A little side-project API for me to learn about Blockchain and Tokens

BlockChain API I built this little side project to learn more about Blockchain and Tokens. It might be maintained and implemented to other projects bu

A workshop to build an NFT smart contract on the polygon blockchain
A workshop to build an NFT smart contract on the polygon blockchain

Polygon NFT Workshop This is an interactive workshop that guides you through the steps to deploy an NFT smart contract on the Polygon blockchain. By t

Blockchain Python Implementation

Blockchain Python Implementation

Accounting Cycle Program with Blockchain Component

In the first iteration of my accounting cycle program, I talked about adding in a blockchain component that allows the user to verify the inegrity of

Best blockchain in the world

alphachain Best blockchain in the world!!! Can be used to implement Layer 2 cryptocurrency protocol just click alphachain.py and it will execute autom

Cryptocurrency with implementet Blockchain

Cryptocurrency with implementet Blockchain

Distributed, blockchain based hashtables middleware for deduplication of file uploads to the cloud

distributed-blockchain-based-secure-file-dedupe Searching is Distributed, Block and Access List for each upload is unique and it is stored in a single

This is simple Blockchain ,miner and wallet to send crypto using python

pythonBlockchain-SImple This is simple Blockchain ,miner and wallet to send crypto using python It is simple Blocchain so it can only dobasic work usi

Retrieve ECDSA signature R,S,Z values from blockchain rawtx or txid.

rsz Retrieve ECDSA signature R,S,Z values from blockchain rawtx or txid. Info The script parse the data of rawtx to fetch all the inputs in the transa

Comments
  • Erron on initialization (pyo3_runtime.PanicException)

    Erron on initialization (pyo3_runtime.PanicException)

    I get following error during initialization (Python 3.8.11).

    import bitcoin_explorer as bex db = bex.BitcoinDB(r"D:\BTC\Chain")

    [19:02:59] INFO - Start loading block_index [19:03:00] INFO - Longest chain: 702696 thread '' panicked at 'called Result::unwrap() on an Err value: Utf8Error { valid_up_to: 58, error_len: Some(1) }', C:\Users\runneradmin.cargo\registry\src\github.com-1ecc6299db9ec823\leveldb-0.8.6\src\database\error.rs:29:72 note: run with RUST_BACKTRACE=1 environment variable to display a backtrace Traceback (most recent call last): File "C:/Users/T/PycharmProjects/BTC_explorer/main.py", line 3, in db = bex.BitcoinDB(r"D:\BTC\Chain") File "D:\anaconda3\envs\env_btc\lib\site-packages\bitcoin_explorer_init_.py", line 82, in init self.db = _BitcoinDB(str(path), tx_index) pyo3_runtime.PanicException: called Result::unwrap() on an Err value: Utf8Error { valid_up_to: 58, error_len: Some(1) } Process finished with exit code 1

    I have data downloaded using Bitcoin Core in D:\BTC\Chain\blocks (.dat files) and D:\BTC\Chain\blocks\index (.ldb files).

    bug 
    opened by TomaszKot2 13
  • Why the results doesn't match?

    Why the results doesn't match?

    I'm using the explorer in a regtest mode bitcoin-core and when I use the function "db.get_transaction()" for a specific transaction, it returns the following data:

    [23:35:22] INFO - Start loading block_index
    [23:35:23] INFO - Successfully opened tx_index DB!
    {'txid': '4f820b821643587d0fb89720e0b2e8e32b6db4533e12c94ec1fee16b3539f7ab', 'input': ({'txid': '39a1aca5790d939d75159e43fc02c77a621c3c6119bc18fd32efee66e17b5657', 'vout': 1},), 'output': ({'value': 2000000000, 'addresses': ('bc1qjpjrryrqxykpe7x7uq63a0jfcc0upral3682a7',)}, {'value': 1999999718, 'addresses': ('bc1qxp54zryddh5jlqnd0u3cmrkt6j7eyrsq2769uu',)})}
    

    If I check the same transaction with bitcoin-cli gettransaction I get the following data:

    {
      "amount": 20.00000000,
      "confirmations": 10,
      "blockhash": "0d93629f7e02ec6c5f5872e36a339df37503629ce77ddf217aa6d40640bad60a",
      "blockheight": 203,
      "blockindex": 3,
      "blocktime": 1659992136,
      "txid": "4f820b821643587d0fb89720e0b2e8e32b6db4533e12c94ec1fee16b3539f7ab",
      "walletconflicts": [
      ],
      "time": 1659991965,
      "timereceived": 1659991965,
      "bip125-replaceable": "no",
      "details": [
        {
          "address": "bcrt1qjpjrryrqxykpe7x7uq63a0jfcc0uprale4953y",
          "category": "receive",
          "amount": 20.00000000,
          "label": "",
          "vout": 0
        }
      ],
      "hex": "0200000000010157567be166eeef32fd18bc19613c1c627ac702fc439e15759d930d79a5aca1390100000000feffffff0200943577000000001600149064319060312c1cf8dee0351ebe49c61fc08fbfe6923577000000001600143069510c8d6de92f826d7f238d8ecbd4bd920e000247304402204b3999d93bca110be6985b765d6ad990b0517c1531a862cf252030dbf08261c40220484c01ce5656c79890fb3db9b1d727bbea7def0b17f0fe3335fe52653969287801210382d5768096f162475257659c99556999cea6d622a4c583ddc7d5fd40ea536118af000000"
    }
    
    

    Why the data don't match? for example, doesn't appear in the return of the bitcoin explorer, or if I check the transaction that appears in the input of the bitcoin explorer ('39a1aca5790d939d75159e43fc02c77a621c3c6119bc18fd32efee66e17b5657') bitcoin-cli returns that is invalid.

    Thanks for reading.

    opened by JavierPorron 1
Releases(v1.2.15)
Bitcoin & Lightning Container Manager for facilitating development tools

Torch-cli Bitcoin & Lightning Container Manager for facilitating development too

Gray Finance 3 Aug 22, 2022
Get the SHA256 hash of any file with this Python Script

Hashfile-SHA256 A SHA256 hash verifying script, written in python. Report Bug Table of Contents About The Project Built With Getting Started Prerequis

Ethan Gallucci 1 Nov 01, 2021
Bitcoin Clipper malware made in Python.

a BTC Clipper or a "Bitcoin Clipper" is a type of malware designed to target cryptocurrency transactions.

Nightfall 96 Dec 30, 2022
This python module can analyse cryptocurrency news for any number of coins given and return a sentiment. Can be easily integrated with a Trading bot to keep an eye on the news.

Python script that analyses news headline or body sentiment and returns the overall media sentiment of any given coin. It can take multiple coins an

185 Dec 22, 2022
This is a fully functioning Binance trading bot that takes into account the news sentiment for the top 100 crypto feeds.

This is a fully functioning Binance trading bot that takes into account the news sentiment for the top 100 crypto feeds.

Andrei 1.5k Jan 04, 2023
J. Brandon Walker 1 May 13, 2022
A community effort to bring back Duino-Coin

Duino-Coin-Revived A community effort to bring back Duino-Coin! Along with reviving the cryptocurrency, we will add many improvements to it, including

1 Dec 22, 2021
Python FFI bindings for libsecp256k1 (maintained)

secp256k1-py Python FFI bindings for libsecp256k1 (an experimental and optimized C library for EC operations on curve secp256k1). Previously maintaine

Rusty Russell 29 Dec 29, 2022
JS Deobfuscation is a Python script that deobfuscates JS code and it's time saver for you

JS Deobfuscation is a Python script that deobfuscate JS code and it's time saver for you. Although it may not work with high degrees of obfuscation, it's a pretty nice tool to help you even if it's j

Quatrecentquatre 3 May 01, 2022
Advanced Digital Envelope System Using Cryptography Techniques (Encryption & Decryption)

Advanced-Digital-Envelope-System Advanced Digital Envelope System Using Cryptography Encryption Techniques The digital envelope system is the techniqu

NelakurthiSudheer 2 Jan 03, 2022
SSEPy: Implementation of searchable symmetric encryption in pure Python

SSEPy: Implementation of searchable symmetric encryption in pure Python Searchable symmetric encryption, one of the research hotspots in applied crypt

33 Dec 05, 2022
Cryptocurrency trading bot with a graphical user interface with support for simulations, backtests, optimizations, and running live bots.

Cryptocurrency trading bot with a graphical user interface with support for simulations, backtests, optimizations, and running live bots.

Mihir Shrestha 834 Dec 30, 2022
Crypto Stats and Tweets Data Pipeline using Airflow

Crypto Stats and Tweets Data Pipeline using Airflow Introduction Project Overview This project was brought upon through Udacity's nanodegree program.

Matthew Greene 1 Nov 24, 2021
SimpleWallet - Simple wallet for Bitcoin

Simple Wallet This is a basic python starter package to be used as a template fo

Mystic 1 Jan 08, 2022
Looks for Bitcoin Wallets starting 1 compresses and Uncompressesed, segwit address and MultiSig starting 3.

Looks for Bitcoin Wallets starting 1 compresses and Uncompressesed, segwit address and MultiSig starting 3. Pick your starting and stop numbers to start looking. Need a database of addresses to check

10 Dec 22, 2022
Fully configurable automated python script to collect most visted pages based on google dork

Ranked pages collector Fully configurable automated python script to collect most visted pages based on google dork Usage This project is still under

Security Analyzer 9 Sep 10, 2022
Message Encrypt and decrypt software // allows you to encrypt the secrete message and decrypt Another Encryption Message. |

Message-Encrypy-Decrypt-App Message Encrypt and decrypt software // allows you to encrypt the secrete message and decrypt Another Encryption Message.

Abdulrahman-Haji 2 Dec 16, 2021
bitcoin-ticker is a E-ink ticker that shows usefull information about bitcoin

bitcoin-ticker bitcoin-ticker is a E-ink ticker that shows usefull information about bitcoin. Due to the limited refresh lifetime, new information is

32 Nov 09, 2022
Gridlock - Encryption and decryption python project

Gridlock Encryption Encryption and decryption of plain text messages inspired by

Matthew 2 Mar 23, 2022
Amazing CryptoWAF was a CTF challenge for ALLES! CTF 2021

ctf-cryptowaf The AmazingCryptoWAF ™️ is used by the "noter" web app, to offer automagically military encryption for any user data. Even if an attacke

32 Jan 02, 2023