简体   繁体   English

如何从块文件中提取所有比特币地址 (revxxxxx.dat)

[英]How to extract all Bitcoin Addresses from block files (revxxxxx.dat)

I'm running a full bitcoin node and I've access to all block files (150GB) (my server has 32GB RAM and 400GB SSD)我正在运行一个完整的比特币节点,并且可以访问所有块文件(150GB)(我的服务器有 32GB RAM 和 400GB SSD)

Any idea how to extract bitcoin addresses or hash160 from block files(revxxxxx.dat)?知道如何从块文件(revxxxxx.dat)中提取比特币地址或 hash160 吗?

Simply I need to find all used bitcoin addresses so far (finding duplicated addresses is fine)只是我需要找到到目前为止所有使用过的比特币地址(找到重复的地址很好)

This is my code for doing this but it's extremely slow and useless这是我执行此操作的代码,但它非常缓慢且无用

from bitcoin.rpc import RawProxy

for blockheight in xrange(0, 543624):
    # Create a connection to local Bitcoin Core node
    p = RawProxy()

    # Get the block hash of block with height blockheight
    blockhash = p.getblockhash(blockheight)

    # Retrieve the block by its hash
    block = p.getblock(blockhash)

    # Element tx contains the list of all transaction IDs in the block
    transactions = block['tx']

    for txid in transactions:
        # Retrieve the raw transaction by ID
        try:
            raw_tx = p.getrawtransaction(txid)
        except:
            with open("error.txt", "a") as f: 
                f.write(str(blockheight) + "," + str(txid) + ",\n" )
            continue

        # Decode the transaction
        decoded_tx = p.decoderawtransaction(raw_tx)

        # Iterate through each output in the transaction
        for output in decoded_tx['vout']:
            try:
                with open('hash160.txt', 'a') as file:
                    file.write(output['scriptPubKey']['asm'].split('OP_HASH160 ')[1].split(' ')[0] + "," + output['scriptPubKey']['addresses'][0] + ",\n")
            except: 
                with open("error.txt", "a") as f: 
                    f.write(str(blockheight) + "," + str(txid) + "," + str(decoded_tx) + ",\n" )

If you want the hash160s , apparently blockparser is a great tool.如果你想要hash160s ,显然 blockparser 是一个很好的工具。

https://github.com/znort987/blockparser

You will likely need a lot of disk space, and crucially at least 128GB RAM from my understanding, or a large swap file and a lot of time.根据我的理解,您可能需要大量磁盘空间,最重要的是至少需要128GB RAM ,或者需要大量交换文件和大量时间。 It apparently has a nasty habit of crashing/seg-faulting .它显然有一个令人讨厌的crashing/seg-faulting习惯。

In the util.cpp on lines 606 and 729 , apparently the solution to make failing is to comment out // BN_CTX_init(ctx);在第606729行的util.cpp ,显然解决失败的方法是注释掉// BN_CTX_init(ctx);

Edit: sorry, change to BN_CTX_free(ctx);编辑:抱歉,更改为BN_CTX_free(ctx); on lines 606 and 729 .606729

git clone https://github.com/znort987/blockparser.git git 克隆https://github.com/znort987/blockparser.git

Install deps, and in the directory run ./make and it should work out okay.安装 deps,并在目录中运行./make ,它应该可以正常工作。

Good luck!祝你好运! Don't forget to check ./parser help first.不要忘记先检查./parser帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM