Python-Cardano / pycardano

A lightweight Cardano library in Python
https://pycardano.readthedocs.io
MIT License
215 stars 67 forks source link

TypeError when computing tx id: Field 'datum' should be of type typing.Union[...] #344

Closed nullhashpixel closed 3 weeks ago

nullhashpixel commented 5 months ago

Describe the bug After serializing a real on-chain tx with tx = Transaction.from_cbor(...) and trying to compute the tx ID with tx.id

TypeError: Field 'datum' should be of type typing.Union[pycardano.plutus.PlutusData, dict, int, bytes, pycardano.serialization.IndefiniteList, pycardano.serialization.RawCBOR, pycardano.plutus.RawPlutusData, NoneType], got [CBORTag(121, [b'\x97\x16\xc2\xad\xb3\x06\xe1\x06\x9fxk3NA\x80\x7f\xe1!\xbc\xd1c{\x94\x93X"S\xfb', b'\x00\x06C\xb0VOQ']), CBORTag(121, [b'\x97\x16\xc2\xad\xb3\x06\xe1\x06\x9fxk3NA\x80\x7f\xe1!\xbc\xd1c{\x94\x93X"S\xfb', b'\x00\x14\xdf\x10VOQ']), 1, 3575299999997] instead.

seems to be of type "list" instead, when dumping the tx:

...
        'datum': [
          CBORTag(121, [b'\x97\x16\xc2\xad\xb3\x06\xe1\x06\x9fxk3NA\x80\x7f\xe1!\xbc\xd1c{\x94\x93X"S\xfb', b'\x00\x06C\xb0VOQ']),
          CBORTag(121, [b'\x97\x16\xc2\xad\xb3\x06\xe1\x06\x9fxk3NA\x80\x7f\xe1!\xbc\xd1c{\x94\x93X"S\xfb', b'\x00\x14\xdf\x10VOQ']),
          1,
          3575299999997,
        ],
...

To Reproduce

tx = Transaction.from_cbor("84ab00838258203d1606562bcb240b03bc35eea54046ed7ec5599ac444d513c0176ec138b1ad210082582065b00ea45c90f79993784caf023869919903d39951d5212c19e3ebed9de001dc0082582065b00ea45c90f79993784caf023869919903d39951d5212c19e3ebed9de001dc020183a3005839116d40172087497feda884a47f03b9211c64b2fb5c0d4891d5aeae2f63915e63eadbe556e898e1317dbda2fab2da8c718dd40a38fca92ee5b901821a0018a97aa1581c18f0e6a5e0846d2d7ca106d06bd8a7ac9af41b67162907ee5c836842a14a766f715374617465563201028201d81858609fd8799f581c9716c2adb306e1069f786b334e41807fe121bcd1637b9493582253fb47000643b0564f51ffd8799f581c9716c2adb306e1069f786b334e41807fe121bcd1637b9493582253fb470014df10564f51ff011b00000340707c88fdff82581d611417d4664623833921ffde8d942160373f7bf48ef4b86b8697ebe8fb821a00103e7aa1581c9716c2adb306e1069f786b334e41807fe121bcd1637b9493582253fba1470014df10564f511b000002b58795b069825839011417d4664623833921ffde8d942160373f7bf48ef4b86b8697ebe8fb915e63eadbe556e898e1317dbda2fab2da8c718dd40a38fca92ee5b91a02284de9021a00044bee031a0745bf3c07582082c64f7e30c07a88c0cd22d3848fb1b29d2f03e2d329c02c4fb77838554ea1a009a1581c9716c2adb306e1069f786b334e41807fe121bcd1637b9493582253fba1470014df10564f511b0000001f972880000b5820fb140009115c497f5ef1b767ced81f93849494600e1f833bf05274b3ff20afc10d8182582065b00ea45c90f79993784caf023869919903d39951d5212c19e3ebed9de001dc020e81581c915e63eadbe556e898e1317dbda2fab2da8c718dd40a38fca92ee5b910825839011417d4664623833921ffde8d942160373f7bf48ef4b86b8697ebe8fb915e63eadbe556e898e1317dbda2fab2da8c718dd40a38fca92ee5b91a022589e712828258206a7e10e0036492f49a5a07589105b90a7ff918ebb817b180525ef24bae51202700825820ea79d84a2eef59841b98bec44b21e23b0fa3cb863e5076f9436859f504837de401a2008282582090a7e8b965fc6da57be410264e6add6f8b6e9ea1f789bf2a5acebe46060ad5ce58408bfb14de216b9f4f927f5abf2e46175042e8905f554952133f1e078393c935c4185533be6258dc079942b1343e0d0940d4dde496390b06d2adce13c2156c810a825820a4f2440da0f33fd5233ba1a1711a6ca7f897b54b30f899ec207b177ace27b0d258409e286d03f07e8ea73e6ebb88e3e6a58de3a30145492da3040253ac5beaf591f5c86efd99c0ea22eab5cb5597b54d156561e2487e90d87fd74a714f8720bfc70a0582840100d87980821a0005822e1a082fee12840001d87980821a0006c0c31a0a611411f5a11902a2a1636d736781781965706f636820343830207374616b696e672072657761726473")
tx.id

