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)
Vaulty - Encrypt/Decrypt with ChaCha20-Poly1305

Vaulty Encrypt/Decrypt with ChaCha20-Poly1305 Vaulty is an extremely lightweight encryption/decryption tool which uses ChaCha20-Poly1305 to provide 25

Chris Mason 1 Jul 04, 2022
A Python library to wrap age and minisign to provide key management, encryption/decryption and signing/verification functionality.

A Python library to wrap age and minisign to provide key management, encryption/decryption and signing/verification functionality.

Vinay Sajip 3 Feb 01, 2022
Python wrapper for the Equibles cryptos API.

Equibles Cryptos API for Python Requirements. Python 2.7 and 3.4+ Installation & Usage pip install If the python package is hosted on Github, you can

Equibles 1 Feb 02, 2022
Given a string or a text file with plain text , returns his encryption using SHA256 method

Encryption using SHA256 Given a string or a .txt file with plain text. Returns his encryption using SHA256 method Requirements : pip install pyperclip

yuno 3 Jan 24, 2022
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 program generate hashes from random salts

Hash Generator This program generate hashes from random salts. How to install Install this program using python 3 and pip: pip install . In the future

Diesan Romero 2 Aug 20, 2022
EncryptAGit - Encrypt Your Git Repos

EncryptAGit - Encrypt Your Git Repos

midnite_runr 25 Oct 06, 2022
This is an experimental AES-encrypted RPC API for ESP 8266.

URPC This is an experimental AES-encrypted RPC API for ESP 8266. Usage The server folder contains a sample ESP 8266 project. Simply set the values in

Ian Walton 1 Oct 26, 2021
A lightweight encryption library in python.

XCrypt About This was initially a project to prove that I could make a strong encryption but I decided to publish it so that the internet peoples coul

Anonymous 8 Sep 10, 2022
Use this script to track the gains of cryptocurrencies using historical data and display it on a super-imposed chart in order to find the highest performing cryptocurrencies historically

crypto-performance-tracker Use this script to track the gains of cryptocurrencies using historical data and display it on a super-imposed chart in ord

Andrei 25 Aug 31, 2022
Historical Crypto Price

Made with Coingecko API, this is a VERY simple python script that asks you the crypto, date and currency you want and then proceeds to give you the price and MarketCap at that precise moment

7 Oct 14, 2022
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

Niño Sison 0 Feb 18, 2022
Tron Wallet (TRX) Crack Finder With Python Just 64 Line

TRXGEN Tron Wallet Finder and Crack With Python Tron Wallet (TRX) Crack Finder With Python Just 64 Line My tools [pycharm + anaconda3 + python3.8 + vi

MMDRZA 6 Dec 18, 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
💰 An Alfred Workflow that provides current price of cryptocurrency

Coin Ticker for Alfred Workflow An Alfred Workflow that provides current price and status about cryptocurrency from cryptocompare.com. Supports Alfred

Bumsoo Kim (Ian) 14 Nov 17, 2022
Python App To Encrypt Data (image, text, all data)

Python App To Encrypt Data (image, text, all data)

1 Oct 29, 2021
Gridlock - Encryption and decryption python project

Gridlock Encryption Encryption and decryption of plain text messages inspired by

Matthew 2 Mar 23, 2022
Active github repos of all cryptocurrencies

This repo is to maintain the list of active repositories for all cryptocurrencies that https://codemask.org uses. The active list will be automaticall

CodeMask 5 May 20, 2022
Generate bitcoin public and private keys and check if they match a filelist of existing addresses that have a nonzero balance

btc-heist Running Install deps, i.e., python3 -m pip install -r requirements.txt Download the CSV dump of all bitcoin addresses with a balance and cut

Denis Khoshaba 103 Dec 05, 2022
Generate simple encrypted messages!

Premio's Shift is a very simple text encryption, you can use it to send secret messages to your friends. Table of Content Table of Content How it work

Peterson Adami Candido 3 Aug 06, 2021