From 4cf16545c64e16d90fcaebf707b1406d42bb0ad4 Mon Sep 17 00:00:00 2001 From: danceratopz Date: Thu, 24 Aug 2023 12:07:17 +0200 Subject: [PATCH] t8n: write output body to sys.stdout if specified --- .../evm_tools/t8n/__init__.py | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/ethereum_spec_tools/evm_tools/t8n/__init__.py b/src/ethereum_spec_tools/evm_tools/t8n/__init__.py index 72c7002b6d..54aa230488 100644 --- a/src/ethereum_spec_tools/evm_tools/t8n/__init__.py +++ b/src/ethereum_spec_tools/evm_tools/t8n/__init__.py @@ -404,17 +404,20 @@ def run(self) -> int: json_state = self.alloc.to_json() json_result = self.result.to_json() + json_output = {} + if self.options.output_body: - txs_rlp_path = os.path.join( - self.options.output_basedir, - self.options.output_body, - ) txs_rlp = "0x" + rlp.encode(self.txs.all_txs).hex() - with open(txs_rlp_path, "w") as f: - json.dump(txs_rlp, f) - self.logger.info(f"Wrote transaction rlp to {txs_rlp_path}") - - json_output = {} + if self.options.output_body == "stdout": + json_output["body"] = txs_rlp + else: + txs_rlp_path = os.path.join( + self.options.output_basedir, + self.options.output_body, + ) + with open(txs_rlp_path, "w") as f: + json.dump(txs_rlp, f) + self.logger.info(f"Wrote transaction rlp to {txs_rlp_path}") if self.options.output_alloc == "stdout": json_output["alloc"] = json_state