Skip to content

Commit b3dc70f

Browse files
gurukamathSamWilsn
authored andcommitted
add additional receipt fields
1 parent ac62722 commit b3dc70f

File tree

1 file changed

+31
-9
lines changed

1 file changed

+31
-9
lines changed

src/ethereum_spec_tools/evm_tools/t8n/t8n_types.py

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -292,14 +292,7 @@ def get_receipts_from_output(
292292
else:
293293
decoded_receipt = receipt
294294

295-
gas_consumed = decoded_receipt.cumulative_gas_used
296-
297-
receipts.append(
298-
{
299-
"transactionHash": "0x" + tx_hash.hex(),
300-
"gasUsed": hex(gas_consumed),
301-
}
302-
)
295+
receipts.append((tx_hash, decoded_receipt))
303296

304297
return receipts
305298

@@ -330,6 +323,35 @@ def update(self, t8n: "T8N", block_env: Any, block_output: Any) -> None:
330323
self.requests = block_output.requests
331324
self.requests_hash = t8n.fork.compute_requests_hash(self.requests)
332325

326+
def json_encode_receipts(self) -> Any:
327+
"""
328+
Encode receipts to JSON.
329+
"""
330+
receipts_json = []
331+
for tx_hash, receipt in self.receipts:
332+
receipt_dict = {"transactionHash": "0x" + tx_hash.hex()}
333+
334+
if hasattr(receipt, "succeeded"):
335+
receipt_dict["succeeded"] = receipt.succeeded
336+
else:
337+
assert hasattr(receipt, "post_state")
338+
receipt_dict["post_state"] = "0x" + receipt.post_state.hex()
339+
340+
receipt_dict["gasUsed"] = hex(receipt.cumulative_gas_used)
341+
receipt_dict["bloom"] = "0x" + receipt.bloom.hex()
342+
receipt_dict["logs"] = [
343+
{
344+
"address": "0x" + log.address.hex(),
345+
"topics": ["0x" + topic.hex() for topic in log.topics],
346+
"data": "0x" + log.data.hex(),
347+
}
348+
for log in receipt.logs
349+
]
350+
351+
receipts_json.append(receipt_dict)
352+
353+
return receipt_dict
354+
333355
def to_json(self) -> Any:
334356
"""Encode the result to JSON"""
335357
data = {}
@@ -363,7 +385,7 @@ def to_json(self) -> Any:
363385
for idx, error in self.rejected.items()
364386
]
365387

366-
data["receipts"] = self.receipts
388+
data["receipts"] = self.json_encode_receipts()
367389

368390
if self.requests_hash is not None:
369391
assert self.requests is not None

0 commit comments

Comments
 (0)