Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(devops): Add cycles ledger and depositor #2375

Merged
merged 3 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions dfx.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,25 @@
}
}
},
"cycles_ledger": {
"type": "custom",
"candid": "https://github.com/dfinity/cycles-ledger/releases/download/cycles-ledger-v1.0.1/cycles-ledger.did",
"wasm": "https://github.com/dfinity/cycles-ledger/releases/download/cycles-ledger-v1.0.1/cycles-ledger.wasm.gz",
"init_arg": "( variant { Init = record { index_id = null; max_blocks_per_request = 9_999 : nat64 }},)",
"remote": {
"id": {
"ic": "um5iw-rqaaa-aaaaq-qaaba-cai"
}
}
},
"cycles_depositor": {
"dependencies": ["cycles_ledger"],
"type": "custom",
"build": "scripts/build.cycles_depositor.sh",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use candid and wasm entries because the arguments need to be dynamic?

"init_arg_file": "out/cycles_depositor.args.did",
"wasm": "out/cycles_depositor.wasm",
"candid": "out/cycles_depositor.did"
},
"pouh_issuer": {
"type": "custom",
"candid": "https://github.com/dfinity/verifiable-credentials-sdk/releases/download/release-2024-07-01/dummy_issuer.did",
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