Consumes the builder and spawns `reth`. If spawning fails, returns an error.
(self)
| 457 | |
| 458 | /// Consumes the builder and spawns `reth`. If spawning fails, returns an error. |
| 459 | pub fn try_spawn(self) -> Result<RethInstance, NodeError> { |
| 460 | let bin_path = self |
| 461 | .program |
| 462 | .as_ref() |
| 463 | .map_or_else(|| RETH.as_ref(), |bin| bin.as_os_str()) |
| 464 | .to_os_string(); |
| 465 | let mut cmd = Command::new(&bin_path); |
| 466 | // `reth` uses stdout for its logs |
| 467 | cmd.stdout(Stdio::piped()); |
| 468 | |
| 469 | // Use Reth's `node` subcommand. |
| 470 | cmd.arg("node"); |
| 471 | |
| 472 | // Set the ports if they are not the default. |
| 473 | if self.http_port != DEFAULT_HTTP_PORT { |
| 474 | cmd.arg("--http.port").arg(self.http_port.to_string()); |
| 475 | } |
| 476 | |
| 477 | if self.ws_port != DEFAULT_WS_PORT { |
| 478 | cmd.arg("--ws.port").arg(self.ws_port.to_string()); |
| 479 | } |
| 480 | |
| 481 | if self.auth_port != DEFAULT_AUTH_PORT { |
| 482 | cmd.arg("--authrpc.port").arg(self.auth_port.to_string()); |
| 483 | } |
| 484 | |
| 485 | if self.p2p_port != DEFAULT_P2P_PORT { |
| 486 | cmd.arg("--discovery.port").arg(self.p2p_port.to_string()); |
| 487 | } |
| 488 | |
| 489 | // If the `dev` flag is set, enable it. |
| 490 | if self.dev { |
| 491 | // Enable the dev mode. |
| 492 | // This mode uses a local proof-of-authority consensus engine with either fixed block |
| 493 | // times or automatically mined blocks. |
| 494 | // Disables network discovery and enables local http server. |
| 495 | // Prefunds 20 accounts derived by mnemonic "test test test test test test test test |
| 496 | // test test test junk" with 10 000 ETH each. |
| 497 | cmd.arg("--dev"); |
| 498 | |
| 499 | // If the block time is set, use it. |
| 500 | if let Some(block_time) = self.block_time { |
| 501 | cmd.arg("--dev.block-time").arg(block_time); |
| 502 | } |
| 503 | } |
| 504 | |
| 505 | // If IPC is not enabled on the builder, disable it. |
| 506 | if !self.ipc_enabled { |
| 507 | cmd.arg("--ipcdisable"); |
| 508 | } |
| 509 | |
| 510 | // Open the HTTP API. |
| 511 | cmd.arg("--http"); |
| 512 | cmd.arg("--http.api").arg(API); |
| 513 | |
| 514 | // Open the WS API. |
| 515 | cmd.arg("--ws"); |
| 516 | cmd.arg("--ws.api").arg(API); |
no test coverage detected