Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into gate-api
Browse files Browse the repository at this point in the history
  • Loading branch information
bitdivine committed Aug 5, 2024
2 parents c5708af + d2952dc commit 0dc956c
Show file tree
Hide file tree
Showing 71 changed files with 714 additions and 434 deletions.
1 change: 1 addition & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ module.exports = {
'@typescript-eslint/no-unnecessary-type-assertion': 'error',
'no-delete-var': 'error',
'curly': 'error',
'arrow-body-style': ['warn', 'as-needed'],
},
globals: {
NodeJS: true
Expand Down
25 changes: 1 addition & 24 deletions .github/workflows/backend-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,6 @@ on:

jobs:

format:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
- uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-backend-tests-${{ hashFiles('Cargo.lock', 'rust-toolchain.toml') }}
- name: Install cargo dependency sorter
run: cargo install cargo-sort@1.0.9
- name: Format
run: ./scripts/format.sh
- name: Check formatted
run: |
test -z "$(git status --porcelain)" || {
echo "FIX: Please run ./scripts/format.sh"
git diff
exit 1
}
lint:
runs-on: ubuntu-20.04
steps:
Expand All @@ -64,7 +41,7 @@ jobs:
run: ./scripts/lint.cargo-workspace-dependencies.sh

may-merge:
needs: [ 'format', 'lint', 'workspace-dependencies' ]
needs: [ 'lint', 'workspace-dependencies' ]
runs-on: ubuntu-20.04
steps:
- name: Cleared for merging
Expand Down
43 changes: 43 additions & 0 deletions .github/workflows/formatting-checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Formatting Backend and Scripts

on:
pull_request:
paths:
- # Files formatted by ./scripts/format.cargo.sh
'**/Cargo.toml'
- # Files formatted by ./scripts/format.rust.sh
'**/*.rs'
- # Files formatted by ./scripts/format.sh.sh
# Note: shell scripts not ending in .sh are found with: scripts/format.sh.sh --list | grep -vE 'sh$'
'**/*.sh'
- 'docker/*'
- 'scripts/*'
- # This workflow
'.github/workflows/formatting-checks.yml'
workflow_dispatch:

jobs:

format:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
- name: Install shfmt
run: sudo snap install --classic shfmt
- name: Install binstall
run: |
BINSTALL_VERSION="1.8.0"
curl -L --proto '=https' --tlsv1.2 -sSf "https://github.com/cargo-bins/cargo-binstall/releases/download/v${BINSTALL_VERSION}/cargo-binstall-x86_64-unknown-linux-musl.tgz" | tar -xvzf - cargo-binstall
./cargo-binstall -y --force "cargo-binstall@$BINSTALL_VERSION"
rm cargo-binstall
- name: Install cargo dependency sorter
run: cargo binstall --no-confirm cargo-sort@1.0.9
- name: Format
run: ./scripts/format.sh
- name: Check formatted
run: |
test -z "$(git status --porcelain)" || {
echo "FIX: Please run ./scripts/format.sh"
git diff
exit 1
}
22 changes: 10 additions & 12 deletions docker/bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@

set -euo pipefail

SCRIPTS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
SCRIPTS_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPTS_DIR/.."

function run() {
1>&2 echo "running $@"
rc=0 && "$@" || rc="$?"
if ! [ "$rc" -eq 0 ]
then
1>&2 echo "Bootstrap command failed: $@"
exit "$rc"
fi
echo 1>&2 "running $@"
rc=0 && "$@" || rc="$?"
if ! [ "$rc" -eq 0 ]; then
echo 1>&2 "Bootstrap command failed: $@"
exit "$rc"
fi
}

rust_version=$(cat ./rust-toolchain.toml | sed -n 's/^channel[[:space:]]*=[[:space:]]"\(.*\)"/\1/p')
Expand All @@ -23,10 +22,9 @@ echo "using rust version '$rust_version'"
run curl --fail https://sh.rustup.rs -sSf | run sh -s -- -y --default-toolchain "none" --no-modify-path

echo "looking for ic-wasm 0.3.6"
if [[ ! "$(command -v ic-wasm)" || "$(ic-wasm --version)" != "ic-wasm 0.3.6" ]]
then
echo "installing ic-wasm 0.3.6"
run cargo install ic-wasm --version 0.3.6
if [[ ! "$(command -v ic-wasm)" || "$(ic-wasm --version)" != "ic-wasm 0.3.6" ]]; then
echo "installing ic-wasm 0.3.6"
run cargo install ic-wasm --version 0.3.6
fi

# make sure the packages are actually installed (rustup waits for the first invoke to lazyload)
Expand Down
156 changes: 76 additions & 80 deletions docker/build
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
set -euo pipefail

# Make sure we always run from the root
SCRIPTS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
SCRIPTS_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPTS_DIR/.."

#########
# USAGE #
#########

function title() {
echo "Build Oisy Canister"
echo "Build Oisy Canister"
}

function usage() {
cat << EOF
cat <<EOF
Usage:
$0 [--only-dependencies] [--backend]
Expand All @@ -27,7 +27,7 @@ EOF
}

function help() {
cat << EOF
cat <<EOF
Build the Backend canister.
Expand All @@ -39,94 +39,90 @@ EOF
ONLY_DEPS=
CANISTERS=()

while [[ $# -gt 0 ]]
do
case "$1" in
-h|--help)
title
usage
help
exit 0
;;
--only-dependencies)
ONLY_DEPS=1
shift
;;
--backend)
CANISTERS+=("backend")
shift
;;
*)
echo "ERROR: unknown argument $1"
usage
echo
echo "Use 'build --help' for more information"
exit 1
;;
esac
while [[ $# -gt 0 ]]; do
case "$1" in
-h | --help)
title
usage
help
exit 0
;;
--only-dependencies)
ONLY_DEPS=1
shift
;;
--backend)
CANISTERS+=("backend")
shift
;;
*)
echo "ERROR: unknown argument $1"
usage
echo
echo "Use 'build --help' for more information"
exit 1
;;
esac
done

