-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathdeploy_and_upgrade.sh
More file actions
executable file
·145 lines (116 loc) · 3.96 KB
/
deploy_and_upgrade.sh
File metadata and controls
executable file
·145 lines (116 loc) · 3.96 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
#!/bin/bash
# Script for deploying and upgrading the Boundless contract
# Usage: ./deploy_and_upgrade.sh [deploy|upgrade] [network] [source_account]
# Default values
ACTION=${1:-"deploy"}
NETWORK=${2:-"testnet"}
SOURCE_ACCOUNT=${3:-"alice"}
# Colors for output
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m' # No Color
# Check if stellar CLI is installed
if ! command -v stellar &> /dev/null; then
echo -e "${RED}Error: stellar CLI is not installed.${NC}"
echo "Please install it from https://soroban.stellar.org/docs/getting-started/setup"
exit 1
fi
# Function to deploy the contract
deploy_contract() {
echo -e "${YELLOW}Deploying Boundless contract to ${NETWORK}...${NC}"
# Build the contract with reference-types enabled
echo "Building contract..."
# Use stellar contract build which handles the reference-types issue
stellar contract build
# Deploy the contract
echo "Deploying contract..."
CONTRACT_ID=$(stellar contract deploy \
--wasm target/wasm32v1-none/release/boundless.wasm \
--source $SOURCE_ACCOUNT \
--network $NETWORK)
if [ $? -ne 0 ]; then
echo -e "${RED}Deployment failed!${NC}"
exit 1
fi
echo -e "${GREEN}Contract deployed successfully!${NC}"
echo "Contract ID: $CONTRACT_ID"
# Create .stellar directory if it doesn't exist
mkdir -p .stellar
# Save the contract ID to a file for future reference
echo $CONTRACT_ID > .stellar/contract_id_${NETWORK}.txt
echo "Contract ID saved to .stellar/contract_id_${NETWORK}.txt"
# Get the admin address
ADMIN_ADDRESS=$(stellar keys address $SOURCE_ACCOUNT)
echo "Admin address: $ADMIN_ADDRESS"
# Initialize the contract
echo "Initializing contract..."
stellar contract invoke \
--id $CONTRACT_ID \
--source $SOURCE_ACCOUNT \
--network $NETWORK \
-- \
initialize \
--admin $ADMIN_ADDRESS
if [ $? -ne 0 ]; then
echo -e "${RED}Initialization failed!${NC}"
exit 1
fi
echo -e "${GREEN}Contract initialized successfully!${NC}"
}
# Function to upgrade the contract
upgrade_contract() {
echo -e "${YELLOW}Upgrading Boundless contract on ${NETWORK}...${NC}"
# Check if contract ID file exists
if [ ! -f .stellar/contract_id_${NETWORK}.txt ]; then
echo -e "${RED}Contract ID file not found. Please deploy the contract first.${NC}"
exit 1
fi
# Read the contract ID
CONTRACT_ID=$(cat .stellar/contract_id_${NETWORK}.txt)
# Build the contract with reference-types enabled
echo "Building contract..."
# Use stellar contract build which handles the reference-types issue
stellar contract build
# Install the new WASM
echo "Installing new WASM..."
WASM_HASH=$(stellar contract upload \
--source-account $SOURCE_ACCOUNT \
--wasm target/wasm32v1-none/release/boundless.wasm \
--network $NETWORK)
if [ $? -ne 0 ]; then
echo -e "${RED}WASM installation failed!${NC}"
exit 1
fi
echo "WASM hash: $WASM_HASH"
# Upgrade the contract
echo "Upgrading contract..."
stellar contract invoke \
--id $CONTRACT_ID \
--source $SOURCE_ACCOUNT \
--network $NETWORK \
-- \
upgrade \
--new_wasm_hash $WASM_HASH
if [ $? -ne 0 ]; then
echo -e "${RED}Upgrade failed!${NC}"
exit 1
fi
echo -e "${GREEN}Contract upgraded successfully!${NC}"
echo "Contract ID: $CONTRACT_ID"
}
# Main script logic
case $ACTION in
"deploy")
deploy_contract
;;
"upgrade")
upgrade_contract
;;
*)
echo -e "${RED}Invalid action. Use 'deploy' or 'upgrade'.${NC}"
echo "Usage: ./deploy_and_upgrade.sh [deploy|upgrade] [network] [source_account]"
exit 1
;;
esac
echo -e "${GREEN}Operation completed successfully!${NC}"