baking-bad / pytezos

🐍 Python SDK for Tezos | Michelson VM in Python
https://pytezos.org
MIT License
111 stars 36 forks source link

How to retrieve lazy diff from operation result easily #326

Closed tbinetruy closed 1 year ago

tbinetruy commented 1 year ago

Hi,

I'm trying to recover the lazy diff from an operation result using from pytezos.operation.result import OperationResult, is this possible?

Here as an example of a transaction that contains some lazy storage diff in its metadata:

pytezos.using(shell="mainnet").shell.blocks[2699293].operations["op3GZiumMFEGWNPae1GDGEG2skKEibhEgusKc7XBG7gzxbSg5SD"]()["contents"][0]["metadata"]["operation_result"]["lazy_storage_diff"]

Is not empty and returns the big map diff resulting from the big map mutations:

[{'diff': {'action': 'update', 'updates': []},
  'id': '182096',
  'kind': 'big_map'},
 {'diff': {'action': 'update',
           'updates': [{'key': {'int': '11206'},
                        'key_hash': 'exprtqb1MqfaiksvYhMoQA2ByY6dVVamYn2S2SwTXWkdnkW3H6AxsM',
                        'value': {'int': '759'}}]},
  'id': '182095',
  'kind': 'big_map'},
 {'diff': {'action': 'update',
           'updates': [{'key': {'int': '1048'},
                        'key_hash': 'exprvMK81gudDY8qJbvzx3EYyhvZ8oX3mjpSaVmm41yN1ei3M8bHtY'},
                       {'key': {'int': '759'},
                        'key_hash': 'expruwoh3Bn7PaJHKFyT8tDJFPCuRvFNZDBarcbPwCY6ovzvSDkJ82',
                        'value': {'int': '3704'}}]},
  'id': '182094',
  'kind': 'big_map'},
 {'diff': {'action': 'update', 'updates': []},
  'id': '182093',
  'kind': 'big_map'},
 {'diff': {'action': 'update', 'updates': []},
  'id': '182092',
  'kind': 'big_map'},
 {'diff': {'action': 'update', 'updates': []},
  'id': '184775',
  'kind': 'big_map'}]

However, when I try to parse the transaction metadata using OperationResult, I get an empty lazy_diff:

OperationResult.from_transaction(pytezos.using(shell="mainnet").shell.blocks[2699293].operations["op3GZiumMFEGWNPae1GDGEG2skKEibhEgusKc7XBG7gzxbSg5SD"]()["contents"][0]).lazy_diff
# []

Am I using this helper properly? Is this the wanted behavior? If so, would it be possible to modify the operation result helper to easily retrieve the lazy diff?

Thanks, and let me know if I can provide you with more detail :)