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

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