无法读取某些块事务

时间:2017-12-04 05:11:13

标签: python blockchain bitcoin bitcoind

我使用python librairy'bitcoinrpc'和比特币核心玩blochain,但我永远无法在块9中读取该事务。

我甚至第二次下载了区块链,认为我的第二次比特币核心安装指向不同的数据目录时出现问题,我仍然无法阅读第9块。

你能重现这个问题吗?知道为什么吗?

用于阅读和显示第7,8,9,10行的脚本:

{
  "Meta Data": {
    "1. Information": "Intraday (1min) prices and volumes",
    "2. Symbol": "MSFT",
    "3. Last Refreshed": "2017-12-01 16:00:00",
    "4. Interval": "1min",
    "5. Output Size": "Compact",
    "6. Time Zone": "US/Eastern"
  },
  "Time Series (1min)": {
    "2017-12-01 16:00:00": {
      "1. open": "84.2000",
      "2. high": "84.2600",
      "3. low": "84.1800",
      "4. close": "84.2000",
      "5. volume": "3311341"
    },
    "2017-12-01 15:59:00": {
      "1. open": "84.2500",
      "2. high": "84.2600",
      "3. low": "84.2000",
      "4. close": "84.2000",
      "5. volume": "175169"
    },
    "2017-12-01 15:58:00": {
      "1. open": "84.2800",
      "2. high": "84.3000",
      "3. low": "84.2400",
      "4. close": "84.2550",
      "5. volume": "139520"
    }

  }
}

结果:

from bitcoinrpc.authproxy import AuthServiceProxy
import traceback

RPC_ADDRESS="127.0.0.1:8332"
RPC_USER="u"
RPC_PASSWORD="p"

def display_block_info(rpc, block_number):
    print "-------- block {} start -------".format(block_number)
    block_hash = rpc.getblockhash(block_number)
    print "Block hash : " + block_hash
    block = rpc.getblock(block_hash)
    for tx in block[u'tx']:
        print "processing transaction " + tx
        print rpc.getrawtransaction(tx, True)
    print "-------- block {} end -------".format(block_number)
    print ""

if __name__ == "__main__":
    rpc = AuthServiceProxy("http://%s:%s@%s"%(RPC_USER, RPC_PASSWORD, RPC_ADDRESS))
    block_numbers = [7, 8, 9, 10]
    for block_number in block_numbers:
        try:
            display_block_info(rpc, block_number)
        except Exception as e:
            traceback.print_exc()
            print "-------- block {} end -------".format(block_number)
            print ""

