-
Notifications
You must be signed in to change notification settings - Fork 1
/
archway.sh
executable file
·156 lines (120 loc) · 3.91 KB
/
archway.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
#!/bin/bash
source consts.sh
function deployContract() {
local contactFile=$1
local init=$2
local contractAddr=$3
echo "$WASM Deploying" $contactFile " and save to " $contractAddr
local res=$(archwayd tx wasm store $contactFile --from $ARCHWAY_WALLET --node $ARCHWAY_NODE --keyring-backend test --chain-id $CHAIN_ID --gas-prices 0.02$TOKEN --gas auto --gas-adjustment 1.3 -y --output json -b block)
# echo "Result: "
# echo $res
local code_id=$(echo $res | jq -r '.logs[0].events[] | select(.type=="store_code") | .attributes[] | select(.key=="code_id") | .value')
echo "code id: "
echo $code_id
local wallet_address=$(archwayd keys show $ARCHWAY_WALLET --keyring-backend=test --output=json | jq -r .address)
local op=$(archwayd query account $wallet_address --output json)
local sequence=$(echo $op | jq -r '.sequence')
echo "sequence number: " $sequence
archwayd tx wasm instantiate $code_id $init \
--from $ARCHWAY_WALLET \
--label "name service" \
--node $ARCHWAY_NODE \
--chain-id $CHAIN_ID \
--gas auto \
--sequence $sequence \
--keyring-backend test \
--gas-prices 0.02$TOKEN \
--gas-adjustment 1.3 \
-y --no-admin
log
echo "sleep for 10 seconds"
log
sleep 10
CONTRACT=$(archwayd query wasm list-contract-by-code $code_id --node $ARCHWAY_NODE --output json | jq -r '.contracts[-1]')
echo "$WASM IBC Contract Deployed at address"
echo $CONTRACT
echo $CONTRACT >$contractAddr
}
function deployIBC() {
local init='{}'
deployContract $IBC_WASM $init $WASM_IBC_CONTRACT
}
function deployMock() {
local ibcContract=$1
local init="{\"timeout_height\":500000,\"ibc_host\":\"$ibcContract\"}"
echo " init message mock: "$init
deployContract $MOCK_WASM $init $WASM_MOCK_APP_CONTRACT
separator
local mockApp=$(cat $WASM_MOCK_APP_CONTRACT)
local bindPortArgs="{\"bind_port\":{\"port_id\":\"mock\",\"address\":\"$mockApp\"}}"
local res=$(archwayd tx wasm execute $ibcContract $bindPortArgs \
--from $ARCHWAY_WALLET \
--node $ARCHWAY_NODE \
--chain-id $CHAIN_ID \
--gas-prices 0.02$TOKEN \
--keyring-backend test \
--gas auto \
--gas-adjustment 1.3 \
-y)
sleep 5
echo $res
separator
}
function deployLightClient() {
echo "To deploy light client"
local init="{}"
deployContract $LIGHT_WASM $init $WASM_LIGHT_CLIENT_CONTRACT
local lightClientAddress=$(cat $WASM_LIGHT_CLIENT_CONTRACT)
local ibcContract=$1
separator
echo "$WASM Register iconclient to IBC Contract"
registerClient="{\"register_client\":{\"client_type\":\"iconclient\",\"client_address\":\"$lightClientAddress\"}}"
local res=$(archwayd tx wasm execute $ibcContract $registerClient \
--from $ARCHWAY_WALLET \
--node $ARCHWAY_NODE \
--chain-id $CHAIN_ID \
--gas-prices 0.02$TOKEN \
--keyring-backend test \
--gas auto \
--gas-adjustment 1.3 \
-y)
sleep 5
echo $res
separator
}
function buildContracts() {
cd $CONTRACTS_DIR
./optimize_build.sh
cp -r $CONTRACTS_DIR/artifacts/cw_ibc_core.wasm $SCRIPTS_DIR/artifacts
# cp -r $CONTRACTS_DIR/artifacts/cw_ibc_core.wasm $SCRIPTS_DIR/artifacts
cp -r $CONTRACTS_DIR/artifacts/cw_icon_light_client.wasm $SCRIPTS_DIR/artifacts
}
function setup() {
deployIBC
local ibcContract=$(cat $WASM_IBC_CONTRACT)
deployLightClient $ibcContract
deployMock $ibcContract
}
########## ENTRYPOINTS ###############
usage() {
echo "Usage: $0 []"
exit 1
}
if [ $# -eq 1 ]; then
# create folder if not exists
if [ ! -d $CONTRACT_ADDRESSES_FOLDER/archway ]; then
mkdir -p env/archway
fi
CMD=$1
else
usage
fi
case "$CMD" in
setup)
setup
;;
*)
echo "Error: unknown command: $CMD"
usage
;;
esac