-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathclose.sh
executable file
·123 lines (109 loc) · 3.99 KB
/
close.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
#!/bin/bash
AKASH_NET="https://raw.githubusercontent.com/ovrclk/net/master/mainnet"
fees="300uakt"
gaslimit="300000"
debug=${debug:-'false'}
dry_run=${dry_run:-'false'}
node_by_ping=${node_by_ping:-'false'}
version=$(akash version)
if [ "$?" != 0 ]; then
echo "Could not query akash version - make sure akash is available on the path." >&2
exit 1
fi
echo "Found akash version $version"
if [ -z "$(which yq)" ]; then
echo "Missing dependency yq needed for parsing return data - install this with `pip install yq`" >&2
exit 1
fi
# select a wallet to use
keys_list=$(akash keys list)
wallet_count=$(yq -r '. | length' <<< "$keys_list")
if [ "$wallet_count" = 0 ]; then
echo "No akash wallets found - please create a wallet first. See https://docs.akash.network/guides/wallet" >&2
exit 1
elif [ "$wallet_count" = 1 ]; then
# there is only one wallet, so select it without prompting
wallet_selected=0
else
# multiple wallets exist, so prompt the user which they want to use
echo "Multiple wallets found:"
for i in $(seq 0 "$((wallet_count - 1))"); do
name=$(yq -r ".[$i].name" <<< "$keys_list")
echo "$i: $name"
done
read -p "Enter number of wallet to use: " wallet_selected
fi
if [ -z "$wallet_selected" ]; then
wallet_selected=0
fi
wallet_name=$(yq -r ".[$wallet_selected].name" <<< "$keys_list")
wallet_address=$(yq -r ".[$wallet_selected].address" <<< "$keys_list")
if [ -z "$wallet_address" ] || [ "$wallet_address" = "null" ]; then
echo "Unable to find address of wallet $wallet_selected - check your wallet status with `akash keys list`" >&2
exit 1
fi
echo "Using wallet $wallet_name, address $wallet_address"
# select a node for these transactions
nodes=$(curl -s "$AKASH_NET/rpc-nodes.txt")
if [ -z "$nodes" ]; then
echo "Could not find node list at $AKASH_NET/rpc-nodes.txt!" >&2
exit 1
fi
chain_id=$(curl -s "$AKASH_NET/chain-id.txt")
if [ -z "$chain_id" ]; then
echo "Could not find node list at $AKASH_NET/chain-id.txt!" >&2
exit 1
fi
echo "Chain ID: $chain_id"
node=$(head -1 <<< "$nodes")
if $node_by_ping; then
lowest_ping=10000
for rpc in $nodes; do
hostname=$(cut -d '/' -f 3- <<< "$rpc" | cut -d ':' -f 1)
ping=$(ping -c1 "$hostname" | grep ^rtt | cut -d '/' -f 5)
if (( $(bc -l <<< "$ping < $lowest_ping") )); then
lowest_ping="$ping"
node="$rpc"
fi
done
echo "Selected node $node with lowest ping ${lowest_ping}ms"
else
echo "Selected default node $node"
fi
function akash_tx {
# wrapper function to send a transaction
$debug && echo "DEBUG: sending: akash tx $@ --from \"$wallet_address\" --node \"$node\" --chain-id \"$chain_id\" --fees \"$fees\" --broadcast-mode sync -y" >&2
akash tx "$@" --from "$wallet_address" --node "$node" --chain-id "$chain_id" --fees "$fees" --gas "$gaslimit" --broadcast-mode sync -y
}
function akash_query {
# wrapper function to query our orders, deployments etc
$debug && echo "DEBUG: sending: akash query $@ --owner \"$wallet_address\" --node \"$node\"" >&2
akash query "$@" --owner "$wallet_address" --node "$node"
}
echo "Looking for our latest order..."
order_result=$(akash_query market order list)
if [ -z "$order_result" ]; then
echo "Empty result from akash query market order list. Something is wrong with the remote RPC node." >&2
exit 1
fi
orders=$(yq -r ".orders" <<< "$order_result")
if [ -z "$orders" ]; then
echo "Error - no meaningful result from akash query market order list. Result: $order_result" >&2
exit 1
fi
order_last=$(yq -r ". | length" <<< "$orders")
newest_order=$(yq -r ".[$((orders_after - 1))]" <<< "$orders")
if [ -z "$newest_order" ]; then
echo "Could not get the latest order - something has gone wrong. Full order list: " >&2
yq "." <<< "$orders" >&2
exit 1
fi
dseq=$(yq -r ".order_id.dseq" <<< "$newest_order")
if [ -z "$dseq" ]; then
echo "Could not get dseq from new order - something has gone wrong. Full order: " >&2
yq "." <<< "$new_order" >&2
exit 1
fi
echo "Requesting close of deployment..."
$dry_run || akash_tx deployment close --dseq "$dseq"
echo "Done."