From 0c231413961fa2c10455a2167f2473ed8cabe509 Mon Sep 17 00:00:00 2001 From: Max Murphy Date: Tue, 17 Sep 2024 15:04:50 +0200 Subject: [PATCH] Create the cycles depositor args automatically --- dfx.json | 9 ++-- scripts/build.cycles_depositor.args.sh | 37 ++++++++++++++++ scripts/build.cycles_depositor.sh | 59 ++++++++++++++++++++++++++ 3 files changed, 102 insertions(+), 3 deletions(-) create mode 100755 scripts/build.cycles_depositor.args.sh create mode 100755 scripts/build.cycles_depositor.sh diff --git a/dfx.json b/dfx.json index 491642b..90b87c8 100644 --- a/dfx.json +++ b/dfx.json @@ -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", @@ -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": { diff --git a/scripts/build.cycles_depositor.args.sh b/scripts/build.cycles_depositor.args.sh new file mode 100755 index 0000000..c5a8882 --- /dev/null +++ b/scripts/build.cycles_depositor.args.sh @@ -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 <"$ARG_FILE" +(record { ledger_id = principal "$CANISTER_ID_CYCLES_LEDGER" }) +EOF + +#### +# Success +cat <"$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 <