|
24 | 24 |
|
25 | 25 | from .ethereum_cli import EthereumCLI |
26 | 26 | from .file_utils import dump_files_to_directory, write_json_file |
27 | | -from .types import TransactionReceipt, TransitionToolInput, TransitionToolOutput |
| 27 | +from .types import ( |
| 28 | + TransactionReceipt, |
| 29 | + TransitionToolContext, |
| 30 | + TransitionToolInput, |
| 31 | + TransitionToolOutput, |
| 32 | + TransitionToolRequest, |
| 33 | +) |
28 | 34 |
|
29 | 35 | model_dump_config: Mapping = {"by_alias": True, "exclude_none": True} |
30 | 36 |
|
@@ -142,6 +148,17 @@ def to_input(self) -> TransitionToolInput: |
142 | 148 | env=self.env, |
143 | 149 | ) |
144 | 150 |
|
| 151 | + def get_request_data(self) -> TransitionToolRequest: |
| 152 | + """Convert the data to a TransitionToolRequest object.""" |
| 153 | + return TransitionToolRequest( |
| 154 | + state=TransitionToolContext( |
| 155 | + fork=self.fork_name, |
| 156 | + chain_id=self.chain_id, |
| 157 | + reward=self.reward, |
| 158 | + ), |
| 159 | + input=self.to_input(), |
| 160 | + ) |
| 161 | + |
145 | 162 | def _evaluate_filesystem( |
146 | 163 | self, |
147 | 164 | *, |
@@ -298,37 +315,29 @@ def _evaluate_server( |
298 | 315 | timeout: int, |
299 | 316 | ) -> TransitionToolOutput: |
300 | 317 | """Execute the transition tool sending inputs and outputs via a server.""" |
301 | | - input_contents = t8n_data.to_input() |
302 | | - input_json = input_contents.model_dump(mode="json", **model_dump_config) |
303 | | - post_data = { |
304 | | - "state": { |
305 | | - "fork": t8n_data.fork_name, |
306 | | - "chainid": t8n_data.chain_id, |
307 | | - "reward": t8n_data.reward, |
308 | | - }, |
309 | | - "input": input_json, |
310 | | - } |
| 318 | + request_data = t8n_data.get_request_data() |
| 319 | + request_data_json = request_data.model_dump(mode="json", **model_dump_config) |
311 | 320 |
|
312 | 321 | if debug_output_path: |
313 | 322 | request_info = ( |
314 | 323 | f"Server URL: {self.server_url}\n\n" |
315 | | - f"Request Data:\n{json.dumps(post_data, indent=2)}\n" |
| 324 | + f"Request Data:\n{json.dumps(request_data_json, indent=2)}\n" |
316 | 325 | ) |
317 | 326 | dump_files_to_directory( |
318 | 327 | debug_output_path, |
319 | 328 | { |
320 | | - "input/alloc.json": input_contents.alloc, |
321 | | - "input/env.json": input_contents.env, |
| 329 | + "input/alloc.json": request_data.input.alloc, |
| 330 | + "input/env.json": request_data.input.env, |
322 | 331 | "input/txs.json": [ |
323 | 332 | tx.model_dump(mode="json", **model_dump_config) |
324 | | - for tx in input_contents.txs |
| 333 | + for tx in request_data.input.txs |
325 | 334 | ], |
326 | 335 | "request_info.txt": request_info, |
327 | 336 | }, |
328 | 337 | ) |
329 | 338 |
|
330 | 339 | response = self._server_post( |
331 | | - data=post_data, url_args=self._generate_post_args(t8n_data), timeout=timeout |
| 340 | + data=request_data_json, url_args=self._generate_post_args(t8n_data), timeout=timeout |
332 | 341 | ) |
333 | 342 | output: TransitionToolOutput = TransitionToolOutput.model_validate(response.json()) |
334 | 343 |
|
|
0 commit comments