Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: generate the wrappers from .abi and .bin #139

Merged
merged 6 commits into from
Mar 27, 2023
Merged
Show file tree
Hide file tree
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
10 changes: 3 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ gen: solidity-wrappers

SOLIDITY_DIR = .
SOLIDITY_SRC_DIR = $(SOLIDITY_DIR)/src
solidity-wrappers: $(SOLIDITY_SRC_DIR)/QuantumGravityBridge.sol
cd $(SOLIDITY_SRC_DIR) ; \
for file in $(^F) ; do \
mkdir -p ../wrappers/$${file} ; \
echo abigen --type=peggy --pkg wrappers --out=../wrappers/$${file}/wrapper.go --sol $${file} ; \
abigen --type=peggy --pkg wrappers --out=../wrappers/$${file}/wrapper.go --sol $${file} ; \
done
CONTRACTS = QuantumGravityBridge.sol
solidity-wrappers:
./scripts/gen.sh $(SOLIDITY_SRC_DIR) $(CONTRACTS)
30 changes: 30 additions & 0 deletions scripts/gen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash
adlerjohn marked this conversation as resolved.
Show resolved Hide resolved

set -e

if (( $# < 2 )); then
echo "Go wrappers generator script. Make sure to specify the following params:"
echo " - first parameter: the contracts source directory"
echo " - second parameter: the contracts names (including the .sol extension) separated by a space"
echo "the output files will be in the ./wrappers directory."
exit 1
fi

forge build > /dev/null

cd "$1"

for file in "${@: 2}"; do
mkdir -p ../wrappers/"${file}"
contractName=$(basename "${file}" .sol)

jq .abi < ../out/"${file}"/"${contractName}".json > ../out/"${file}"/"${contractName}".abi
jq -r .bytecode.object < ../out/"${file}"/"${contractName}".json > ../out/"${file}"/"${contractName}".bin

abigen --pkg wrappers \
--out=../wrappers/"${file}"/wrapper.go \
--abi ../out/"${file}"/"${contractName}".abi \
--bin ../out/"${file}"/"${contractName}".bin
done

echo "done."
Loading