LN #11 - commando, lnsocket and CLN 23.08 rc1
Do you know that any application that you can connect to your CLN node can run authorized commands on your node?
This is possible thanks to commando builtin plugin and runes restriction tokens.
Let's take an example.
Let's assume:
- we are running a CLN node locally on port 7171 (
localhost:7171) and - our node id is
02ceb05d945017b6be076cfdb64e1015bc4ef80bbc27e79d89d4180e836b2cfb1d.
To authorized an application to run only the bookkeeper commands prefixed by bkpr- we generate a rune for that application like this:
$ lightning-cli commando-rune null '[["method^bkpr-"]]'
{
"rune": "DgyVcuTm3hcqmeDoyZ3xNpwfeq8MaxniCRFpUnEHFko9MCZtZXRob2ReYmtwci0=",
"unique_id": "0"
}
Then we can write the command line application bkpr.go in Go which prints out bkpr-listbalances information. To do so we use lnsocket Go library like this (note that we've hard coded the node information and the rune):
package main
import (
"fmt"
lnsocket "github.com/jb55/lnsocket/go"
"github.com/tidwall/gjson"
)
func main() {
nodeid := "02ceb05d945017b6be076cfdb64e1015bc4ef80bbc27e79d89d4180e836b2cfb1d"
hostname := "localhost:7171"
rune := "DgyVcuTm3hcqmeDoyZ3xNpwfeq8MaxniCRFpUnEHFko9MCZtZXRob2ReYmtwci0="
ln := lnsocket.LNSocket{}
ln.GenKey()
ln.ConnectAndInit(hostname, nodeid)
body, _ := ln.Rpc(rune, "bkpr-listbalances", "[]")
bkprListbalances := gjson.Get(body, "result").String()
fmt.Println(bkprListbalances)
}
Finally we install the dependencies and run bkpr.go app like this (assuming our node has no onchain funds neither any channel opened):
$ go mod init bkpr
$ go mod tidy
$ go run bkpr.go
{"accounts":[{"account":"wallet","balances":[{"balance_msat":0,"coin_type":"bcrt"}]}]}
This is the power of commando!
If you want to know more about it you can check the last two live coding sessions:
- Introduction to commando and commando-rune,
- Simple CLN bookkeeper web app powered by lnsocket & Golang - part 1.
If you like podcasts here they are 3 that I've recently listened to:
- The Power of Lightning Summit 2023: Every Company is a Lightning Company with Bobby Shell VP of Marketing at Voltage,
- Lisa Neigut and Dusty Dettmer talk about some CLN PRs merged in CLN 23.08 rc1,
- Rusty Russell - Privacy and Robustness in Lightning in The Chaincode Podcast.
Maybe you'll like them!
Have a nice day, see you next time.