forked from Lafiya-xyz/Lafiya-contract
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy-testnet.sh
More file actions
executable file
·195 lines (170 loc) · 5.86 KB
/
Copy pathdeploy-testnet.sh
File metadata and controls
executable file
·195 lines (170 loc) · 5.86 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
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#!/bin/bash
# Exit immediately if a command exits with a non-zero status
set -e
# Lafiya Smart Contract Deployment Script
# Deploys both contracts to Stellar Testnet (or other networks) and initializes them.
NETWORK="testnet"
IDENTITY=""
ADMIN_ADDRESS=""
YES=false
# Help message
show_help() {
echo "Usage: $0 [options]"
echo ""
echo "Options:"
echo " -i, --identity <identity> stellar-cli identity name to use for deployment (or set STELLAR_IDENTITY)"
echo " -a, --admin-address <address> Admin address for contract initialization (defaults to the identity's address)"
echo " -n, --network <network> Stellar network (default: testnet)"
echo " -y, --yes Skip interactive confirmation prompt"
echo " -h, --help Show this help message"
echo ""
echo "Example:"
echo " $0 --identity my-testnet-account"
}
# Parse command line options
while [[ $# -gt 0 ]]; do
case "$1" in
-i|--identity)
IDENTITY="$2"
shift 2
;;
-a|--admin-address)
ADMIN_ADDRESS="$2"
shift 2
;;
-n|--network)
NETWORK="$2"
shift 2
;;
-y|--yes)
YES=true
shift
;;
-h|--help)
show_help
exit 0
;;
*)
echo "Error: Unknown option: $1" >&2
show_help >&2
exit 1
;;
esac
done
# Check if stellar CLI is installed
if ! command -v stellar &> /dev/null; then
echo "Error: 'stellar' CLI is not installed or not in PATH." >&2
echo "Please install it following instructions at: https://developers.stellar.org/docs/smart-contracts/getting-started/setup" >&2
exit 1
fi
# Fallback to environment variable for identity if not provided via CLI
if [ -z "$IDENTITY" ]; then
IDENTITY="$STELLAR_IDENTITY"
fi
if [ -z "$IDENTITY" ]; then
echo "Error: Identity is required. Specify it with -i/--identity or the STELLAR_IDENTITY environment variable." >&2
show_help >&2
exit 1
fi
# Resolve admin address if not provided
if [ -z "$ADMIN_ADDRESS" ]; then
echo "Resolving admin address for identity '$IDENTITY'..."
if ! ADMIN_ADDRESS=$(stellar keys address "$IDENTITY" 2>/dev/null); then
echo "Error: Failed to resolve address for identity '$IDENTITY' using 'stellar keys address'." >&2
echo "Ensure the identity exists in stellar-cli, or provide the admin address explicitly using -a/--admin-address." >&2
exit 1
fi
fi
# Print configuration and ask for confirmation
echo "=========================================================="
echo " Lafiya Soroban Contract Deployment"
echo "=========================================================="
echo "Network: $NETWORK"
echo "Identity: $IDENTITY"
echo "Admin Address: $ADMIN_ADDRESS"
echo "=========================================================="
echo ""
if [ "$YES" = false ]; then
read -p "Do you want to proceed with the deployment to $NETWORK? (y/N): " CONFIRM
if [[ ! "$CONFIRM" =~ ^[yY](es)?$ ]]; then
echo "Deployment aborted."
exit 0
fi
fi
# 1. Build WASM contracts
echo "Building WASM contracts for release..."
cargo build --workspace --release --target wasm32v1-none
# Paths to the compiled WASM files
ATTESTER_WASM="target/wasm32v1-none/release/attester_registry.wasm"
ATTESTATION_WASM="target/wasm32v1-none/release/attestation_registry.wasm"
# Verify built files exist
if [ ! -f "$ATTESTER_WASM" ]; then
echo "Error: $ATTESTER_WASM not found after build." >&2
exit 1
fi
if [ ! -f "$ATTESTATION_WASM" ]; then
echo "Error: $ATTESTATION_WASM not found after build." >&2
exit 1
fi
# 2. Deploy attester-registry
echo "Deploying attester-registry..."
ATTESTER_REGISTRY_ID=$(stellar contract deploy \
--wasm "$ATTESTER_WASM" \
--source-account "$IDENTITY" \
--network "$NETWORK")
if [ -z "$ATTESTER_REGISTRY_ID" ]; then
echo "Error: Failed to deploy attester-registry." >&2
exit 1
fi
echo "attester-registry deployed successfully. ID: $ATTESTER_REGISTRY_ID"
echo ""
# 3. Deploy attestation-registry
echo "Deploying attestation-registry..."
ATTESTATION_REGISTRY_ID=$(stellar contract deploy \
--wasm "$ATTESTATION_WASM" \
--source-account "$IDENTITY" \
--network "$NETWORK")
if [ -z "$ATTESTATION_REGISTRY_ID" ]; then
echo "Error: Failed to deploy attestation-registry." >&2
exit 1
fi
echo "attestation-registry deployed successfully. ID: $ATTESTATION_REGISTRY_ID"
echo ""
# 4. Initialize attester-registry
echo "Initializing attester-registry..."
stellar contract invoke \
--id "$ATTESTER_REGISTRY_ID" \
--source-account "$IDENTITY" \
--network "$NETWORK" \
-- initialize \
--admin "$ADMIN_ADDRESS"
echo "attester-registry initialized successfully."
echo ""
# 5. Initialize attestation-registry
echo "Initializing attestation-registry..."
stellar contract invoke \
--id "$ATTESTATION_REGISTRY_ID" \
--source-account "$IDENTITY" \
--network "$NETWORK" \
-- initialize \
--admin "$ADMIN_ADDRESS" \
--attester_registry "$ATTESTER_REGISTRY_ID"
echo "attestation-registry initialized successfully."
echo ""
# 6. Save deployment details to deployments/<network>.json
mkdir -p deployments
DEPLOYMENTS_FILE="deployments/${NETWORK}.json"
cat <<EOF > "$DEPLOYMENTS_FILE"
{
"network": "$NETWORK",
"attester_registry": "$ATTESTER_REGISTRY_ID",
"attestation_registry": "$ATTESTATION_REGISTRY_ID",
"admin": "$ADMIN_ADDRESS",
"timestamp": "$(date -u +"%Y-%m-%dT%H:%M:%SZ")"
}
EOF
echo "=========================================================="
echo " Deployment Complete!"
echo "=========================================================="
echo "Contract IDs and configuration saved to: $DEPLOYMENTS_FILE"
echo "=========================================================="