-
Notifications
You must be signed in to change notification settings - Fork 1
/
deploy.sh
executable file
·179 lines (155 loc) · 6.48 KB
/
deploy.sh
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
#!/bin/bash
payer="none" # Payer wallet, pays for all the executions
auction="none" # Auction program wallet
test_asset="none" # Test game TradableAsset program wallet
xgold="none" # Current XGold program wallet
meta_server="none" # Test game meta server address
endpoint="http://localhost:8080/api/public" # Pravda endpoint
help="false" # Show help tooltip
help_text="\n""Options:"
help_text+="\n"'-p --payer Payer wallet, pays for all the executions'
help_text+="\n""-a --auction Auction program wallet"
help_text+="\n""-t --test-asset Test game TradableAsset program wallet"
help_text+="\n""-x --xgold Current XGold program wallet"
help_text+="\n""-m --meta-server Test game meta server base URL (without class/instance postfixes)"
help_text+="\n""-e --endpoint Pravda endpoint, default: http://localhost:8080/api/public"
help_text+="\n""-h --help Show this help message"
# Parse arguments
while [ "$1" != "" ]; do
case $1 in
-p | --payer ) shift
payer=$1
;;
-a | --auction ) shift
auction=$1
;;
-t | --test-asset ) shift
test_asset=$1
;;
-x | --xgold ) shift
xgold=$1
;;
-m | --meta-server ) shift
meta_server=$1
;;
-e | --endpoint ) shift
endpoint=$1
;;
-h | --help ) shift
help="true"
;;
* ) echo "Unknown argument: $1"
echo -e "${help_text}"
exit 1
esac
shift
done
# Show help tooltip if needed
if [[ $help == "true" ]]; then
echo -e "${help_text}"
exit 0
fi
# Check if all needed arguments are provided
if [[ $payer == "none" ]] || [[ $auction == "none" ]] || \
[[ $test_asset == "none" ]] || [[ $xgold == "none" ]] || [[ $meta_server == "none" ]]; then
echo "Not enough arguments!"
exit 1
fi
# Get program addresses
auction_address=$( cat $auction | jq -r '.address' )
test_asset_address=$( cat $test_asset | jq -r '.address' )
xgold_address=$( cat $xgold | jq -r '.address' )
# Compile dotnet solution
echo "Compiling Auction program..."
publish_log=$( dotnet publish Auction/source/Auction.sln )
if [[ $publish_log == *"error MSB"* ]]; then
echo "dotnet publish failed"
echo $publish_log
exit 1
fi
# Auction dotnet package bin route
auction_compiled="Auction/source/bin/Auction.pravda"
# Check if auction program was previously deployed
echo "Checking if Auction has been deployed before..."
auction_deployed=$( echo "push x$auction_address pexist" | pravda compile asm | pravda broadcast run -w $payer -l 10000 -e $endpoint )
# Update if already deployed
if [[ $auction_deployed == *"bool.true"* ]]; then
echo "Auction already deployed, updating the program"
update_log=$( pravda broadcast update -i $auction_compiled -w $payer -p $auction -l 9000000 -e $endpoint )
if [[ $update_log == *"Exception in"* ]]; then
echo "Failed to update Auction"
exit 1
else
echo "Auction program successfully updated"
fi
# Deploy if not yet deployed
else
echo "Auction not deployed yet, deploying"
deploy_log=$( pravda broadcast deploy -i $auction_compiled -w $payer -p $auction -l 9000000 -e $endpoint )
if [[ $deploy_log == *"Exception in"* ]]; then
echo "Failed to deploy Auction"
exit 1
else
echo "Auction program successfully deployed"
fi
fi
# Deploy test TradableAsset program
# Edit meta URL
meta_server_escaped=$(echo $meta_server | sed 's/\//\\\//g')
command="s/https:\/\/some_url\/class-meta\//${meta_server_escaped}class-meta\//1"
sed -i $command TradableAsset/source/XG/TradableXGAsset.cs
command="s/https:\/\/some_url\/instance-meta\//${meta_server_escaped}instance-meta\//1"
sed -i $command TradableAsset/source/XG/TradableXGAsset.cs
# Compile dotnet solution
echo "Compiling TradableAsset program..."
publish_log=$( dotnet publish TradableAsset/source/XG/TradableXGAsset.csproj )
if [[ $log == *"error MSB"* ]]; then
echo "dotnet publish failed"
exit 1
fi
# TradableAsset dotnet package bin route
test_asset_compiled="TradableAsset/source/XG/bin/TradableXGAsset.pravda"
# Check if TradableAsset program was previously deployed
echo "Checking if TradableAsset has been deployed before..."
test_asset_deployed=$( echo "push x$test_asset_address pexist" | pravda compile asm | pravda broadcast run -w $payer -l 10000 -e $endpoint )
# Update if already deployed
if [[ $test_asset_deployed == *"bool.true"* ]]; then
echo "TradableAsset already deployed, updating the program..."
update_log=$( pravda broadcast update -i $test_asset_compiled -w $payer -p $test_asset -l 9000000 -e $endpoint )
if [[ $update_log == *"Exception in"* ]]; then
echo "Failed to update TradableAsset"
exit 1
else
echo "TradableAsset program successfully updated"
fi
# Deploy if not yet deployed
else
echo "TradableAsset not deployed yet, deploying..."
deploy_log=$( pravda broadcast deploy -i $test_asset_compiled -w $payer -p $test_asset -l 9000000 -e $endpoint )
if [[ $deploy_log == *"Exception in"* ]]; then
echo "Failed to deploy TradableAsset"
exit 1
else
echo "TradableAsset program successfully deployed"
fi
fi
# Set Auction address in TradableAsset
echo "Setting Auction address in TradableAsset..."
set_auction_log=$( echo "push x$auction_address push \"SetAuction\" push x$test_asset_address push 2 pcall" | pravda compile asm | pravda broadcast run -w $test_asset --watt-payer-wallet $payer -l 100000 -e $endpoint )
if [[ $set_auction_log == *"Exception in"* ]]; then
echo "Failed to set Auction address"
exit 1
else
echo "Auction address successfully set"
fi
# Set XGold adress in Auction
echo "Setting XGold address in Auction..."
set_xgold_log=$( echo "push x$xgold_address push \"SetXGAddress\" push x$auction_address push 2 pcall" | pravda compile asm | pravda broadcast run -w $auction --watt-payer-wallet $payer -l 100000 -e $endpoint )
if [[ $set_xgold_log == *"Exception in"* ]]; then
echo "Failed to set XGold address"
exit 1
else
echo "XGold address successfully set"
fi
echo "Finished deploying and setting up marketplace"
exit 0