1200wd / bitcoinlib

Bitcoin and other Cryptocurrencies Library for Python. Includes a fully functional wallet, Mnemonic key generation and management and connection with various service providers to receive and send blockchain and transaction information.
http://bitcoinlib.readthedocs.io/
GNU General Public License v3.0
596 stars 199 forks source link

BitcoindClient does not accept "strict=False" which causes errors during transaction parsing #342

Closed pputnik closed 10 months ago

pputnik commented 10 months ago

Similar to https://github.com/1200wd/bitcoinlib/issues/338 using BitcoindClient instead of Service:

from bitcoinlib.services.bitcoind import *

bdc = BitcoindClient.from_config('/path/to/bitcoin.conf')
txid = "67e758b27df26ad609f943b30e5bbb270d835b737c8b3df1a7944ba08df8b9a2"
t = bdc.gettransaction(txid)

print(t.as_json())

The error:

    self.script = Script.parse_bytes(self.unlocking_script, strict=strict)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.pyenv/versions/3.11.4/lib/python3.11/site-packages/bitcoinlib/scripts.py", line 492, in parse_bytes
    return cls.parse_bytesio(BytesIO(script), message, tx_data, data_length, strict, _level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.pyenv/versions/3.11.4/lib/python3.11/site-packages/bitcoinlib/scripts.py", line 351, in parse_bytesio
    raise ScriptError(str(e))
bitcoinlib.scripts.ScriptError: Expected a sequence of 69 bytes, got 70

I tried

bdc = BitcoindClient.from_config('/path/to/bitcoin.conf', strict=False)

but got error TypeError: BitcoindClient.from_config() got an unexpected keyword argument 'strict'

Could you please lmk what is the workaround for this case?

mccwdev commented 10 months ago

The BitcoindClient was only accepting positional arguments. Now using **kwargs to accept only extra keyword arguments.

Fixed in commit d935eea0744738667e32ce4bac06c571ec679458