forked from blckbx/NodeTools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanchor_check.sh
137 lines (115 loc) · 4.04 KB
/
anchor_check.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
#!/bin/bash
# Help text
help_text="
NAME:
bash anchor_check.sh - Get information on your peer's fee-commitments
USAGE:
bash anchor_check.sh [command options]
DESCRIPTION:
shows all your channel peers anchor commit fee-rate in ascending order.
OPTIONS:
--peer value"$'\t\t'"limit to only one specific pubkey
--limit value"$'\t'"Show commitment-fee below specific limit
--type string"$'\t\t'"filter by 'anchors' or 'static' output only
--umbrel"$'\t\t'"adjust lncli since ☂️ needs a different command call
-h, --help"$'\t\t'"Show this help message
"
# Check for --help option
if [[ $1 == "--help" || $1 == "-h" ]]; then
echo "$help_text"
exit 0
fi
# Check if both --type and --filter options are provided
if [[ "$*" =~ "--type" && "$*" =~ "--limit" ]]; then
echo "Error: Only one of --type or --limit can be used at a time."
exit 1
fi
# Set the anchor_list variable based on --umbrel option
if [[ $# -eq 1 && $1 == "--umbrel" ]]; then
anchor_list="/home/umbrel/umbrel/scripts/app compose lightning exec -T lnd lncli"
else
anchor_list="/usr/local/bin/lncli"
fi
get_channel_info() {
local CHANNEL_INFO=$1
local line=$2
ALIAS=$(echo "$CHANNEL_INFO" | jq -r '.peer_alias')
FEE_PER_KW=$(echo "$CHANNEL_INFO" | jq -r '.fee_per_kw')
ANCHOR=$(echo "$CHANNEL_INFO" | jq -r '.commitment_type')
if [[ "$ANCHOR" == "ANCHORS" ]]; then
ANCHOR="⚓Anchors"
elif [[ "$ANCHOR" == "STATIC_REMOTE_KEY" ]]; then
ANCHOR="⚠️ Static"
else
ANCHOR="🥪??"
fi
}
# Check if --peer option is provided
if [[ $1 == "--peer" ]]; then
PEER=$2
LIMIT=$3
# Fetch channel information for the specified pubkey
CHANNEL_INFO=$($anchor_list listchannels --peer "$PEER" | jq -r '.channels[0]')
# Check if channel information is available
if [ -z "$CHANNEL_INFO" ]; then
echo "Invalid node pubkey or no channels found: $PEER"
exit 1
fi
PUBKEY=$PEER
get_channel_info "$CHANNEL_INFO" "$line"
# Calculate the sat_vbyte value
SAT_VBYTE=$((FEE_PER_KW * 4 / 1000))
# Print SAT_VBYTE value
echo "$ANCHOR $SAT_VBYTE sat/vb "$'\t'" $ALIAS ($PUBKEY)"
else
# Check if --type option is provided
if [[ $1 == "--type" ]]; then
if [[ $2 == "anchors" ]]; then
TYPE="ANCHORS"
elif [[ $2 == "static" ]]; then
TYPE="STATIC_REMOTE_KEY"
else
echo "Invalid type: $2. Valid types are 'anchors' or 'static'."
exit 1
fi
LIMIT=$3
else
# If --limit is provided, set the limit
LIMIT=$2
fi
# Fetch and parse channel information
CHANNELS=$($anchor_list listchannels | jq -c '.channels | sort_by(.fee_per_kw | tonumber)[]')
# Loop through each channel and extract the pubkey and fee_per_kw values
echo "$CHANNELS" | while read -r line; do
# Extract the fee_per_kw, remote_pubkey, and peer_alias values
FEE_PER_KW=$(echo "$line" | jq -r '.fee_per_kw')
PUBKEY=$(echo "$line" | jq -r '.remote_pubkey')
ALIAS=$(echo "$line" | jq -r '.peer_alias')
ANCHOR=$(echo "$line" | jq -r '.commitment_type')
if [[ -n "$TYPE" && "$ANCHOR" != "$TYPE" ]]; then
continue
fi
# Emoji setting for $line
if [[ "$ANCHOR" == "ANCHORS" ]]; then
ANCHOR_EMOJI="⚓Anchors"
elif [[ "$ANCHOR" == "STATIC_REMOTE_KEY" ]]; then
ANCHOR_EMOJI="⚠️ Static"
else
ANCHOR_EMOJI="🥪"
fi
# Calculate the sat_vbyte value
SAT_VBYTE=$((FEE_PER_KW * 4 / 1000))
if [[ -z "$LIMIT" ]]; then
# LIMIT is empty, print everything
echo "$ANCHOR_EMOJI $SAT_VBYTE sat/vb "$'\t'" $ALIAS ($PUBKEY)"
else
# LIMIT is not empty, proceed with filtering
if [ "$SAT_VBYTE" -lt "$LIMIT" ]; then
# Print everything below filter limit
echo "$ANCHOR_EMOJI $SAT_VBYTE sat/vb "$'\t'" $ALIAS ($PUBKEY)"
else
break
fi
fi
done
fi