# build Backend by default
if [ ${#CANISTERS[@]} -eq 0 ]; then
CANISTERS=("backend")
CANISTERS=("backend")
fi

# Checking for dependencies
if [[ ! "$(command -v ic-wasm)" || "$(ic-wasm --version)" != "ic-wasm 0.3.6" ]]
then
echo "could not find ic-wasm 0.3.6"
echo "ic-wasm version 0.3.6 is needed, please run the following command:"
echo " cargo install ic-wasm --version 0.3.6"
exit 1
if [[ ! "$(command -v ic-wasm)" || "$(ic-wasm --version)" != "ic-wasm 0.3.6" ]]; then
echo "could not find ic-wasm 0.3.6"
echo "ic-wasm version 0.3.6 is needed, please run the following command:"
echo " cargo install ic-wasm --version 0.3.6"
exit 1
fi

# Builds a single canister
function build_canister() {
local canister=$1
shift
local extra_build_args=("$@")

echo "Building $canister"
echo

SRC_DIR="$PWD/src/$canister"
TARGET="wasm32-unknown-unknown"
# standardize source references
CARGO_HOME="${CARGO_HOME:-"$HOME/.cargo"}"
RUSTFLAGS="--remap-path-prefix $CARGO_HOME=/cargo -C link-args=-zstack-size=3000000"

cargo_build_args=(
--manifest-path "$SRC_DIR/Cargo.toml"
--target "$TARGET"
--release
-j1
)
# XXX: for bash > 4.4, empty arrays are considered unset, so do some substitution
cargo_build_args+=(${extra_build_args[@]+"${extra_build_args[@]}"})

echo Running cargo build "${cargo_build_args[@]}"
echo RUSTFLAGS: "$RUSTFLAGS"

RUSTFLAGS="$RUSTFLAGS" cargo build "${cargo_build_args[@]}"

if [ "$ONLY_DEPS" != "1" ]
then
CARGO_TARGET_DIR="${CARGO_TARGET_DIR:-$SRC_DIR/../../target/}"

# Optimize WASM and set metadata
ic-wasm \
"$CARGO_TARGET_DIR/$TARGET/release/$canister.wasm" \
-o "./$canister.wasm" \
shrink

# adds the content of $canister.did to the `icp:public candid:service` custom section of the public metadata in the wasm
ic-wasm "$canister.wasm" -o "$canister.wasm" metadata candid:service -f "$SRC_DIR/$canister.did" -v public

gzip "./$canister.wasm"
fi
local canister=$1
shift
local extra_build_args=("$@")

echo "Building $canister"
echo

SRC_DIR="$PWD/src/$canister"
TARGET="wasm32-unknown-unknown"
# standardize source references
CARGO_HOME="${CARGO_HOME:-"$HOME/.cargo"}"
RUSTFLAGS="--remap-path-prefix $CARGO_HOME=/cargo -C link-args=-zstack-size=3000000"

cargo_build_args=(
--manifest-path "$SRC_DIR/Cargo.toml"
--target "$TARGET"
--release
-j1
)
# XXX: for bash > 4.4, empty arrays are considered unset, so do some substitution
cargo_build_args+=(${extra_build_args[@]+"${extra_build_args[@]}"})

echo Running cargo build "${cargo_build_args[@]}"
echo RUSTFLAGS: "$RUSTFLAGS"

RUSTFLAGS="$RUSTFLAGS" cargo build "${cargo_build_args[@]}"

if [ "$ONLY_DEPS" != "1" ]; then
CARGO_TARGET_DIR="${CARGO_TARGET_DIR:-$SRC_DIR/../../target/}"

# Optimize WASM and set metadata
ic-wasm \
"$CARGO_TARGET_DIR/$TARGET/release/$canister.wasm" \
-o "./$canister.wasm" \
shrink

# adds the content of $canister.did to the `icp:public candid:service` custom section of the public metadata in the wasm
ic-wasm "$canister.wasm" -o "$canister.wasm" metadata candid:service -f "$SRC_DIR/$canister.did" -v public

gzip "./$canister.wasm"
fi
}

for canister in "${CANISTERS[@]}"
do
for canister in "${CANISTERS[@]}"; do
build_canister "$canister"
done
2 changes: 1 addition & 1 deletion docker/deploy
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ dfx start --background --quiet

npm run deploy

dfx stop
dfx stop
16 changes: 8 additions & 8 deletions docker/wait-port
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

#source https://stackoverflow.com/a/70181222/5404186

for _ in `seq 1 20`; do
echo -n .
if nc -z localhost $1; then
echo "✅ Connection to port $1 succeeded."
exit 0
fi
sleep 0.5
for _ in $(seq 1 20); do
echo -n .
if nc -z localhost $1; then
echo "✅ Connection to port $1 succeeded."
exit 0
fi
sleep 0.5
done

echo "❌ Connection to port $1 failed!"

exit 1
exit 1
10 changes: 4 additions & 6 deletions scripts/add.tokens.erc20.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -295,22 +295,20 @@ const updateTokensErc20Env = ({ fileName, mainnetToken, testnetToken }) => {
writeFileSync(filePath, content);
};

const flattenData = (data) => {
return Object.keys(data).map((symbol) => ({
const flattenData = (data) =>
Object.keys(data).map((symbol) => ({
symbol,
...data[symbol]
}));
};

const flattenEnvironmentData = (data) => {
return Object.entries(data).reduce(
const flattenEnvironmentData = (data) =>
Object.entries(data).reduce(
(acc, [environment, values]) => ({
...acc,
[environment]: flattenData(values)
}),
{}
);
};

const readSupportedTokens = () => {
const jsonPath = resolve(DATA_DIR_PATH, 'tokens.ckerc20.json');
Expand Down
2 changes: 1 addition & 1 deletion scripts/build.compress.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env bash

find build/ -type f | xargs -I{} gzip -fnk "{}"
find build/ -type f | xargs -I{} gzip -fnk "{}"
Loading

0 comments on commit 0dc956c

Please sign in to comment.