forked from Lilly-Protocol/lily-contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
89 lines (75 loc) · 2.2 KB
/
Copy pathdeploy.sh
File metadata and controls
89 lines (75 loc) · 2.2 KB
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
#!/usr/bin/env sh
set -eu
# Deploy all Lily Protocol contracts to a target network.
#
# Usage:
# ./scripts/deploy.sh <network> <source-account> [output-file]
#
# Examples:
# ./scripts/deploy.sh testnet alice
# ./scripts/deploy.sh local alice ./config/deployed-contracts.json
#
# The script records returned contract IDs to the output file (default:
# ./config/deployed-contracts.json) so that init-contracts.sh can consume them.
NETWORK="${1:-}"
SOURCE="${2:-}"
OUTPUT_FILE="${3:-./config/deployed-contracts.json}"
DRY_RUN="${DRY_RUN:-false}"
CONTRACT_PACKAGES="protocol identity wallet payments"
WASM_DIR="target/wasm32v1-none/release"
if [ -z "$NETWORK" ] || [ -z "$SOURCE" ]; then
echo "Usage: $0 <network> <source-account> [output-file]" >&2
exit 1
fi
if [ "$DRY_RUN" != "false" ]; then
echo "Dry run mode enabled. No contracts will be deployed."
fi
if ! command -v stellar >/dev/null 2>&1; then
echo "Error: stellar CLI is not installed." >&2
exit 1
fi
mkdir -p "$(dirname "$OUTPUT_FILE")"
# Start with an empty JSON object.
{
printf '{'
first=1
for pkg in $CONTRACT_PACKAGES; do
wasm_path="$WASM_DIR/$pkg.wasm"
if [ ! -f "$wasm_path" ]; then
echo "Error: $wasm_path not found. Run 'make build-wasm' first." >&2
exit 1
fi
if [ "$DRY_RUN" != "false" ]; then
contract_id="CDRYRUN${pkg}000000000000000000000000000"
echo "Dry run: would deploy $pkg -> $contract_id"
else
echo "Deploying $pkg..."
contract_id=$(stellar contract deploy \
--wasm "$wasm_path" \
--source-account "$SOURCE" \
--network "$NETWORK" \
2>&1 | tail -n 1 | tr -d '[:space:]')
if [ -z "$contract_id" ]; then
echo "Error: failed to deploy $pkg (no contract id returned)." >&2
exit 1
fi
fi
if [ "$first" -eq 1 ]; then
first=0
else
printf ','
fi
printf '"%s":"%s"' "$pkg" "$contract_id"
done
printf '}\n'
} > "$OUTPUT_FILE"
echo "Deployment complete. Contract IDs written to $OUTPUT_FILE"
if command -v jq >/dev/null 2>&1; then
jq . "$OUTPUT_FILE"
else
cat "$OUTPUT_FILE"
fi
if [ "$DRY_RUN" = "false" ]; then
echo ""
echo "Next step: initialize contracts with ./scripts/init-contracts.sh"
fi