Environment and software version (please complete the following information):

cffls commented 5 months ago

Looks like this issue is fixed in the latest main branch:

>>> tx = Transaction.from_cbor("84ab00838258203d1606562bcb240b03bc35eea54046ed7ec5599ac444d513c0176ec138b1ad210082582065b00ea45c90f79993784caf023869919903d39951d5212c19e3ebed9de001dc0082582065b00ea45c90f79993784caf023869919903d39951d5212c19e3ebed9de001dc020183a3005839116d40172087497feda884a47f03b9211c64b2fb5c0d4891d5aeae2f63915e63eadbe556e898e1317dbda2fab2da8c718dd40a38fca92ee5b901821a0018a97aa1581c18f0e6a5e0846d2d7ca106d06bd8a7ac9af41b67162907ee5c836842a14a766f715374617465563201028201d81858609fd8799f581c9716c2adb306e1069f786b334e41807fe121bcd1637b9493582253fb47000643b0564f51ffd8799f581c9716c2adb306e1069f786b334e41807fe121bcd1637b9493582253fb470014df10564f51ff011b00000340707c88fdff82581d611417d4664623833921ffde8d942160373f7bf48ef4b86b8697ebe8fb821a00103e7aa1581c9716c2adb306e1069f786b334e41807fe121bcd1637b9493582253fba1470014df10564f511b000002b58795b069825839011417d4664623833921ffde8d942160373f7bf48ef4b86b8697ebe8fb915e63eadbe556e898e1317dbda2fab2da8c718dd40a38fca92ee5b91a02284de9021a00044bee031a0745bf3c07582082c64f7e30c07a88c0cd22d3848fb1b29d2f03e2d329c02c4fb77838554ea1a009a1581c9716c2adb306e1069f786b334e41807fe121bcd1637b9493582253fba1470014df10564f511b0000001f972880000b5820fb140009115c497f5ef1b767ced81f93849494600e1f833bf05274b3ff20afc10d8182582065b00ea45c90f79993784caf023869919903d39951d5212c19e3ebed9de001dc020e81581c915e63eadbe556e898e1317dbda2fab2da8c718dd40a38fca92ee5b910825839011417d4664623833921ffde8d942160373f7bf48ef4b86b8697ebe8fb915e63eadbe556e898e1317dbda2fab2da8c718dd40a38fca92ee5b91a022589e712828258206a7e10e0036492f49a5a07589105b90a7ff918ebb817b180525ef24bae51202700825820ea79d84a2eef59841b98bec44b21e23b0fa3cb863e5076f9436859f504837de401a2008282582090a7e8b965fc6da57be410264e6add6f8b6e9ea1f789bf2a5acebe46060ad5ce58408bfb14de216b9f4f927f5abf2e46175042e8905f554952133f1e078393c935c4185533be6258dc079942b1343e0d0940d4dde496390b06d2adce13c2156c810a825820a4f2440da0f33fd5233ba1a1711a6ca7f897b54b30f899ec207b177ace27b0d258409e286d03f07e8ea73e6ebb88e3e6a58de3a30145492da3040253ac5beaf591f5c86efd99c0ea22eab5cb5597b54d156561e2487e90d87fd74a714f8720bfc70a0582840100d87980821a0005822e1a082fee12840001d87980821a0006c0c31a0a611411f5a11902a2a1636d736781781965706f636820343830207374616b696e672072657761726473")
>>> tx.id
TransactionId(hex='b85e3de831ab519634afd6d2e8fde813eaa2915dd82935a459e22aa227aac4d2')