我想从比特币区块链中提取所有已确认的交易。我知道那里有存储库(例如https://github.com/znort987/blockparser),但我想自己写一些东西以便更好地理解。
bitcoind
在下载了超过 42 个块并在运行时(最小示例),我尝试了以下代码:
from bitcoin.rpc import RawProxy
proxy = RawProxy()
blockheight=42
block = proxy.getblock(proxy.getblockhash(blockheight))
tx_list = block['tx']
for tx_id in tx_list:
raw_tx = proxy.getrawtransaction(tx_id)
这会产生以下错误:
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
File "/home/donkeykong/.local/lib/python3.7/site-packages/bitcoin/rpc.py", line 315, in <lambda>
f = lambda *args: self._call(name, *args)
File "/home/donkeykong/.local/lib/python3.7/site-packages/bitcoin/rpc.py", line 239, in _call
'message': err.get('message', 'error message not specified')})
bitcoin.rpc.InvalidAddressOrKeyError: {'code': -5, 'message': 'No such mempool transaction. Use -txindex or provide a block hash to enable blockchain transaction queries. Use gettransaction for wallet transactions.'}
谁能解释我的误解?
对于复制:
- 蟒蛇版本:Python 3.7.3
- 我通过以下方式安装了 bitcoin.rpc:
pip3 install python-bitcoinlib
- bitcoin-cli 版本:Bitcoin Core RPC 客户端版本 v0.20.1