如您所见,无法使用-------- block 7 start ------- Block hash : 0000000071966c2b1d065fd446b1e485b2c9d9594acd2007ccbd5441cfc89444 processing transaction 8aa673bc752f2851fd645d6a0a92917e967083007d9c1684f9423b100540673f {u'hash': u'8aa673bc752f2851fd645d6a0a92917e967083007d9c1684f9423b100540673f', u'blockhash': u'0000000071966c2b1d065fd446b1e485b2c9d9594acd2007ccbd5441cfc89444', u'vout': [{u'scriptPubKey': {u'reqSigs': 1, u'hex': u'4104a59e64c774923d003fae7491b2a7f75d6b7aa3f35606a8ff1cf06cd3317d16a41aa16928b1df1f631f31f28c7da35d4edad3603adb2338c4d4dd268f31530555ac', u'addresses': [u'16LoW7y83wtawMg5XmT4M3Q7EdjjUmenjM'], u'asm': u'04a59e64c774923d003fae7491b2a7f75d6b7aa3f35606a8ff1cf06cd3317d16a41aa16928b1df1f631f31f28c7da35d4edad3603adb2338c4d4dd268f31530555 OP_CHECKSIG', u'type': u'pubkey'}, u'value': Decimal('50.00000000'), u'n': 0}], u'hex': u'01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0704ffff001d012bffffffff0100f2052a01000000434104a59e64c774923d003fae7491b2a7f75d6b7aa3f35606a8ff1cf06cd3317d16a41aa16928b1df1f631f31f28c7da35d4edad3603adb2338c4d4dd268f31530555ac00000000', u'vin': [{u'coinbase': u'04ffff001d012b', u'sequence': 4294967295L}], u'txid': u'8aa673bc752f2851fd645d6a0a92917e967083007d9c1684f9423b100540673f', u'blocktime': 1231472369, u'version': 1, u'confirmations': 3677, u'time': 1231472369, u'locktime': 0, u'vsize': 134, u'size': 134} -------- block 7 end ------- -------- block 8 start ------- Block hash : 00000000408c48f847aa786c2268fc3e6ec2af68e8468a34a28c61b7f1de0dc6 processing transaction a6f7f1c0dad0f2eb6b13c4f33de664b1b0e9f22efad5994a6d5b6086d85e85e3 {u'hash': u'a6f7f1c0dad0f2eb6b13c4f33de664b1b0e9f22efad5994a6d5b6086d85e85e3', u'blockhash': u'00000000408c48f847aa786c2268fc3e6ec2af68e8468a34a28c61b7f1de0dc6', u'vout': [{u'scriptPubKey': {u'reqSigs': 1, u'hex': u'4104cc8d85f5e7933cb18f13b97d165e1189c1fb3e9c98b0dd5446b2a1989883ff9e740a8a75da99cc59a21016caf7a7afd3e4e9e7952983e18d1ff70529d62e0ba1ac', u'addresses': [u'1J6PYEzr4CUoGbnXrELyHszoTSz3wCsCaj'], u'asm': u'04cc8d85f5e7933cb18f13b97d165e1189c1fb3e9c98b0dd5446b2a1989883ff9e740a8a75da99cc59a21016caf7a7afd3e4e9e7952983e18d1ff70529d62e0ba1 OP_CHECKSIG', u'type': u'pubkey'}, u'value': Decimal('50.00000000'), u'n': 0}], u'hex': u'01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0704ffff001d012cffffffff0100f2052a01000000434104cc8d85f5e7933cb18f13b97d165e1189c1fb3e9c98b0dd5446b2a1989883ff9e740a8a75da99cc59a21016caf7a7afd3e4e9e7952983e18d1ff70529d62e0ba1ac00000000', u'vin': [{u'coinbase': u'04ffff001d012c', u'sequence': 4294967295L}], u'txid': u'a6f7f1c0dad0f2eb6b13c4f33de664b1b0e9f22efad5994a6d5b6086d85e85e3', u'blocktime': 1231472743, u'version': 1, u'confirmations': 3681, u'time': 1231472743, u'locktime': 0, u'vsize': 134, u'size': 134} -------- block 8 end ------- -------- block 9 start ------- Block hash : 000000008d9dc510f23c2657fc4f67bea30078cc05a90eb89e84cc475c080805 processing transaction 0437cd7f8525ceed2324359c2d0ba26006d92d856a9c20fa0241106ee5a597c9 Traceback (most recent call last): File "blocReader.py", line 24, in <module> display_block_info(rpc, block_number) File "blocReader.py", line 15, in display_block_info print rpc.getrawtransaction(tx, True) File "c:\Python27\lib\site-packages\bitcoinrpc\authproxy.py", line 116, in __call__ raise JSONRPCException(response['error']) JSONRPCException -------- block 9 end ------- -------- block 10 start ------- Block hash : 000000002c05cc2e78923c34df87fd108b22221ac6076c18f3ade378a4d915e9 processing transaction d3ad39fa52a89997ac7381c95eeffeaf40b66af7a57e9eba144be0a175a12b11 {u'hash': u'd3ad39fa52a89997ac7381c95eeffeaf40b66af7a57e9eba144be0a175a12b11', u'blockhash': u'000000002c05cc2e78923c34df87fd108b22221ac6076c18f3ade378a4d915e9', u'vout': [{u'scriptPubKey': {u'reqSigs': 1, u'hex': u'4104fcc2888ca91cf0103d8c5797c256bf976e81f280205d002d85b9b622ed1a6f820866c7b5fe12285cfa78c035355d752fc94a398b67597dc4fbb5b386816425ddac', u'addresses': [u'15yN7NPEpu82sHhB6TzCW5z5aXoamiKeGy'], u'asm': u'04fcc2888ca91cf0103d8c5797c256bf976e81f280205d002d85b9b622ed1a6f820866c7b5fe12285cfa78c035355d752fc94a398b67597dc4fbb5b386816425dd OP_CHECKSIG', u'type': u'pubkey'}, u'value': Decimal('50.00000000'), u'n': 0}], u'hex': u'01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0704ffff001d0136ffffffff0100f2052a01000000434104fcc2888ca91cf0103d8c5797c256bf976e81f280205d002d85b9b622ed1a6f820866c7b5fe12285cfa78c035355d752fc94a398b67597dc4fbb5b386816425ddac00000000', u'vin': [{u'coinbase': u'04ffff001d0136', u'sequence': 4294967295L}], u'txid': u'd3ad39fa52a89997ac7381c95eeffeaf40b66af7a57e9eba144be0a175a12b11', u'blocktime': 1231473952, u'version': 1, u'confirmations': 3687, u'time': 1231473952, u'locktime': 0, u'vsize': 134, u'size': 134} -------- block 10 end -------

读取交易'0437cd7f8525ceed2324359c2d0ba26006d92d856a9c20fa0241106ee5a597c9'

1 个答案:

答案 0 :(得分:1)

问题很可能是由于您在没有bitcoind命令行标志的情况下运行-txindex。没有它bitcoind将只跟踪未收到的交易输出和它收到的交易。前几个块工作的原因是因为它们只包含未使用的成因输出,即新生成的硬币。您未能解析的交易是从Satoshi到Hal Finney的第一笔交易,该交易已花费,因此不再在索引中。

尝试使用-txindex运行或更好地使用getblock(block_hash, 0)来获取十六进制序列化块,然后在本地解析它(例如,使用bitcoinlib),而不是使用bitcoind检索每一笔交易。你会以这种方式加快速度。