Skip to content

Commit

Permalink
eth: Update bytecode gen script
Browse files Browse the repository at this point in the history
This diff updates the script which used to only generate the runtime
bytecode to also update contract.go and the bytecode used to initiate
the contract in the testing harness.
  • Loading branch information
martonp committed Oct 28, 2021
1 parent d808492 commit 9df4f78
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 37 deletions.
6 changes: 1 addition & 5 deletions dex/networks/eth/contracts/README.md
Expand Up @@ -2,11 +2,7 @@

Have `solc` and `abigen` installed on your system and run from this directory:

`abigen --sol ETHSwapV{version}.sol --pkg eth --out ../contract.go`

To generate the runtime bytecode, run from this directory:

`./genruntime.sh {version}`
`./updatecontract.sh {version}`

## History

Expand Down
32 changes: 0 additions & 32 deletions dex/networks/eth/contracts/genruntime.sh

This file was deleted.

43 changes: 43 additions & 0 deletions dex/networks/eth/contracts/updatecontract.sh
@@ -0,0 +1,43 @@
#!/usr/bin/env bash
# This script does 3 things:
#
# 1. Updates contract.go to reflect updated solidity code.
# 2. Generates the runtime bytecoode. This is used to compare against the runtime
# bytecode on chain in order to verify that the expected contract is deployed.
# 3. Updates the bytecode in the harness test.

if [ "$#" -ne 1 ]
then
echo "Usage: $0 version" >&2
exit 1
fi

ETH_SWAP_VERSION=$1
SOLIDITY_FILE=ETHSwapV${ETH_SWAP_VERSION}.sol
if [ ! -f ./${SOLIDITY_FILE} ]
then
echo "${SOLIDITY_FILE} does not exist" >&2
exit 1
fi

solc --bin-runtime --optimize ${SOLIDITY_FILE} -o .
BYTECODE=$(<ETHSwap.bin-runtime)

cat > "../BinRuntimeV${ETH_SWAP_VERSION}.go" <<EOF
// Code generated - DO NOT EDIT.
// This file is a generated binding and any manual changes will be lost.
package eth
const ETHSwapRuntimeBin = "${BYTECODE}"
EOF

rm ETHSwap.bin-runtime

abigen --sol ${SOLIDITY_FILE} --pkg eth --out ../contract.go

solc --bin --optimize ${SOLIDITY_FILE} -o .
BYTECODE=$(<ETHSwap.bin)
sed -i.tmp "s/ETH_SWAP_V${ETH_SWAP_VERSION}=.*/ETH_SWAP_V${ETH_SWAP_VERSION}=\"${BYTECODE}\"/" ../../../testing/eth/harness.sh
rm ../../../testing/eth/harness.sh.tmp
rm ETHSwap.bin

0 comments on commit 9df4f78

Please sign in to comment.