forked from kkrt-labs/kakarot-rpc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: deploy account contract + execute at address utils (kkrt-labs#550)
<!--- Please provide a general summary of your changes in the title above --> This PR provides python utilities in order to easily deploy a contract on Kakarot and execute calldata on deployed contracts. <!-- Give an estimate of the time you spent on this PR in terms of work days. Did you spend 0.5 days on this PR or rather 2 days? --> Time spent on this PR: 1 day ## Pull request type <!-- Please try to limit your pull request to one type, submit multiple pull requests if needed. --> Please check the type of change your PR introduces: - [ ] Bugfix - [x] Feature - [ ] Code style update (formatting, renaming) - [ ] Refactoring (no functional changes, no api changes) - [ ] Build related changes - [ ] Documentation content changes - [ ] Other (please describe): ## What is the current behavior? <!-- Please describe the current behavior that you are modifying, or link to a relevant issue. --> No script available to deploy a contract account on Kakarot or execute calldata on a deployed contract. Resolves N/A ## What is the new behavior? <!-- Please describe the behavior or changes that are being added by this PR. --> - Provide a script to deploy a contract account or execute calldata on a deployed contract.
- Loading branch information
Showing
7 changed files
with
421 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# Imports | ||
import io | ||
import logging | ||
import os | ||
import zipfile | ||
from pathlib import Path | ||
|
||
import pandas as pd | ||
import requests | ||
from dotenv import load_dotenv | ||
|
||
load_dotenv() | ||
logging.basicConfig(level=logging.INFO) | ||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def get_resources( | ||
coverage_dir: Path = Path("coverage"), base_branch_name: str = "main" | ||
): | ||
# Pull latest main artifacts | ||
response = requests.get( | ||
"https://api.github.com/repos/sayajin-labs/kakarot/actions/artifacts" | ||
) | ||
artifacts = ( | ||
pd.DataFrame( | ||
[ | ||
{**artifact["workflow_run"], **artifact} | ||
for artifact in response.json()["artifacts"] | ||
] | ||
) | ||
.loc[lambda df: df.name == "coverage"] | ||
.reindex(["head_branch", "updated_at", "archive_download_url"], axis=1) | ||
.sort_values(["head_branch", "updated_at"], ascending=False) | ||
.drop_duplicates(["head_branch"]) | ||
) | ||
if base_branch_name not in artifacts.head_branch.tolist(): | ||
logger.info( | ||
f"No artifacts found for base branch '{base_branch_name}'. Found\n{artifacts.head_branch.tolist()}" | ||
) | ||
|
||
for artifact in artifacts.to_dict("records"): | ||
response = requests.get( | ||
artifact["archive_download_url"], | ||
headers={"Authorization": f"Bearer {os.environ['GITHUB_TOKEN']}"}, | ||
) | ||
|
||
z = zipfile.ZipFile(io.BytesIO(response.content)) | ||
z.extractall(coverage_dir / artifact["head_branch"]) | ||
|
||
return artifacts | ||
|
||
|
||
def get_deployments(path: str = "deployments"): | ||
response = requests.get( | ||
"https://api.github.com/repos/sayajin-labs/kakarot/actions/artifacts" | ||
) | ||
artifacts = ( | ||
pd.DataFrame( | ||
[ | ||
{**artifact["workflow_run"], **artifact} | ||
for artifact in response.json()["artifacts"] | ||
] | ||
) | ||
.loc[lambda df: df["head_branch"] == "main"] | ||
.loc[lambda df: df["name"] == "deployments"] | ||
.sort_values(["updated_at"], ascending=False) | ||
.archive_download_url | ||
) | ||
|
||
if artifacts.empty: | ||
raise ValueError(f"No deployment artifacts found for base branch main") | ||
|
||
response = requests.get( | ||
artifacts.tolist()[0], | ||
headers={"Authorization": f"Bearer {os.getenv('GITHUB_TOKEN')}"}, | ||
) | ||
z = zipfile.ZipFile(io.BytesIO(response.content)) | ||
z.extractall(path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.