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
597 stars 199 forks source link

Litecoin transaction parsing raise exception #320

Closed fogmoon closed 1 year ago

fogmoon commented 1 year ago

Seems when input contains P2TR addresses, the transaction parsing will raise exception :

bitcoinlib.scripts.ScriptError: Malformed script, not enough data found

Test Case:

1. input contains P2TR addresses :x:

t = Transaction.parse_hex(
    '0100000000010122614318de2d668e53481173347915aa340e48d65088a88e77eb6464f7fc34610000000000fdffffff011027000000000000160014daba82eb57ac200b44fd87030398906cc742233c03402121b2683cc78e2de583dd82e7e2be76eaf5905dc03af01178bb0f40a309fe1b9669fe491fb3bdcc04c5366fdfac9d2c5b7c1f764b94545ad55a696122e6d9f14d205029871633eecea9ebe3c12a622f40321135649c30c0a018fd8d2879a0b608cfac0063036f7264010118746578742f706c61696e3b636861727365743d7574662d380007686f742e6c74636821c15029871633eecea9ebe3c12a622f40321135649c30c0a018fd8d2879a0b608cf00000000',
    True,
    'litecoin',
)
for output in t.outputs:
    address = output.address
    amount_lit = output.value
    print('address', address, ' -- ', output.script_type, ' -- ', amount_lit)

2. output contains P2TR addresses :white_check_mark:

t = Transaction.parse_hex(
    '010000000001015ffb488733aa2fcdb8d450e1805abf11944342532c3414899b8aa2fc383a0adb0100000000fdffffff020e28000000000000225120cce2a9f263ef79321d1e32c70f09790b24fdbf52d67ff5b2a0a3f3a5006c5a6f38c7ad0000000000160014033af0d69261c8182f8ba14a73d99ab5fc93e47e0247304402203bcf4f2e14da94681e308ec8a3bc5dbd02253843c8b64da0da09fe48c2be24bd02203273c79091ba30bfe62fb2d05d964b6864085eb61f4db764dd3415189ffbdcea012103b11dba1c2aed1de161033228b787961e0d2b382fe87f78dca8d4dfc8d1fa2fae00000000',
    True,
    'litecoin',
)
for output in t.outputs:
    address = output.address
    amount_lit = output.value
    print('address', address, ' -- ', output.script_type, ' -- ', amount_lit)

:four_leaf_clover::four_leaf_clover::four_leaf_clover::four_leaf_clover: BTW. Maybe it's a similar issue with #310 which you have fixed in the lastest version. I have tried to debug and make a fix, unfortunately, I don't have a luck.

mccwdev commented 1 year ago

Fixed in https://github.com/1200wd/bitcoinlib/commit/2aac069f342211b3ddfb22e93b1690b104b2d907

The p2tr inputs can be parsed now without raising errors, but taproot scripts itself are not supported yet, so the transaction cannot be verified.