python-bitcoin-blockchain-parser icon indicating copy to clipboard operation
python-bitcoin-blockchain-parser copied to clipboard

Why self.blockIndexes returns an empty list?

Open Tony642 opened this issue 6 years ago • 6 comments

in blockchain.py:

def __getBlockIndexes(self, index):
    """There is no method of leveldb to close the db (and release the lock).
    This creates problem during concurrent operations.
    This function also provides caching of indexes.
    """
    if self.indexPath != index:
        db = plyvel.DB(index, compression=None)
		print("%s" % (str(db))) # added by me and it returns <plyvel.DB with name 'something' at somewhere>
        self.blockIndexes = [DBBlockIndex(format_hash(k[1:]), v)
                             for k, v in db.iterator() if k[0] == ord('b')]
        db.close()
        self.blockIndexes.sort(key=lambda x: x.height)
        self.indexPath = index
    return self.blockIndexes

returned self.blockIndexes is an empty list. Wondering why? If you still maintaining this code pls reply!

Tony642 avatar Feb 17 '19 16:02 Tony642

Are you providing the path to the index part of the datadir of a full node to Blockchain?

alecalve avatar Feb 18 '19 10:02 alecalve

Are you providing the path to the index part of the datadir of a full node to Blockchain?

this is how I use this parser:

import os from blockchain_parser.blockchain import Blockchain

blockchain = Blockchain(os.path.expanduser('/mnt/g/blockchains/blocks')) for block in blockchain.get_ordered_blocks(os.path.expanduser('/mnt/g/blockchains/blocks/index'), end=1000): print("height=%d block=%s" % (block.height, block.hash))

Tony642 avatar Feb 18 '19 13:02 Tony642

Are you providing the path to the index part of the datadir of a full node to Blockchain?

Thank you for reply but is that means I uses this parser wrong? If wrong how can I change my code?

Tony642 avatar Feb 18 '19 21:02 Tony642

I have the same problem.

evd0kim avatar Apr 09 '19 09:04 evd0kim

Sorry, my fault. I missed that a start of ordered blocks was > end. I remember this error before so it could be useful for all to check their ordered blocks interval while there is no error message.

evd0kim avatar Apr 09 '19 21:04 evd0kim

I got the following

Traceback (most recent call last):
  File "main.py", line 29, in <module>
    for block in blockchain.get_ordered_blocks(os.path.expanduser(base + '/testnet3/blocks/index'),  end=END_BLOCK):
  File "/mnt/6da521ae-93b2-44d6-bd41-422c135def79/devEnv/ventureum/projects/python-bitcoin-blockchain-parser/blockchain_parser/blockchain.py", line 167, in get_ordered_blocks
    blockIndexes = self.__getBlockIndexes(index)
  File "/mnt/6da521ae-93b2-44d6-bd41-422c135def79/devEnv/ventureum/projects/python-bitcoin-blockchain-parser/blockchain_parser/blockchain.py", line 102, in __getBlockIndexes
    for k, v in db.iterator() if True]
  File "/mnt/6da521ae-93b2-44d6-bd41-422c135def79/devEnv/ventureum/projects/python-bitcoin-blockchain-parser/blockchain_parser/index.py", line 31, in __init__
    n_version, i = _read_varint(raw_hex[pos:])
  File "/mnt/6da521ae-93b2-44d6-bd41-422c135def79/devEnv/ventureum/projects/python-bitcoin-blockchain-parser/blockchain_parser/index.py", line 21, in _read_varint
    n = (n << 7) | (data & 0x7f)
TypeError: unsupported operand type(s) for &: 'str' and 'int'

weird

timothywangdev avatar Jan 13 '20 20:01 timothywangdev