Joh*_*kin 11 bitcoin bitcoind blockchain
我现在拥有所有150GB比特币块?如何打开它们并用Python读取它们?到目前为止,我需要提取所有使用过的hash160
我试图用Berkeley DB打开它们,但没有成功,似乎这些文件不是Berkeley DB,blkxxxxx.dat和revxxxxx.dat文件之间有什么区别?似乎revxxxxx.dat文件的文件大小有所改善
小智 0
您可以使用 python-bitcoin-blockchain-parser 库。它允许您解析存储在 .dat 文件中的比特币区块链数据。该库提供了一个接口来访问来自块、交易和输出的信息。
pip 安装比特币区块链解析器
安装该库后,您可以使用以下代码从比特币块中提取使用的 hash160 地址:
from blockchain_parser.blockchain import Blockchain
blockchain = Blockchain("/path/to/bitcoin/blocks/folder")
hash160_addresses = set()
for block in blockchain.get_unordered_blocks():
for tx in block.transactions:
for output in tx.outputs:
if output.addresses:
for address in output.addresses:
hash160_addresses.add(address.address)
# Print all the hash160 addresses
for address in hash160_addresses:
print(address)
Run Code Online (Sandbox Code Playgroud)
在处理比特币区块链时,您通常使用 blkxxxxx.dat 文件来访问区块数据,而 revxxxxx.dat 文件由 Bitcoin Core 内部使用以进行高效的区块查找。
请记住,由于其规模,使用整个比特币区块链数据集可能会占用大量资源。最初在区块子集上测试代码可能会有所帮助,或者考虑使用像 Bitcoin Core 的 LevelDB 这样的数据库或其他专用工具来更有效地处理数据。
| 归档时间: |
|
| 查看次数: |
4057 次 |
| 最近记录: |