-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathimport-candid
executable file
·120 lines (101 loc) · 3.99 KB
/
import-candid
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/usr/bin/env bash
set -ueo pipefail
help_text() {
cat <<-EOF
Imports did files for NNS canisters from the IC repo.
Usage:
$(basename "$0") <ic_repo_dir>
EOF
}
import_did() {
local in_path="$1"
local out_filename="${2:-$(basename "$1")}"
local pkg="$3"
local in_fullpath="$IC_DIR/$in_path"
local out_path="packages/${pkg}/candid/${out_filename}"
echo "Copying ${in_fullpath} -> REPO_ROOT/${out_path}"
{
echo "// Generated from IC repo commit ${IC_COMMIT} (${IC_DATE}${IC_TAGS:+ tags: ${IC_TAGS% }}) '${in_path}' by $(basename "${0}")"
cat "$in_fullpath"
} >"${out_path}"
}
download_did() {
local raw_url="$1"
local out_filename="$2"
local pkg="$3"
local out_path="packages/${pkg}/candid/${out_filename}"
# Extract repository, branch, and file path from the raw URL
local repo=$(echo "$raw_url" | awk -F '/' '{print $4"/"$5}')
local branch=$(echo "$raw_url" | awk -F '/' '{print $6}')
local file_path=$(echo "$raw_url" | awk -F "$branch/" '{print $2}')
# Get the latest commit hash for the specified file
local api_url="https://api.github.com/repos/${repo}/commits?path=${file_path}&sha=${branch}"
local commit_hash=$(curl -s "$api_url" | jq -r '.[0].sha')
if [ -z "$commit_hash" ]; then
echo "Failed to retrieve commit hash for ${file_path} in ${repo}."
return 1
fi
echo "Downloading ${raw_url} -> REPO_ROOT/${out_path}"
{
echo "// Generated from ${repo} commit ${commit_hash} for file '${file_path}'"
curl -s "$raw_url"
} >"${out_path}"
}
: Move to root of the repo
cd "$(dirname "$(realpath "$0")")/.."
: Get args
while (($# > 0)); do
arg="${1:-}"
shift 1
case "$arg" in
--help)
help_text
exit 0
;;
*)
test -d "${arg:-}" || {
echo "ERROR: Invalid directory for IC repo dir: '${arg:-}'"
echo " Use --help for usage."
exit 1
} >&2
IC_DIR="$(realpath "$arg")"
;;
esac
done
test -n "${IC_DIR:-}" || {
echo "ERROR: ic_repo_dir command line argument not provided."
echo " Use --help for usage."
exit 1
} >&2
IC_COMMIT="$(cd "${IC_DIR}" && git rev-parse --short HEAD)"
IC_DATE="$(cd "${IC_DIR}" && git show -s --format=%as)"
IC_TAGS="$(cd "${IC_DIR}" && git tag --points-at HEAD | tr "\n" " ")"
THIS_SCRIPT_NAME="$(basename "$0")"
: Import canisters
mkdir -p packages/nns/candid
import_did "rs/nns/governance/canister/governance.did" "governance.did" "nns"
import_did "rs/nns/governance/canister/governance_test.did" "governance_test.did" "nns"
import_did "rs/nns/gtc/canister/gtc.did" "genesis_token.did" "nns"
import_did "rs/nns/sns-wasm/canister/sns-wasm.did" "sns_wasm.did" "nns"
mkdir -p packages/sns/candid
import_did "rs/sns/swap/canister/swap.did" "sns_swap.did" "sns"
import_did "rs/sns/root/canister/root.did" "sns_root.did" "sns"
import_did "rs/sns/governance/canister/governance.did" "sns_governance.did" "sns"
import_did "rs/sns/governance/canister/governance_test.did" "sns_governance_test.did" "sns"
mkdir -p packages/cmc/candid
import_did "rs/nns/cmc/cmc.did" "cmc.did" "cmc"
mkdir -p packages/ledger-icp/candid
import_did "rs/ledger_suite/icp/ledger.did" "ledger.did" "ledger-icp"
import_did "rs/ledger_suite/icp/index/index.did" "index.did" "ledger-icp"
mkdir -p packages/ledger-icrc/candid
import_did "rs/ledger_suite/icrc1/ledger/ledger.did" "icrc_ledger.did" "ledger-icrc"
import_did "rs/ledger_suite/icrc1/index-ng/index-ng.did" "icrc_index-ng.did" "ledger-icrc"
mkdir -p packages/ckbtc/candid
import_did "rs/bitcoin/ckbtc/minter/ckbtc_minter.did" "minter.did" "ckbtc"
download_did https://raw.githubusercontent.com/dfinity/bitcoin-canister/master/canister/candid.did "bitcoin.did" "ckbtc"
mkdir -p packages/cketh/candid
import_did "rs/ethereum/cketh/minter/cketh_minter.did" "minter.did" "cketh"
import_did "rs/ethereum/ledger-suite-orchestrator/ledger_suite_orchestrator.did" "orchestrator.did" "cketh"
mkdir -p packages/ic-management/candid
download_did https://raw.githubusercontent.com/dfinity/portal/master/docs/references/_attachments/ic.did "ic-management.did" "ic-management"
: Fin