PyBC icon indicating copy to clipboard operation
PyBC copied to clipboard

Issue in common.py

Open ehsanmeisami opened this issue 2 years ago • 2 comments

When I run the read_next_block() with a .dat file from my bitcoin core folder. An error pops up. Code ran:

path = 'pybit/Blocks/'
f = 'blk02944.dat'
dat = Dat(path, f,
          verb=1)


# Read the block
dat.read_next_block()

TypeError:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
~/PyBC/read_dat.py in <module>
      [15](file:///Users/ehsan/PyBC/read_dat.py?line=14)[ 
      ]()[16](file:///Users/ehsan/PyBC/read_dat.py?line=15)[ # Read the block
----> ]()[17](file:///Users/ehsan/PyBC/read_dat.py?line=16)[ dat.read_next_block()
      ]()[18](file:///Users/ehsan/PyBC/read_dat.py?line=17)[ 
     ]()[19](file:///Users/ehsan/PyBC/read_dat.py?line=18)[ # Verify it's correct (this may already have been done on import)

~/PyBC/pybit/py3/chain.py in read_next_block(self, n, tqdm_on)
    149 
    150             # Read it
--> 151             b.read_block()
    152 
    153             # Validate, if on

~/PyBC/pybit/py3/block.py in read_block(self)
    136 
    137         # Read transactions
--> 138         self.read_trans()
    139 
    140         # Record end of block

~/PyBC/pybit/py3/block.py in read_trans(self)
    289 
    290             # Read the transaction
--> 291             trans.get_transaction()
    292 
    293             # Validate, if on

~/PyBC/pybit/py3/block.py in get_transaction(self)
    538 
    539             # Read the input data
--> 540             txIn.read_in()
    541 
    542             # Append to inputs in Trans object

~/PyBC/pybit/py3/block.py in read_in(self)
    771 
    772         # Read the script length: VarInt
--> 773         self._scriptLength = self.read_var()
    774 
    775         # Read the script sig: Variable

~/PyBC/pybit/py3/common.py in read_var(self, pr)
     77         # Get the next byte
     78         by = self.read_next(1)
---> 79         o = ord(by)
     80 
     81         if pr:

TypeError: ord() expected a character, but string of length 0 found]()

ehsanmeisami avatar Mar 11 '22 21:03 ehsanmeisami

I observe the same issue with different blocks. In my case problem lies in read_var() function, which returns an astronomically high value for pkScriptLen in read_out method for TxOut class.

artursil avatar Apr 06 '22 17:04 artursil

I'm encountering the same issue. Has anyone made any improvements to the code to resolve this problem?

Moises-mfg avatar Sep 10 '23 19:09 Moises-mfg