用于将比特币区块链数据导出到JSON的工具

bitcoin-etl的Python项目详细描述


比特币ETL

Join the chat at https://gitter.im/ethereum-ethBuild StatusJoin Telegram Group

安装比特币ETL:

pip install bitcoin-etl

导出块和事务(SchemaReference):

> bitcoinetl export_blocks_and_transactions --start-block 0 --end-block 500000\
--provider-uri http://user:pass@localhost:8332 --chain bitcoin \
 --blocks-output blocks.json --transactions-output transactions.json

支撑链:

  • 比特币
  • 比特币现金
  • 狗粪蛋白
  • 莱特币
  • 破折号
  • zcash

将区块链数据连续流到控制台(Reference):

> pip install bitcoin-etl[streaming]
> bitcoinetl stream -p http://user:pass@localhost:8332 --start-block 500000

将区块链数据连续传输到google pub/sub(Reference):

> exportGOOGLE_APPLICATION_CREDENTIALS=/path_to_credentials_file.json
> bitcoinetl stream -p http://user:pass@localhost:8332 --start-block 500000 --output projects/your-project/topics/crypto_bitcoin

有关最新版本,请查看回购协议并致电

> pip install -e .[streaming] 
> python bitcoinetl.py

目录

架构

blocks.json

FieldType
hashhex_string
sizebigint
stripped_sizebigint
weightbigint
numberbigint
versionbigint
merkle_roothex_string
timestampbigint
noncehex_string
bitshex_string
coinbase_paramhex_string
transaction_countbigint

事务处理.json

FieldType
hashhex_string
sizebigint
virtual_sizebigint
versionbigint
lock_timebigint
block_numberbigint
block_hashhex_string
block_timestampbigint
is_coinbaseboolean
inputs[]transaction_input
outputs[]transaction_output
input_countbigint
output_countbigint
input_valuebigint
output_valuebigint
feebigint

事务输入

FieldType
indexbigint
spent_transaction_hashhex_string
spent_output_indexbigint
script_asmstring
script_hexhex_string
sequencebigint
required_signaturesbigint
typestring
addresses[]string
valuebigint

事务输出

FieldType
indexbigint
script_asmstring
script_hexhex_string
required_signaturesbigint
typestring
addresses[]string
valuebigint

您可以在schemas中找到列描述

注释

  1. DogeCoin API返回的输出值在版本1.14之前的客户端中有精度损失。 这是由这个问题引起的https://github.com/dogecoin/dogecoin/issues/1558
    使用旧版本导出数据的资源管理器可能会显示不正确的地址余额和交易金额。

  2. 对于zcash,vjoinsplitvalueBalance字段转换为具有“屏蔽”类型的输入和输出 https://zcash-rpc.github.io/getrawtransaction.htmlhttps://zcash.readthedocs.io/en/latest/rtd_pages/zips/zip-0243.html

导出区块链

  1. 安装python 3.5.3+https://www.python.org/downloads/

  2. 安装比特币节点https://hackernoon.com/a-complete-beginners-guide-to-installing-a-bitcoin-full-node-on-linux-2018-edition-cb8e384479ea

  3. 启动比特币。 通过在终端中执行$ bitcoin-cli getblockchaininfo,确保它下载了所需的块。 您可以导出blocks以下的块,无需等到完全同步

  4. 安装比特币ETL:

    > pip install bitcoin-etl
    
  5. 导出块和事务:

    > bitcoinetl export_all --start 0 --end 499999\
    --partition-batch-size 100\
    --provider-uri http://user:pass@localhost:8332 --chain bitcoin
    

    结果将在output子目录中,以配置单元样式分区:

    output/blocks/start_block=00000000/end_block=00000099/blocks_00000000_00000099.csv
    output/blocks/start_block=00000100/end_block=00000199/blocks_00000100_=00000199.csv
    ...
    output/transactions/start_block=00000000/end_block=00000099/transactions_00000000_00000099.csv
    ...
    

    如果路径中没有bitcoinetl命令,请改用python -m bitcoinetl

在Docker中运行

  1. 安装Dockerhttps://docs.docker.com/install/

  2. 建立Docker图像

    > docker build -t bitcoin-etl:latest .
    > docker image ls
    
  3. 从图像中运行容器

    > docker run -v $HOME/output:/bitcoin-etl/output bitcoin-etl:latest export_blocks_and_transactions --start-block 0 --end-block 500000\
        --rpc-pass '' --rpc-host 'localhost' --rpc-user '' --blocks-output blocks.json --transactions-output transactions.json
    
  4. 运行流媒体到控制台或发布/订阅

    > docker build -t bitcoin-etl:latest-streaming -f Dockerfile_with_streaming .
    > echo"Stream to console"
    > docker run bitcoin-etl:latest-streaming stream -p http://user:pass@localhost:8332 --start-block 500000
    > echo"Stream to Pub/Sub"
    > docker run -v /path_to_credentials_file/:/bitcoin-etl/ --env GOOGLE_APPLICATION_CREDENTIALS=/bitcoin-etl/credentials_file.json bitcoin-etl:latest-streaming stream -p http://user:pass@localhost:8332 --start-block 500000 --output projects/your-project/topics/crypto_bitcoin
    
  5. 请参阅https://github.com/blockchain-etl/bitcoin-etl-streaming以将流式应用程序部署到 谷歌Kubernetes引擎。

