Skip to content

Commit 09f42ce

Browse files
committed
Canton: Add upload token standard dars script
1 parent e5aefb9 commit 09f42ce

1 file changed

Lines changed: 152 additions & 0 deletions

File tree

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
usage() {
6+
cat <<'EOF'
7+
Upload Canton token-standard interface DARs to a participant using grpcurl.
8+
9+
Required environment variables:
10+
PARTICIPANT_HOST gRPC host:port of the participant
11+
AUTH_TOKEN Bearer token with package upload rights
12+
13+
Optional environment variables:
14+
SYNCHRONIZER_ID Target synchronizer/domain id for vetting
15+
PROTO_ROOT Defaults to ~/Source/splice/canton/community/ledger-api/src/main/protobuf
16+
PACKAGE_PROTO Defaults to com/daml/ledger/api/v2/admin/package_management_service.proto
17+
VALIDATE_FIRST Defaults to 1. Set to 0 to skip ValidateDarFile calls.
18+
LIST_AFTER Defaults to 1. Set to 0 to skip ListKnownPackages at the end.
19+
20+
The script uploads these DARs in dependency order:
21+
splice-api-token-metadata-v1
22+
splice-api-token-holding-v1
23+
splice-api-token-transfer-instruction-v1
24+
splice-api-token-allocation-v1
25+
splice-api-token-allocation-request-v1
26+
splice-api-token-allocation-instruction-v1
27+
EOF
28+
}
29+
30+
if [[ "${1:-}" == "-h" || "${1:-}" == "--help" ]]; then
31+
usage
32+
exit 0
33+
fi
34+
35+
: "${PARTICIPANT_HOST:?PARTICIPANT_HOST is required}"
36+
: "${AUTH_TOKEN:?AUTH_TOKEN is required}"
37+
38+
PROTO_ROOT="${PROTO_ROOT:-$HOME/Source/splice/canton/community/ledger-api/src/main/protobuf}"
39+
PACKAGE_PROTO="${PACKAGE_PROTO:-com/daml/ledger/api/v2/admin/package_management_service.proto}"
40+
VALIDATE_FIRST="${VALIDATE_FIRST:-1}"
41+
LIST_AFTER="${LIST_AFTER:-1}"
42+
43+
DAR_METADATA="${DAR_METADATA:-$HOME/Source/splice/token-standard/splice-api-token-metadata-v1/.daml/dist/splice-api-token-metadata-v1-1.0.0.dar}"
44+
DAR_HOLDING="${DAR_HOLDING:-$HOME/Source/splice/token-standard/splice-api-token-holding-v1/.daml/dist/splice-api-token-holding-v1-1.0.0.dar}"
45+
DAR_TRANSFER_INSTR="${DAR_TRANSFER_INSTR:-$HOME/Source/splice/token-standard/splice-api-token-transfer-instruction-v1/.daml/dist/splice-api-token-transfer-instruction-v1-1.0.0.dar}"
46+
DAR_ALLOCATION="${DAR_ALLOCATION:-$HOME/Source/splice/token-standard/splice-api-token-allocation-v1/.daml/dist/splice-api-token-allocation-v1-1.0.0.dar}"
47+
DAR_ALLOC_REQ="${DAR_ALLOC_REQ:-$HOME/Source/splice/token-standard/splice-api-token-allocation-request-v1/.daml/dist/splice-api-token-allocation-request-v1-1.0.0.dar}"
48+
DAR_ALLOC_INSTR="${DAR_ALLOC_INSTR:-$HOME/Source/splice/token-standard/splice-api-token-allocation-instruction-v1/.daml/dist/splice-api-token-allocation-instruction-v1-1.0.0.dar}"
49+
50+
DARS=(
51+
"$DAR_METADATA"
52+
"$DAR_HOLDING"
53+
"$DAR_TRANSFER_INSTR"
54+
"$DAR_ALLOCATION"
55+
"$DAR_ALLOC_REQ"
56+
"$DAR_ALLOC_INSTR"
57+
)
58+
59+
for dar in "${DARS[@]}"; do
60+
if [[ ! -f "$dar" ]]; then
61+
echo "DAR not found: $dar" >&2
62+
exit 1
63+
fi
64+
done
65+
66+
if [[ ! -f "$PROTO_ROOT/$PACKAGE_PROTO" ]]; then
67+
echo "Proto not found: $PROTO_ROOT/$PACKAGE_PROTO" >&2
68+
exit 1
69+
fi
70+
71+
grpc_call() {
72+
local method="$1"
73+
grpcurl \
74+
-H "authorization: Bearer $AUTH_TOKEN" \
75+
-import-path "$PROTO_ROOT" \
76+
-proto "$PACKAGE_PROTO" \
77+
-d @ \
78+
"$PARTICIPANT_HOST" \
79+
"$method"
80+
}
81+
82+
json_for_dar() {
83+
local dar="$1"
84+
local submission_id="$2"
85+
local action="$3"
86+
87+
if [[ -n "${SYNCHRONIZER_ID:-}" ]]; then
88+
jq -n \
89+
--arg darFile "$(base64 < "$dar" | tr -d '\n')" \
90+
--arg submissionId "$submission_id" \
91+
--arg synchronizerId "$SYNCHRONIZER_ID" \
92+
--arg action "$action" \
93+
'if $action == "validate" then
94+
{
95+
darFile: $darFile,
96+
submissionId: $submissionId,
97+
synchronizerId: $synchronizerId
98+
}
99+
else
100+
{
101+
darFile: $darFile,
102+
submissionId: $submissionId,
103+
vettingChange: "VETTING_CHANGE_VET_ALL_PACKAGES",
104+
synchronizerId: $synchronizerId
105+
}
106+
end'
107+
else
108+
jq -n \
109+
--arg darFile "$(base64 < "$dar" | tr -d '\n')" \
110+
--arg submissionId "$submission_id" \
111+
--arg action "$action" \
112+
'if $action == "validate" then
113+
{
114+
darFile: $darFile,
115+
submissionId: $submissionId
116+
}
117+
else
118+
{
119+
darFile: $darFile,
120+
submissionId: $submissionId,
121+
vettingChange: "VETTING_CHANGE_VET_ALL_PACKAGES"
122+
}
123+
end'
124+
fi
125+
}
126+
127+
validate_dar() {
128+
local dar="$1"
129+
local sid="validate-$(basename "$dar")-$(date +%s)"
130+
json_for_dar "$dar" "$sid" "validate" | grpc_call "com.daml.ledger.api.v2.admin.PackageManagementService/ValidateDarFile"
131+
}
132+
133+
upload_dar() {
134+
local dar="$1"
135+
local sid="upload-$(basename "$dar")-$(date +%s)"
136+
json_for_dar "$dar" "$sid" "upload" | grpc_call "com.daml.ledger.api.v2.admin.PackageManagementService/UploadDarFile"
137+
}
138+
139+
for dar in "${DARS[@]}"; do
140+
echo "==> $(basename "$dar")"
141+
if [[ "$VALIDATE_FIRST" == "1" ]]; then
142+
echo " validating"
143+
validate_dar "$dar"
144+
fi
145+
echo " uploading"
146+
upload_dar "$dar"
147+
done
148+
149+
if [[ "$LIST_AFTER" == "1" ]]; then
150+
echo "==> listing known packages"
151+
printf '{}' | grpc_call "com.daml.ledger.api.v2.admin.PackageManagementService/ListKnownPackages"
152+
fi

0 commit comments

Comments
 (0)