Skip to content

Commit

Permalink
Merge pull request #1 from dfinity/api
Browse files Browse the repository at this point in the history
feat(devops): Create the cycles depositor args automatically
  • Loading branch information
bitdivine authored Sep 17, 2024
2 parents 89709e5 + 0c23141 commit d8fc01c
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 3 deletions.
9 changes: 6 additions & 3 deletions dfx.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"dfx": "0.20.0",
"dfx": "0.23.0",
"canisters": {
"example_paid_service": {
"candid": "src/example/paid_service/example-paid-service.did",
Expand All @@ -26,9 +26,12 @@
}
},
"cycles_depositor": {
"dependencies": ["cycles_ledger"],
"type": "custom",
"candid": "https://github.com/dfinity/cycles-ledger/releases/download/cycles-ledger-v1.0.1/depositor.did",
"wasm": "https://github.com/dfinity/cycles-ledger/releases/download/cycles-ledger-v1.0.1/depositor.wasm.gz"
"build": "scripts/build.cycles_depositor.sh",
"init_arg_file": "out/cycles_depositor.args.did",
"wasm": "out/cycles_depositor.wasm.gz",
"candid": "out/cycles_depositor.did"
}
},
"defaults": {
Expand Down
37 changes: 37 additions & 0 deletions scripts/build.cycles_depositor.args.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env bash
set -euo pipefail

print_help() {
cat <<-EOF
Creates the cycles_depositor installation arguments.
The file is installed at the location defined for 'cycles_depositor' in 'dfx.json'.
EOF
}

[[ "${1:-}" != "--help" ]] || {
print_help
exit 0
}

DFX_NETWORK="${DFX_NETWORK:-local}"
ARG_FILE="$(jq -r .canisters.cycles_depositor.init_arg_file dfx.json)"

####
# Computes the install args, overwriting any existing args file.

CANISTER_ID_CYCLES_LEDGER="${CANISTER_ID_CYCLES_LEDGER:-$(dfx canister id cycles_ledger --network "$DFX_NETWORK")}"

# .. Creates the init args file
rm -f "$ARG_FILE"
mkdir -p "$(dirname "$ARG_FILE")"
cat <<EOF >"$ARG_FILE"
(record { ledger_id = principal "$CANISTER_ID_CYCLES_LEDGER" })
EOF

####
# Success
cat <<EOF
SUCCESS: The cycles_depositor argument file has been created:
cycles_depositor install args: $(sha256sum "$ARG_FILE")
EOF
59 changes: 59 additions & 0 deletions scripts/build.cycles_depositor.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env bash
set -euo pipefail

print_help() {
cat <<-EOF
Creates the cycles_depositor installation files:
- The Wasm and Candid files are downloaded.
- The installation args are computed based on the target network,
determined by the DFX_NETWORK environment variable.
The files are installed at at the locations defined for 'cycles_depositor' in 'dfx.json'.
EOF
}

[[ "${1:-}" != "--help" ]] || {
print_help
exit 0
}

DFX_NETWORK="${DFX_NETWORK:-local}"

LEDGER_RELEASE="v1.0.1"
CANDID_URL="https://github.com/dfinity/cycles-ledger/releases/download/cycles-ledger-${LEDGER_RELEASE}/depositor.did"
WASM_URL="https://github.com/dfinity/cycles-ledger/releases/download/cycles-ledger-${LEDGER_RELEASE}/depositor.wasm.gz"

CANDID_FILE="$(jq -r .canisters.cycles_depositor.candid dfx.json)"
WASM_FILE="$(jq -r .canisters.cycles_depositor.wasm dfx.json)"
ARG_FILE="$(jq -r .canisters.cycles_depositor.init_arg_file dfx.json)"

####
# Downloads the candid file, if it does not exist already.
if test -e "$CANDID_FILE"; then
echo "Using existing cycles_depositor candid file"
else
mkdir -p "$(dirname "$CANDID_FILE")"
curl -sSL "$CANDID_URL" >"$CANDID_FILE"
fi

####
# Downloads the Wasm file, if it does not exist already.
if test -e "$WASM_FILE"; then
echo "Using existing cycles_depositor Wasm file"
else
mkdir -p "$(dirname "$WASM_FILE")"
curl -sSL "$WASM_URL" >"$WASM_FILE"
fi

####
# Computes the install args, overwriting any existing args file.
scripts/build.cycles_depositor.args.sh

# Success
cat <<EOF
SUCCESS: The cycles_depositor installation files have been created:
cycles_depositor candid: $CANDID_FILE
cycles_depositor Wasm: $WASM_FILE
cycles_depositor install args: $ARG_FILE
EOF

0 comments on commit d8fc01c

Please sign in to comment.