命令参考

所有命令都接受-h参数以获取帮助,例如:

> bitcoinetl export_blocks_and_transactions --help
Usage: bitcoinetl.py export_blocks_and_transactions [OPTIONS]

  Export blocks and transactions.

Options:
  -s, --start-block INTEGER   Start block
  -e, --end-block INTEGER     End block  [required]
  -b, --batch-size INTEGER    The number of blocks to export at a time.
  -p, --provider-uri TEXT     The URI of the remote Bitcoin node
  -w, --max-workers INTEGER   The maximum number of workers.
  --blocks-output TEXT        The output file for blocks. If not provided
                              blocks will not be exported. Use "-"for stdout
  --transactions-output TEXT  The output file for transactions. If not
                              provided transactions will not be exported. Use
                              "-"for stdout
  --help                      Show this message and exit.

对于--output参数,支持的类型是json格式类型是从输出文件名推断出来的。

导出块和事务

> bitcoinetl export_blocks_and_transactions --start-block 0 --end-block 500000\
  --provider-uri http://user:pass@localhost:8332 \
  --blocks-output blocks.json --transactions-output transactions.json

如果只想导出事务/块,请省略--blocks-output--transactions-output选项。

您可以调整--batch-size--max-workers以获得性能。

注意,事务输入中的required_signaturestypeaddressesvalue字段将为空。 使用enrich_transactions填充这些字段。

丰富交易

> bitcoinetl enrich_transactions  \
  --provider-uri http://user:pass@localhost:8332 \
  --transactions-input transactions.json --transactions-output enriched_transactions.json

您可以调整--batch-size--max-workers以获得性能。

获取日期的块范围

> bitcoinetl get_block_range_for_date --provider-uri http://user:pass@localhost:8332 --date=2017-03-01

此命令保证返回在指定的 日期。但是,返回的块范围也可能包含指定日期以外的块,因为块时间不是 单调的你可以过滤 blocks.json/transactions.json使用以下命令:

> bitcoinetl filter_items -i blocks.json -o blocks_filtered.json \
-p "datetime.datetime.fromtimestamp(item['timestamp']).astimezone(datetime.timezone.utc).strftime('%Y-%m-%d') == '2017-03-01'"

全部导出

> bitcoinetl export_all --provider-uri http://user:pass@localhost:8332 --start 2018-01-01 --end 2018-01-02

您可以调整--export-batch-size--max-workers以获得性能。

> bitcoinetl stream --provider-uri http://user:pass@localhost:8332 --start-block 500000
  • 默认情况下,此命令将块和事务输出到控制台。
  • 使用--output选项指定发布区块链数据的google发布/子主题, 例如projects/your-project/topics/crypto_bitcoin。块和事务将被推送到 projects/your-project/topics/crypto_bitcoin.blocksprojects/your-project/topics/crypto_bitcoin.transactions 话题。
  • 该命令将其状态保存到保存上次同步块号的last_synced_block.txt文件中d定期。
  • 指定--start-block--last-synced-block-file选项--last-synced-block-file应该指向 保存块编号的文件,从中开始对块链数据进行流式处理。
  • 使用--lag选项指定要落后于区块链头部的块数这是最简单的方法 处理链重组-他们不太可能离头部更远一个街区
  • 使用--chain选项指定链的类型,例如bitcoinlitecoindashzcash等。
  • 您可以调整--period-seconds--batch-size--max-workers以获得性能

运行测试

> pip install -e .[dev]
> echo"The below variables are optional"
> exportBITCOINETL_BITCOIN_PROVIDER_URI=http://user:pass@localhost:8332
> exportBITCOINETL_LITECOIN_PROVIDER_URI=http://user:pass@localhost:8331
> exportBITCOINETL_DOGECOIN_PROVIDER_URI=http://user:pass@localhost:8330
> exportBITCOINETL_BITCOIN_CASH_PROVIDER_URI=http://user:pass@localhost:8329
> exportBITCOINETL_DASH_PROVIDER_URI=http://user:pass@localhost:8328
> exportBITCOINETL_ZCASH_PROVIDER_URI=http://user:pass@localhost:8327
> pytest -vv

进行毒性试验

> pip install tox
> tox

bigquery中的公共数据集

https://cloud.google.com/blog/products/data-analytics/introducing-six-new-cryptocurrencies-in-bigquery-public-datasets-and-how-to-analyze-them

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java语义理解递归反向字符串返回语句   java toString()方法打印空值   java大型IN子句   如何使用JavaSpring在JavaScriptjQuery中设置post路径   java ByteArrayOutputStream已上载到服务器   java为什么轮询在SocketIO上获取数据“无法加载请求的项”?   java源代码应该以UTF8格式保存   Java数据库轮询器?   在Java中将double转换为float   java AccessDeniedException:C:\Windows\System32\drivers\etc\hosts