-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
Β·152 lines (131 loc) Β· 4.27 KB
/
deploy.sh
File metadata and controls
executable file
Β·152 lines (131 loc) Β· 4.27 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
#!/bin/bash
# SecureFlow Contract Deployment Script
# This script deploys the updated contract with rating and badge system
set -e
echo "π SecureFlow Contract Deployment"
echo "================================"
echo ""
# Colors for output
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m' # No Color
# Check if WASM file exists (Cargo often puts it under release/deps/)
WASM_FILE="target/wasm32-unknown-unknown/release/secureflow.wasm"
WASM_FILE_DEPS="target/wasm32-unknown-unknown/release/deps/secureflow.wasm"
if [ ! -f "$WASM_FILE" ] && [ ! -f "$WASM_FILE_DEPS" ]; then
echo -e "${RED}β WASM file not found. Building contract...${NC}"
cargo build -p secureflow --target wasm32-unknown-unknown --release
fi
# Prefer the deps wasm if present (it is the real cdylib artifact)
if [ -f "$WASM_FILE_DEPS" ]; then
WASM_FILE="$WASM_FILE_DEPS"
fi
echo -e "${GREEN}β
Contract built successfully${NC}"
echo ""
# Check for CLI (prefer `stellar`, fall back to `soroban`)
HAS_STELLAR=0
HAS_SOROBAN=0
if command -v stellar &> /dev/null; then
HAS_STELLAR=1
fi
if command -v soroban &> /dev/null; then
HAS_SOROBAN=1
fi
if [ "$HAS_STELLAR" -eq 0 ] && [ "$HAS_SOROBAN" -eq 0 ]; then
echo -e "${RED}β Neither 'stellar' nor 'soroban' CLI was found.${NC}"
echo "Install from: https://developers.stellar.org/docs/tools/cli"
exit 1
fi
# Get network (default to testnet)
NETWORK=${1:-testnet}
echo -e "${YELLOW}π‘ Deploying to: ${NETWORK}${NC}"
echo ""
# Check if source account is provided
if [ -z "$2" ]; then
echo -e "${YELLOW}β οΈ No source account provided.${NC}"
echo "Usage: ./deploy.sh [network] [source-account]"
echo "Example: ./deploy.sh testnet GABCDEF..."
echo ""
echo "Please provide your Stellar account public key:"
read -p "Source Account: " SOURCE_ACCOUNT
else
SOURCE_ACCOUNT=$2
fi
echo ""
echo -e "${YELLOW}π¦ Deploying contract...${NC}"
echo ""
# Deploy contract (capture output even on failure)
set +e
if [ "$HAS_STELLAR" -eq 1 ]; then
DEPLOY_OUTPUT=$(stellar contract deploy \
--wasm "$WASM_FILE" \
--source-account "$SOURCE_ACCOUNT" \
--network "$NETWORK" 2>&1)
DEPLOY_EXIT_CODE=$?
else
DEPLOY_OUTPUT=$(soroban contract deploy \
--wasm "$WASM_FILE" \
--source "$SOURCE_ACCOUNT" \
--network "$NETWORK" 2>&1)
DEPLOY_EXIT_CODE=$?
fi
set -e
if [ "$DEPLOY_EXIT_CODE" -ne 0 ]; then
echo -e "${RED}β Deployment command failed (exit code: ${DEPLOY_EXIT_CODE})${NC}"
echo "Output:"
echo "$DEPLOY_OUTPUT"
exit "$DEPLOY_EXIT_CODE"
fi
# Extract contract ID from output (portable across macOS/Linux)
# Stellar/Soroban contract IDs are StrKey and start with "C" (56 chars).
CONTRACT_ID=$(
echo "$DEPLOY_OUTPUT" | awk '
{
# If the line itself is a contract id, keep it
if ($0 ~ /^C[A-Z2-7]+$/ && length($0) == 56) id=$0
# If the line contains a lab URL, extract after /contract/
if (index($0, "/contract/") > 0) {
s=$0
sub(/.*\/contract\//, "", s)
sub(/[^A-Z2-7].*/, "", s)
if (s ~ /^C[A-Z2-7]+$/ && length(s) == 56) id=s
}
}
END { print id }
'
)
if [ -z "$CONTRACT_ID" ]; then
echo -e "${RED}β Deployment failed or contract ID not found${NC}"
echo "Output:"
echo "$DEPLOY_OUTPUT"
exit 1
fi
echo -e "${GREEN}β
Contract deployed successfully!${NC}"
echo ""
echo -e "${GREEN}π Contract ID: ${CONTRACT_ID}${NC}"
echo ""
# Save contract ID to file
echo "$CONTRACT_ID" > .contract-id
echo "Contract ID saved to .contract-id"
echo ""
echo -e "${YELLOW}π Next Steps:${NC}"
echo "1. Initialize contract storage once (owner + fee collector + fee in basis points, max 1000 = 10%):"
echo ""
echo " stellar contract invoke \\"
echo " --network $NETWORK \\"
echo " --source-account $SOURCE_ACCOUNT \\"
echo " --id $CONTRACT_ID \\"
echo " -- initialize \\"
echo " --owner <OWNER_PUBLIC_KEY> \\"
echo " --fee_collector <FEE_COLLECTOR_PUBLIC_KEY> \\"
echo " --platform_fee_bp 100 \\"
echo " --default_whitelisted_tokens [<USDC_TOKEN_CONTRACT_ADDRESS>]"
echo ""
echo "2. Update your .env file with:"
echo " VITE_SECUREFLOW_CONTRACT_ID=$CONTRACT_ID"
echo ""
echo "3. Rebuild frontend:"
echo " npm run build"
echo ""
echo -e "${GREEN}β¨ Deployment complete!${NC}"