-
Notifications
You must be signed in to change notification settings - Fork 278
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
312 changed files
with
57,680 additions
and
24,257 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Put all output in build directory. | ||
build --symlink_prefix=build/bazel | ||
|
||
# Don't inherit the user environment as that trashes the cache. | ||
build --incompatible_strict_action_env | ||
build --profile=bazel_build.profile | ||
|
||
# Prevent Bazel from adding empty __init__.py files. Those files prevent the packages from becoming | ||
# a namespace package and can cause an import collision. | ||
build --incompatible_default_to_explicit_init_py | ||
|
||
build --test_output=errors |
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
Empty file.
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,79 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import json | ||
import os | ||
import subprocess | ||
from argparse import ArgumentParser | ||
|
||
BAD_BRANCH_IDENTIFIER = "BADB51" | ||
|
||
|
||
def main(): | ||
parser = ArgumentParser() | ||
parser.add_argument( | ||
"--input_json", | ||
type=str, | ||
help="The path to the combined.json file.", | ||
required=True, | ||
) | ||
parser.add_argument( | ||
"--artifacts_dir", | ||
type=str, | ||
help="The directory of the resulted compiled contracts.", | ||
required=True, | ||
) | ||
parser.add_argument("--source_dir", type=str, required=True) | ||
parser.add_argument("--contracts", type=str, nargs="*", help="Contracts list.", required=True) | ||
args = parser.parse_args() | ||
|
||
with open(os.path.join(args.input_json)) as fp: | ||
combined_json = json.load(fp) | ||
|
||
git_commit = BAD_BRANCH_IDENTIFIER | ||
try: | ||
git_commit = ( | ||
subprocess.check_output("git rev-parse HEAD".split(), stderr=subprocess.DEVNULL) | ||
.decode("ascii") | ||
.strip()[:6] | ||
) | ||
except Exception: | ||
pass | ||
|
||
for path_and_name, val in combined_json["contracts"].items(): | ||
path, contract_name = path_and_name.split(":") | ||
compiled_path = os.path.relpath( | ||
os.path.join(os.path.dirname(path), f"{contract_name}.json"), start=args.source_dir | ||
) | ||
if compiled_path not in args.contracts: | ||
continue | ||
|
||
# 1. We cannot put "0x" in case of empty bin, as this would not prevent | ||
# loading an empty (virtual) contract. (We want it to fail) | ||
# 2. Note that we can't put an assert len(val['bin']) > 0 here, because some contracts | ||
# are pure virtual and others lack external and public functions. | ||
bytecode = None | ||
if len(val["bin"]) > 0: | ||
bytecode = "0x" + val["bin"] | ||
|
||
# Support both solc-0.6 & solc-0.8 output format. | ||
# In solc-0.6 the abi is a list in a json string, | ||
# whereas in 0.8 it's a plain json. | ||
try: | ||
abi = json.loads(val["abi"]) | ||
except TypeError: | ||
abi = val["abi"] | ||
|
||
artifact = { | ||
"contractName": contract_name, | ||
"abi": abi, | ||
"bytecode": bytecode, | ||
"build_tag": git_commit, | ||
} | ||
|
||
destination_filename = os.path.join(args.artifacts_dir, compiled_path) | ||
with open(destination_filename, "w") as fp: | ||
json.dump(artifact, fp, indent=4) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
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,33 @@ | ||
#!/usr/bin/env python3 | ||
|
||
""" | ||
A helper script for python.bzl. | ||
Generates an executable file that runs a python module. | ||
""" | ||
|
||
from argparse import ArgumentParser | ||
|
||
|
||
def main(): | ||
parser = ArgumentParser(description="Generates an executable file for py_exe().") | ||
parser.add_argument("--name", help="The name of the target", required=True) | ||
parser.add_argument("--module", help="The name of the module to run", required=True) | ||
args = parser.parse_args() | ||
|
||
print( | ||
f"""\ | ||
import os | ||
import subprocess | ||
import sys | ||
cmd = [ | ||
sys.executable, "-u", "-m", {args.module!r} | ||
] + sys.argv[1:] | ||
proc = subprocess.run(cmd) | ||
sys.exit(proc.returncode) | ||
""" | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
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,6 @@ | ||
import sys | ||
|
||
import pytest | ||
|
||
if __name__ == "__main__": | ||
sys.exit(pytest.main(sys.argv[1:])) |
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,31 @@ | ||
#!/bin/bash | ||
|
||
# This script runs either python or pypy depending on the name of the module that is being run. | ||
# This script is needed because Bazel only supports one python interpreter. | ||
|
||
# --- begin runfiles.bash initialization v2 --- | ||
# Copy-pasted from the Bazel Bash runfiles library v2. | ||
set -uo pipefail; f=bazel_tools/tools/bash/runfiles/runfiles.bash | ||
source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \ | ||
source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \ | ||
source "$0.runfiles/$f" 2>/dev/null || \ | ||
source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ | ||
source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ | ||
{ echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e | ||
# --- end runfiles.bash initialization v2 --- | ||
|
||
set +e | ||
|
||
python_interpreter="$(rlocation "python3_x86_64-unknown-linux-gnu/bin/python3")" | ||
if [[ -x "$(rlocation "pypy3.9/bin/pypy3.9")" ]]; then | ||
if [[ $1 == *_uses_pypy_.py ]]; then | ||
python_interpreter="$(rlocation "pypy3.9/bin/pypy3.9")" | ||
fi | ||
fi | ||
|
||
if [[ ! -x "$python_interpreter" ]]; then | ||
echo "Could not find interpreter $python_interpreter" >&2 | ||
exit 1 | ||
fi | ||
|
||
exec "$python_interpreter" "$@" |
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,83 @@ | ||
import os | ||
import shutil | ||
import subprocess | ||
import sys | ||
import tempfile | ||
from argparse import ArgumentParser | ||
|
||
|
||
def main(): | ||
parser = ArgumentParser() | ||
|
||
parser.add_argument( | ||
"--solc", | ||
type=str, | ||
help="Solidity compiler path.", | ||
required=True, | ||
) | ||
parser.add_argument( | ||
"--optimize_runs", | ||
type=str, | ||
help=( | ||
"Set for how many contract runs to optimize. Lower values will optimize more for " | ||
"initial deployment cost, higher values will optimize more for high-frequency usage." | ||
), | ||
required=True, | ||
) | ||
parser.add_argument( | ||
"--base_path", | ||
type=str, | ||
help=( | ||
"Use the given path as the root of the source tree instead of the root of the " | ||
"filesystem." | ||
), | ||
required=True, | ||
) | ||
parser.add_argument( | ||
"--output", | ||
type=str, | ||
help="Output path for combined.json.", | ||
required=True, | ||
) | ||
parser.add_argument( | ||
"--srcs", | ||
type=str, | ||
help="Paths of the solidity source files.", | ||
required=True, | ||
nargs="+", | ||
) | ||
args = parser.parse_args() | ||
|
||
files_to_compile = [] | ||
|
||
with tempfile.TemporaryDirectory() as tmp_dir: | ||
for src in args.srcs: | ||
if src.startswith("external/cairo-lang"): | ||
dest_path = src.replace("external/cairo-lang/", "") | ||
else: | ||
dest_path = src | ||
files_to_compile.append(dest_path) | ||
os.makedirs(os.path.dirname(tmp_dir + "/" + dest_path), exist_ok=True) | ||
shutil.copyfile(src, tmp_dir + "/" + dest_path) | ||
|
||
subprocess.check_call( | ||
[ | ||
os.path.join(os.getcwd(), args.solc), | ||
"--optimize", | ||
"--optimize-runs", | ||
args.optimize_runs, | ||
"--combined-json", | ||
"abi,bin", | ||
"--base-path", | ||
args.base_path, | ||
"-o", | ||
os.path.join(os.getcwd(), args.output), | ||
] | ||
+ files_to_compile, | ||
cwd=tmp_dir, | ||
stdout=subprocess.DEVNULL, | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
sys.exit(main()) |
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,12 @@ | ||
# Install Clang | ||
apt-get update | ||
apt-get install -y libstdc++-8-dev libc6-dbg | ||
apt-get install -y clang-12 clang-format-12 clang-tidy-6.0 libclang-12-dev llvm-12 g++-7 | ||
ln -sf /usr/bin/clang++-12 /usr/bin/clang++ | ||
ln -sf /usr/bin/clang-12 /usr/bin/clang | ||
|
||
# Install bazel | ||
apt-get install unzip -y | ||
curl -L -o /tmp/bazel_install.sh https://github.com/bazelbuild/bazel/releases/download/5.2.0/bazel-5.2.0-installer-linux-x86_64.sh | ||
chmod +x /tmp/bazel_install.sh | ||
/tmp/bazel_install.sh |
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,12 @@ | ||
{ | ||
"name": "workspace", | ||
"version": "1.0.0", | ||
"private": true, | ||
"description": "", | ||
"dependencies": { | ||
"ganache": "7.4.4" | ||
}, | ||
"devDependencies": {}, | ||
"author": "", | ||
"license": "ISC" | ||
} |
Empty file.
Empty file.
Empty file.
Oops, something went wrong.