{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "deddf281", "metadata": {}, "outputs": [], "source": [ "import bitcoinquery as bq\n", "from tqdm.notebook import tqdm\n", "import random\n", "import logging" ] }, { "cell_type": "code", "execution_count": 2, "id": "edea286c", "metadata": { "scrolled": true }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "[14:04:30] INFO - Start loading block_index\n", "[14:04:32] INFO - Longest chain: 701178\n", "[14:04:35] INFO - Successfully opened tx_index DB!\n" ] } ], "source": [ "db = bq.BitcoinDB(\"/Volumes/Extreme SSD/bitcoin\")" ] }, { "cell_type": "code", "execution_count": 3, "id": "06157a17", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'txid': '97d1b00fcef1f19531a19bb1722635341a9f2ad261ecf6eed89eca2cbd3bb3ee',\n", " 'input': [{'txid': 'ac348c1a49389c4408ac8541b79dba83a25a817f199c0a5474fc647494cb07e5',\n", " 'vout': 0}],\n", " 'output': [{'value': 2020000,\n", " 'script_type': 'Pay2PublicKeyHash',\n", " 'addresses': ['1JwhvD6mwpRzAhVKihWcxXPJNeFKJGgHUh']},\n", " {'value': 300000,\n", " 'script_type': 'Pay2PublicKeyHash',\n", " 'addresses': ['13vCrWerFRP2rULtNUpV5bTipDfubVtm7U']}]}" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "db.get_transaction(\"97d1b00fcef1f19531a19bb1722635341a9f2ad261ecf6eed89eca2cbd3bb3ee\")" ] }, { "cell_type": "code", "execution_count": 4, "id": "5b51a065", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'txid': '97d1b00fcef1f19531a19bb1722635341a9f2ad261ecf6eed89eca2cbd3bb3ee',\n", " 'input': [{'value': 2323200,\n", " 'script_type': 'Pay2ScriptHash',\n", " 'addresses': ['3GA77qTGUyPRT17j6UdBPdZ8uLr2rsNUzU']}],\n", " 'output': [{'value': 2020000,\n", " 'script_type': 'Pay2PublicKeyHash',\n", " 'addresses': ['1JwhvD6mwpRzAhVKihWcxXPJNeFKJGgHUh']},\n", " {'value': 300000,\n", " 'script_type': 'Pay2PublicKeyHash',\n", " 'addresses': ['13vCrWerFRP2rULtNUpV5bTipDfubVtm7U']}]}" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "db.get_transaction(\"97d1b00fcef1f19531a19bb1722635341a9f2ad261ecf6eed89eca2cbd3bb3ee\", connected=True)" ] }, { "cell_type": "code", "execution_count": 5, "id": "0faafc56", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'value': 2323200,\n", " 'script_type': 'Pay2ScriptHash',\n", " 'addresses': ['3GA77qTGUyPRT17j6UdBPdZ8uLr2rsNUzU']}" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "db.get_transaction(\"ac348c1a49389c4408ac8541b79dba83a25a817f199c0a5474fc647494cb07e5\")[\"output\"][0]" ] }, { "cell_type": "code", "execution_count": 6, "id": "3f284d89", "metadata": {}, "outputs": [], "source": [ "big_blk = db.get_block(700000)" ] }, { "cell_type": "code", "execution_count": 7, "id": "5b3b710d", "metadata": {}, "outputs": [], "source": [ "big_blk = db.get_block(100000, connected=True)" ] }, { "cell_type": "code", "execution_count": 8, "id": "11612390", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "4" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "len(big_blk[\"txdata\"])" ] }, { "cell_type": "code", "execution_count": 9, "id": "7deb3c21", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "701178" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "db.get_max_height()" ] }, { "cell_type": "code", "execution_count": 10, "id": "14df2f2f", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'block_hash': '0000000000000000000590fc0f3eba193a278534220b2b37e9849e1a770ca959',\n", " 'n_version': 210100,\n", " 'n_height': 700000,\n", " 'n_status': 157,\n", " 'n_tx': 1276,\n", " 'n_file': 2721,\n", " 'n_data_pos': 28521169,\n", " 'n_undo_pos': 4290720,\n", " 'block_header': {'version': 1073733636,\n", " 'prev_blockhash': '0000000000000000000aa3ce000eb559f4143be419108134e0ce71042fc636eb',\n", " 'merkle_root': '1f8d213c864bfe9fb0098cecc3165cce407de88413741b0300d56ea0f4ec9c65',\n", " 'time': 1631333672,\n", " 'bits': 386877668,\n", " 'nonce': 2881644503}}" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "db.get_block_header(700000)" ] }, { "cell_type": "code", "execution_count": 11, "id": "8723a97e", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'0000000099c744455f58e6c6e98b671e1bf7f37346bfd4cf5d0274ad8ee660cb'" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "db.get_hash_from_height(10000)" ] }, { "cell_type": "code", "execution_count": 12, "id": "b435aa89", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "10000" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "db.get_height_from_hash(\"0000000099c744455f58e6c6e98b671e1bf7f37346bfd4cf5d0274ad8ee660cb\")" ] }, { "cell_type": "code", "execution_count": 13, "id": "cec3043a", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "f6ae6c428fdb4098b89f259576e61d7a", "version_major": 2, "version_minor": 0 }, "text/plain": [ " 0%| | 0/700000 [00:00