Skip to content

Commit

Permalink
Merge pull request #50 from ava-labs/abi-bindings
Browse files Browse the repository at this point in the history
Refactor abi binding files
  • Loading branch information
gwen917 authored Oct 5, 2023
2 parents 8b87d70 + c8e2118 commit a392920
Show file tree
Hide file tree
Showing 9 changed files with 1,146 additions and 1,143 deletions.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions scripts/abi_go_bindings.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,23 @@ if [[ -z "${CONTRACT_LIST}" ]]; then
contract_names=($DEFAULT_CONTRACT_LIST)
fi

cd $TELEPORTER_PATH
cd $TELEPORTER_PATH/contracts/src
for contract_name in "${contract_names[@]}"
do
path=$(find . -name $contract_name.sol)
dir=$(dirname $path)
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
mkdir -p $TELEPORTER_PATH/abi-bindings/$dir/$contract_name
$GOPATH/bin/abigen --abi $abi_file \
--pkg $(convertToLower $contract_name) \
--out $TELEPORTER_PATH/abis/$contract_name/$contract_name.go
--type $contract_name \
--out $TELEPORTER_PATH/abi-bindings/$dir/$contract_name/$contract_name.go
echo "Done generating Go bindings for $contract_name."
done

Expand Down
4 changes: 2 additions & 2 deletions tests/basic_one_way_send.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/ava-labs/awm-relayer/messages/teleporter"
"github.com/ava-labs/subnet-evm/interfaces"
teleportermessenger "github.com/ava-labs/teleporter/abis/TeleporterMessenger"
teleportermessenger "github.com/ava-labs/teleporter/abi-bindings/Teleporter/TeleporterMessenger"
"github.com/ava-labs/teleporter/tests/utils"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log"
Expand Down Expand Up @@ -49,7 +49,7 @@ func BasicOneWaySend() {
log.Info("Sending Teleporter transaction on source chain", "destinationChainID", subnetBInfo.BlockchainID, "txHash", signedTx.Hash())
receipt := utils.SendTransactionAndWaitForAcceptance(ctx, subnetAInfo.ChainWSClient, signedTx)

bind, err := teleportermessenger.NewTeleportermessenger(teleporterContractAddress, subnetAInfo.ChainWSClient)
bind, err := teleportermessenger.NewTeleporterMessenger(teleporterContractAddress, subnetAInfo.ChainWSClient)
Expect(err).Should(BeNil())
event, err := utils.GetSendEventFromLogs(receipt.Logs, bind)
Expect(err).Should(BeNil())
Expand Down
8 changes: 4 additions & 4 deletions tests/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/ava-labs/avalanchego/ids"
avalancheWarp "github.com/ava-labs/avalanchego/vms/platformvm/warp"
warpBackend "github.com/ava-labs/subnet-evm/warp"
teleportermessenger "github.com/ava-labs/teleporter/abis/TeleporterMessenger"
teleportermessenger "github.com/ava-labs/teleporter/abi-bindings/Teleporter/TeleporterMessenger"

"github.com/ava-labs/awm-relayer/messages/teleporter"
"github.com/ava-labs/subnet-evm/core/types"
Expand Down Expand Up @@ -305,7 +305,7 @@ func RelayMessage(
log.Info("Sending transaction to destination chain")
receipt := SendTransactionAndWaitForAcceptance(ctx, destination.ChainWSClient, signedTx)

bind, err := teleportermessenger.NewTeleportermessenger(teleporterContractAddress, source.ChainWSClient)
bind, err := teleportermessenger.NewTeleporterMessenger(teleporterContractAddress, source.ChainWSClient)
Expect(err).Should(BeNil())
// Check the transaction logs for the ReceiveCrossChainMessage event emitted by the Teleporter contract
event, err := GetReceiveEventFromLogs(receipt.Logs, bind)
Expand All @@ -314,7 +314,7 @@ func RelayMessage(
return nil
}

func GetReceiveEventFromLogs(logs []*types.Log, bind *teleportermessenger.Teleportermessenger) (*teleportermessenger.TeleportermessengerReceiveCrossChainMessage, error) {
func GetReceiveEventFromLogs(logs []*types.Log, bind *teleportermessenger.TeleporterMessenger) (*teleportermessenger.TeleporterMessengerReceiveCrossChainMessage, error) {
for _, log := range logs {
event, err := bind.ParseReceiveCrossChainMessage(*log)
if err == nil {
Expand All @@ -325,7 +325,7 @@ func GetReceiveEventFromLogs(logs []*types.Log, bind *teleportermessenger.Telepo
return nil, fmt.Errorf("failed to find ReceiveCrossChainMessage event in receipt logs")
}

func GetSendEventFromLogs(logs []*types.Log, bind *teleportermessenger.Teleportermessenger) (*teleportermessenger.TeleportermessengerSendCrossChainMessage, error) {
func GetSendEventFromLogs(logs []*types.Log, bind *teleportermessenger.TeleporterMessenger) (*teleportermessenger.TeleporterMessengerSendCrossChainMessage, error) {
for _, log := range logs {
event, err := bind.ParseSendCrossChainMessage(*log)
if err == nil {
Expand Down

0 comments on commit a392920

Please sign in to comment.