I am not responsible, directly or indirectly for the loss of funds using these commands. Use at your own risk.
Channels with received satoshis
alias lrecv="lncli listchannels | jq '[ .channels | .[] | select(.total_satoshis_received|tonumber>0) ]'"
Channels with offchain transactions
alias loffchain="lncli listchannels | jq '[ .channels | .[] | select(.num_updates|tonumber>0) ]'"
Lots of info plus distribution_pct, a representation of the balance of your channels
alias lchaninfo="lncli listchannels | jq '[ .channels | .[] | { \"remote_pubkey\": .remote_pubkey, \"capacity\": .capacity|tonumber, \"local_balance\": .local_balance|tonumber, \"remote_balance\": .remote_balance|tonumber, \"distribution_pct\": ( ( .local_balance|tonumber ) / ( (.remote_balance|tonumber ) + ( .local_balance|tonumber ) ) ), \"total_satoshis_sent\": .total_satoshis_sent|tonumber, \"total_satoshis_received\": .total_satoshis_received|tonumber } ]'"
Show just channel distributions
alias ldist="lncli listchannels | jq '[ .channels | .[] | { \"remote_pubkey\": .remote_pubkey, \"capacity\": .capacity, \"distribution_pct\": ( ( .local_balance|tonumber ) / ( (.remote_balance|tonumber ) + ( .local_balance|tonumber ) ) ) } ]'"
Show channels with unsettled balances
alias lunsettled="lncli listchannels | jq '[ .channels | .[] | select(.unsettled_balance|tonumber>0) ]'"
Total capacity of all channels
alias ltotalcap="lncli listchannels | jq '.channels | map(.capacity|tonumber) | add'"
Total remote balance of all channels
alias lremotebal="lncli listchannels | jq '.channels | map(.remote_balance|tonumber) | add'"
alias lunsettledbal="lncli listchannels | jq '.channels | map(.unsettled_balance|tonumber) | add'"
alias lsentbal="lncli listchannels | jq '.channels | map(.total_satoshis_sent|tonumber) | add'"
alias lreceivedbal="lncli listchannels | jq '.channels | map(.total_satoshis_received|tonumber) | add'"
Total number of offchain channel updates
alias loffchainupdates="lncli listchannels | jq '.channels | map(.num_updates|tonumber) | add'"
Number of active channels
alias lactive="lncli listchannels | jq '[ .channels | .[] | select(.active==true) ] | length'"
Number of inactive channels
alias linactive="lncli listchannels | jq '[ .channels | .[] | select(.active==false) ] | length'"
alias llimbo="lncli pendingchannels | jq '.total_limbo_balance|tonumber'"
alias lpendingo="lncli pendingchannels | jq '.pending_open_channels|length'"
alias lpendingc="lncli pendingchannels | jq '.pending_close_channels|length'"
alias lpendingf="lncli pendingchannels | jq '.pending_force_closing_channels|length'"
alias ltopchannels="lncli describegraph | jq '[ .edges | sort_by(.capacity|tonumber) | reverse | .[] | { \"node1_pub\": .node1_pub, \"node2_pub\": .node2_pub, \"Capacity\": .capacity|tonumber, } ]'"
alias ltopchannels="lncli describegraph | jq '[ .edges | sort_by(.capacity|tonumber) | reverse | .[] | { \"node1_pub\": .node1_pub, \"node2_pub\": .node2_pub, \"Capacity\": .capacity|tonumber, } ]'"
channels that haven't been used for sending or receiving payments
alias lunusedchannels='lncli listchannels | jq '\''[ .channels[] | select(.total_satoshis_sent=="0" and .total_satoshis_received=="0") ]| {"unused channels": map({"channel_point": .channel_point, "local_balance": .local_balance|tonumber, "num_updates": .num_updates|tonumber, "active": .active, "private": .private}) | sort_by(.local_balance) | reverse }'\'''
get the node info for all nodes that have channels with us
alias lnodeinfo='lncli listchannels | jq -r '''.channels[].remote_pubkey' | while read p; do lncli getnodeinfo "$p"; done'''
get the total connected capacity of a specific node pubkey
lremotecap() { if [ -z $1 ]; then "specify remote node pubkey"; else lncli describegraph | jq --arg node $1 '[ .edges[] | select(.node1_pub==$node or .node2_pub==$node) ] | map(.capacity|tonumber) | add | { "capacity" : . }'; fi }
See channel caps of all known nodes
NOT WORKING AT THE MOMENT
alias lchannelcaps="lncli describegraph | jq '.nodes[].total_channel_capacities=0 | foreach .nodes[] as $node ( . ; foreach .edges[] as $edge ( . ; if $edge.node1_pub==$node.pub_key then ($node|.total_channel_capacities=.total_channel_capacity+($edge.capacity|tonumber)) else empty end ; .) ; . )'"
see the best route for a particular pubkey and amount
lbestroute() { if [ -z $1 ]; then echo "need pubkey+amt"; else lncli queryroutes $1 $2 | jq 'routes[0]'; fi; }
see the shortest distance to a particular node for a particular amount
ldistance() { if [ -z $1 ]; then echo "need pubkey+amt"; else lncli queryroutes $1 $2 | jq '[ .routes[].hops | length ] | min'; fi; }
see the furthest node from you (takes a long time to run)
lfurthest() { if [ -z $1 ]; then echo "need an amount"; else lncli describegraph | jq '.nodes[].pub_key' | while read p; do echo -en "$p: "; ldistance ${p//\"} $1; done; fi; }
alias lforcegraph='lncli describegraph | jq -c '\''{ "nodes": .nodes | map({ "id": .pub_key, "alias": .alias|match("[^\u0000]+")| .string, "group": 1, "color": .color, "addresses": .addresses }), "links": .edges | map({"source": .node1_pub, "target": .node2_pub, "capacity": .capacity|tonumber }) }'\'
forwarding history with human readable timestamps
alias lfwdinghistory='lncli fwdinghistory --start_time=1 --end_time=$(date +%s) | jq '\''.forwarding_events[].timestamp |= (. | tonumber | strftime("%F %T")) | .event_count = (.forwarding_events | length) | .forwarding_events[].amt_in |= (. | tonumber) | .forwarding_events[].amt_out |= (. | tonumber)'\'
These are commands which PERFORM OPERATIONS ON YOUR NODE. Use with caution. I am not responsible for any loss of funds resulting from the use of these or any commands.
attempt to cooperatively close all channels with a specific node
lcloseall() { if [ -z $1 ]; then echo "specify remote node pubkey"; else lncli listchannels | jq -r --arg pubkey $1 '.channels[] | select(.remote_pubkey==$pubkey) | "\(.channel_point | .[0:64])"' | while read c; do lncli closechannel $c; done fi }
attempt to force close all channels with a specific node
lforcecloseall() { if [ -z $1 ]; then echo "specify remote node pubkey"; else lncli listchannels | jq -r --arg pubkey $1 '.channels[] | select(.remote_pubkey==$pubkey) | .channel_point' | while read c; do lncli closechannel --force ${c%:*} ${c/*:/}; done fi }
fails:
works:
seem to be a few like this :)