Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions smart_contracts/__main__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import dataclasses
import importlib
import logging
import re
import subprocess
import sys
from collections.abc import Callable
Expand Down Expand Up @@ -155,7 +156,10 @@ def build(
# Determine where to save the client
target_dir = client_output_dir if client_output_dir is not None else output_dir

# Generate Python App Clients (off-chain)
for file_name in app_spec_file_names:
logger.info(f"Generating App Client (off-chain) for {file_name}")

client_file = file_name
print(file_name)
generate_result = subprocess.run(
Expand Down Expand Up @@ -184,6 +188,49 @@ def build(
raise Exception(
f"Could not generate typed client:\n{generate_result.stdout}"
)

# Generate Python AVM Clients (on-chain)
for file_name in app_spec_file_names:
logger.info(f"Generating AVM Client (on-chain) for {file_name}")

puyapy_result = subprocess.run(
[
"puyapy-clientgen",
str(output_dir / file_name),
"--out-dir",
str(target_dir),
],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True,
)

if puyapy_result.stdout:
print(puyapy_result.stdout)

if puyapy_result.returncode:
raise Exception(
f"Could not generate client with puyapy-clientgen:\n{puyapy_result.stdout}"
)

# Apply naming convention: {contract_name}_avm_client.py
contract_name = file_name.removesuffix(".arc56.json")
generated_file = target_dir / f"client_{contract_name}.py"

# Convert PascalCase to snake_case
snake_case_name = re.sub(r"(?<!^)(?=[A-Z])", "_", contract_name).lower()
Comment thread
cusma marked this conversation as resolved.
desired_file = target_dir / f"{snake_case_name}_avm_client.py"

if not generated_file.exists():
raise FileNotFoundError(
f"Expected generated AVM client '{generated_file.name}' was not created by puyapy-clientgen"
)

if desired_file.exists():
desired_file.unlink()

generated_file.rename(desired_file)
logger.info(f"Renamed AVM client to {desired_file.name}")
if client_file:
return output_dir / client_file
return output_dir
Expand Down