decred.org/dcrdex@v1.0.5/dex/networks/eth/contracts/updatecontract.sh (about)

     1  #!/usr/bin/env bash
     2  # This script does 3 things:
     3  #
     4  # 1. Updates contract.go to reflect updated solidity code.
     5  # 2. Generates the runtime bytecoode. This is used to compare against the runtime
     6  #    bytecode on chain in order to verify that the expected contract is deployed.
     7  # 3. Updates the bytecode in the harness test.
     8  
     9  if [ "$#" -ne 1 ]
    10  then
    11    echo "Usage: $0 version" >&2
    12    exit 1
    13  fi
    14  
    15  VERSION=$1
    16  PKG_NAME=v${VERSION}
    17  CONTRACT_NAME=ETHSwap
    18  SOLIDITY_FILE=./${CONTRACT_NAME}V${VERSION}.sol
    19  if [ ! -f ${SOLIDITY_FILE} ]
    20  then
    21      echo "${SOLIDITY_FILE} does not exist" >&2
    22      exit 1
    23  fi
    24  
    25  mkdir temp
    26  
    27  solc --abi --bin --bin-runtime --overwrite --optimize ${SOLIDITY_FILE} -o ./temp/
    28  BYTECODE=$(<./temp/${CONTRACT_NAME}.bin-runtime)
    29  
    30  cat > "./${PKG_NAME}/BinRuntimeV${VERSION}.go" <<EOF
    31  // Code generated - DO NOT EDIT.
    32  // This file is a generated binding and any manual changes will be lost.
    33  
    34  package ${PKG_NAME}
    35  
    36  const ${CONTRACT_NAME}RuntimeBin = "${BYTECODE}"
    37  EOF
    38  
    39  abigen --abi ./temp/${CONTRACT_NAME}.abi --bin ./temp/${CONTRACT_NAME}.bin --pkg ${PKG_NAME} \
    40   --type ${CONTRACT_NAME} --out ./${PKG_NAME}/contract.go
    41  
    42  BYTECODE=$(<./temp/${CONTRACT_NAME}.bin)
    43  
    44  for HARNESS_PATH in "$(realpath ../../../testing/eth/harness.sh)" "$(realpath ../../../testing/polygon/harness.sh)"; do
    45    sed -i.tmp "s/ETH_SWAP_V${VERSION}=.*/ETH_SWAP_V${VERSION}=\"${BYTECODE}\"/" "${HARNESS_PATH}"
    46    # mac needs a temp file specified above.
    47    rm "${HARNESS_PATH}.tmp"
    48  done
    49  
    50  rm -fr temp