-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from ava-labs/abi-go-binding
Create TeleporterMessenger ABI Go binding
- Loading branch information
Showing
10 changed files
with
5,705 additions
and
0 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,39 @@ | ||
name: ABI Go Bindings Checker | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- "*" | ||
|
||
env: | ||
GO_VERSION: "1.20.8" | ||
|
||
jobs: | ||
abi_binding: | ||
name: abi_binding | ||
runs-on: ubuntu-20.04 | ||
|
||
steps: | ||
- name: Setup Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: ${{ env.GO_VERSION }} | ||
|
||
- name: Checkout Teleporter repository | ||
uses: actions/checkout@v4 | ||
with: | ||
submodules: recursive | ||
|
||
- name: Install forge and generate ABI Go bindings | ||
run: | | ||
BASE_DIR=${XDG_CONFIG_HOME:-$HOME} | ||
curl -L https://foundry.paradigm.xyz | bash | ||
source $HOME/.bashrc | ||
$BASE_DIR/.foundry/bin/foundryup | ||
export GOPATH=$HOME/go | ||
export PATH="$PATH:$BASE_DIR/.foundry/bin" | ||
export PATH="$PATH:$GOPATH/bin" | ||
./scripts/abi_go_bindings.sh | ||
- name: Check for clean branch | ||
run: .github/workflows/check_clean_branch.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 @@ | ||
#!/bin/bash | ||
# Exits if any uncommitted changes are found. | ||
|
||
set -o errexit | ||
set -o nounset | ||
set -o pipefail | ||
|
||
# Modifies the index based on the current index. | ||
# Checks to see if merges or updates are needed by checking stat() information. | ||
git update-index --really-refresh > /dev/null | ||
# Checks to see if there are any differences from the index to the current HEAD commit | ||
git diff-index --quiet HEAD |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
610 changes: 610 additions & 0 deletions
610
abis/ExampleCrossChainMessenger/ExampleCrossChainMessenger.go
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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,77 @@ | ||
#!/usr/bin/env bash | ||
# Copyright (C) 2023, Ava Labs, Inc. All rights reserved. | ||
# See the file LICENSE for licensing terms. | ||
|
||
set -e | ||
|
||
source ./scripts/utils.sh | ||
|
||
setARCH | ||
|
||
TELEPORTER_PATH=$( | ||
cd "$(dirname "${BASH_SOURCE[0]}")" | ||
cd .. && pwd | ||
) | ||
|
||
DEFAULT_CONTRACT_LIST="TeleporterMessenger ERC20Bridge ExampleCrossChainMessenger BlockHashPublisher BlockHashReceiver BridgeToken" | ||
|
||
CONTRACT_LIST= | ||
HELP= | ||
while [ $# -gt 0 ]; do | ||
case "$1" in | ||
-c | --contract) CONTRACT_LIST=$2 ;; | ||
-h | --help) HELP=true ;; | ||
esac | ||
shift | ||
done | ||
|
||
if [ "$HELP" = true ]; then | ||
echo "Usage: ./scripts/abi_go_bindings.sh [OPTIONS]" | ||
echo "Build contracts and generate Go bindings" | ||
echo "" | ||
echo "Options:" | ||
echo " -c, --contract <contract_name> Generate Go bindings for the contract. If empty, generate Go bindings for a default list of contracts" | ||
echo " -c, --contract "contract1 contract2" Generate Go bindings for multiple contracts" | ||
echo " -h, --help Print this help message" | ||
exit 0 | ||
fi | ||
|
||
if ! command -v forge &> /dev/null; then | ||
echo "forge not found, installing" | ||
curl -L https://foundry.paradigm.xyz | bash | ||
source $HOME/.bashrc | ||
foundryup | ||
fi | ||
|
||
echo "Building subnet-evm abigen" | ||
go install $TELEPORTER_PATH/subnet-evm/cmd/abigen | ||
|
||
echo "Building Contracts" | ||
cd $TELEPORTER_PATH/contracts | ||
forge build --extra-output-files abi | ||
|
||
contract_names=($CONTRACT_LIST) | ||
|
||
# If CONTRACT_LIST is empty, use DEFAULT_CONTRACT_LIST | ||
if [[ -z "${CONTRACT_LIST}" ]]; then | ||
contract_names=($DEFAULT_CONTRACT_LIST) | ||
fi | ||
|
||
cd $TELEPORTER_PATH | ||
for contract_name in "${contract_names[@]}" | ||
do | ||
abi_file=$TELEPORTER_PATH/contracts/out/$contract_name.sol/$contract_name.abi.json | ||
if ! [ -f $abi_file ]; then | ||
echo "Error: Contract $contract_name abi file not found" | ||
exit 1 | ||
fi | ||
|
||
echo "Generating Go bindings for $contract_name..." | ||
mkdir -p $TELEPORTER_PATH/abis/$contract_name | ||
$GOPATH/bin/abigen --abi $abi_file \ | ||
--pkg $(convertToLower $contract_name) \ | ||
--out $TELEPORTER_PATH/abis/$contract_name/$contract_name.go | ||
echo "Done generating Go bindings for $contract_name." | ||
done | ||
|
||
exit 0 |
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