Skip to content

Commit

Permalink
feat: include additional flags to ape networks run
Browse files Browse the repository at this point in the history
  • Loading branch information
0xthedance committed Jan 28, 2025
1 parent a87fba6 commit eab5667
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
13 changes: 12 additions & 1 deletion src/ape/api/networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,10 @@ def base_fee_multiplier(self) -> float:
"""
return self.config.get("base_fee_multiplier", 1.0)

@base_fee_multiplier.setter
def base_fee_multiplier(self, value: float):
self.config["base_fee_multiplier"] = value

@property
def chain_id(self) -> int:
"""
Expand Down Expand Up @@ -1038,9 +1042,12 @@ def block_time(self) -> int:
mainnet:
block_time: 15
"""

return self.config.get("block_time", 0)

@block_time.setter
def block_time(self, value: int):
self.config["block_time"] = value

@property
def transaction_acceptance_timeout(self) -> int:
"""
Expand All @@ -1052,6 +1059,10 @@ def transaction_acceptance_timeout(self) -> int:
"transaction_acceptance_timeout", DEFAULT_TRANSACTION_ACCEPTANCE_TIMEOUT
)

@transaction_acceptance_timeout.setter
def transaction_acceptance_timeout(self, value: int):
self.config["transaction_acceptance_timeout"] = value

@cached_property
def explorer(self) -> Optional["ExplorerAPI"]:
"""
Expand Down
24 changes: 23 additions & 1 deletion src/ape_networks/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,15 @@ def make_sub_tree(data: dict, create_tree: Callable) -> Tree:
@cli.command(short_help="Start a node process")
@ape_cli_context()
@network_option(default="ethereum:local:node")
def run(cli_ctx, provider):
@click.option("--block-time", default=None, type=int, help="Block time in seconds")
@click.option("--base-fee-multiplier", default=None, type=float, help="Base fee multiplier")
@click.option(
"--transaction-timeout",
default=None,
type=int,
help="Transaction acceptance timeout in seconds",
)
def run(cli_ctx, provider, block_time, base_fee_multiplier, transaction_timeout):
"""
Start a subprocess node as if running independently
and stream stdout and stderr.
Expand All @@ -128,13 +136,26 @@ def run(cli_ctx, provider):
elif provider.is_connected:
cli_ctx.abort("Process already running.")

# Set block time if provided
if block_time is not None:
provider.network.block_time = block_time

# Set transaction acceptance timeout if provided
if transaction_timeout is not None:
provider.network.transaction_acceptance_timeout = transaction_timeout

# Set base fee multiplier if provided
if base_fee_multiplier is not None:
provider.network.base_fee_multiplier = base_fee_multiplier

# Start showing process logs.
original_level = cli_ctx.logger.level
original_format = cli_ctx.logger.fmt
cli_ctx.logger.set_level(LogLevel.DEBUG)

# Change format to exclude log level (since it is always just DEBUG)
cli_ctx.logger.format(fmt="%(message)s")

try:
_run(cli_ctx, provider)
finally:
Expand All @@ -143,6 +164,7 @@ def run(cli_ctx, provider):


def _run(cli_ctx, provider: "SubprocessProvider"):

provider.connect()
if process := provider.process:
try:
Expand Down

0 comments on commit eab5667

Please sign in to comment.