-
Notifications
You must be signed in to change notification settings - Fork 5
/
validator_test_upload_contract.sh
executable file
·94 lines (80 loc) · 3.32 KB
/
validator_test_upload_contract.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
args=("$@")
BIN=neutrond
CONTRACT=${args[0]}
NEUTRON_KEY_NAME=validator_test
GAS_PRICES=0.01untrn
EXPLORER_URL=http://explorer.quark.ntrn.info/
FAUCET_URL=https://t.me/+Y_BQropm0_VlZjVi
NODE_URL="${NODE_URL:-tcp://localhost:26657}"
echo "Node url: $NODE_URL"
if [ $# != "1" ]
then
echo "Usage: ./validator_test_upload_contract.sh [path_to_wasm_artifact]"
exit
fi
if [[ ! -f $CONTRACT ]]
then
echo "Artifact file doesn't exists"
exit
fi
if ! command -v $BIN &> /dev/null
then
echo "$BIN could not be found.
You can add symlink from your neutron binary to /bin this way: ln -s PATH_TO_NEUTRON_BIN /bin/neutron"
exit
fi
NEUTRON_CHAIN_ID=$(neutrond status --node ${NODE_URL}| jq -r '.NodeInfo.network')
if [ -z "$NEUTRON_CHAIN_ID" ]
then
echo "Cannot get chain id"
exit;
fi
echo "Chain id: $NEUTRON_CHAIN_ID"
RES=$($BIN keys add $NEUTRON_KEY_NAME --output json)
NEUTRON_ADDRESS=$(echo $RES | jq -r .address)
MNEMONIC=$(echo $RES | jq -r .mnemonic)
if [ "$NEUTRON_ADDRESS" = "" ]
then
echo "Can't get address from key. Probably key already exists and you should agree to override the existing name"
exit
fi
echo "Local address in neutron: $NEUTRON_ADDRESS"
echo ""
echo " ##### ### ### ### "
echo "# # ## # # ###### # # ##### # # # # ###### # # #### # # # #### ### ### ### "
echo "# # # # # # # # # # ## ## ## # # ## ## # # ## # # # # ### ### ### "
echo " ##### # # # # ##### # # # # # ## # # # # ##### # ## # # # # # # # # # # # "
echo " # ###### # # # # # ##### # # # # # # # # # # # # # # # "
echo "# # # # # # # # # # # # # # ## # # # # # # ## # # # ### ### ### "
echo " ##### # # ## ###### #### # # # # # # ###### # # #### # # # #### ### ### ### "
echo ""
echo "Key mnemonic: $MNEMONIC"
echo "Key name: $NEUTRON_KEY_NAME"
echo ""
echo "Please go to $FAUCET_URL and get tokens for $NEUTRON_ADDRESS"
echo "Make sure tx is passed by going to $EXPLORER_URL/accounts/$NEUTRON_ADDRESS"
echo "Hit enter when ready"
read
echo "Upload the queries contract"
RES=$(${BIN} tx wasm store ${CONTRACT} --from ${NEUTRON_KEY_NAME} --gas 50000000 --node ${NODE_URL} --chain-id ${NEUTRON_CHAIN_ID} --broadcast-mode=block --gas-prices ${GAS_PRICES} -y --output json)
CONTRACT_CODE_ID=$(echo $RES | jq -r '.logs[0].events[1].attributes[0].value')
if [[ $CONTRACT_CODE_ID == "null" ]]
then
echo "Can't get code id"
echo "$RES"
exit
fi
echo "Contract code id: $CONTRACT_CODE_ID"
echo ""
echo "Instantiate the contract"
INIT_CONTRACT='{}'
RES=$(${BIN} tx wasm instantiate $CONTRACT_CODE_ID "$INIT_CONTRACT" --from $NEUTRON_KEY_NAME --admin ${NEUTRON_ADDRESS} -y --node ${NODE_URL} --chain-id ${NEUTRON_CHAIN_ID} --output json --broadcast-mode=block --label "init" --gas-prices ${GAS_PRICES} --gas auto --gas-adjustment 1.4)
CONTRACT_ADDRESS=$(echo $RES | jq -r '.logs[0].events[0].attributes[0].value')
echo "Contract address: $CONTRACT_ADDRESS"
if [[ $CONTRACT_ADDRESS == "null" ]]
then
echo "Can't get contract address"
echo "$RES"
exit
fi
echo "$CONTRACT_ADDRESS" > ./contract_address.tmp