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

Cycles #3482

Draft
wants to merge 20 commits into
base: main
Choose a base branch
from
22 changes: 22 additions & 0 deletions scripts/bind.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash

[[ "${1:-}" != "--help" ]] || {
cat <<-EOF
Generates candid files and bindings.

Prerequisites:
- Deploy all canisters to the 'local' network. Or otherwise ensure that:
- Wasm for each canister is at: '.dfx/local/canisters/$CANISTER/$CANISTER.wasm.gz'
Note: You may need to set '"gzip": true' for canisters in 'dfx.json'.
- Candid for each canister is at: '.dfx/local/canisters/$CANISTER/$CANISTER.did'
EOF

exit 0
}

# Generate candid for the backend
scripts/did.sh # TODO: Use local Wasm as input.
# Generate rust bindings
scripts/bind/rust.sh
# Format
scripts/format.sh
31 changes: 31 additions & 0 deletions scripts/bind/rust.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash
set -euo pipefail

[[ "${1:-}" != "--help" ]] || {
cat <<-EOF
Generates rust canister bindings.

Usage:
$(basename $0) [canister_name..]
EOF

exit 0
}

# If no canisters are specified, generate bindings for all.
if (($# == 0)); then
mapfile -t canisters < <(jq -r '.canisters|keys|.[]' dfx.json)
else
canisters=("${@}")
fi

for canister in "${canisters[@]}"; do
canister_binding_config="./scripts/bind/rust/${canister}.toml"
if test -f "$canister_binding_config"; then
echo "INFO: Creating rust bindings for $canister..."
mkdir -p "src/backend/src/bind"
didc bind -t rs ".dfx/local/canisters/$canister/$canister.did" --config "$canister_binding_config" >"src/backend/src/bind/$canister.rs"
else
echo "INFO: No rust binding script for $canister at $canister_binding_config"
fi
done
3 changes: 3 additions & 0 deletions scripts/bind/rust/cycles_ledger.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[rust]
visibility = "pub(crate)"
attributes = "#[derive(CandidType, Deserialize, Debug, Eq, PartialEq, Clone)]"
3 changes: 3 additions & 0 deletions src/backend/src/bind.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//! Bindings to call other canisters.

pub mod cycles_ledger;
Loading
Loading