This commit is contained in:
callebtc
2022-05-28 12:13:44 +02:00
parent e47049ebe6
commit 6921cd4b2d
4 changed files with 25 additions and 9 deletions

View File

@@ -11,4 +11,4 @@ go build .
```
## Config
Edit `config.yaml`
Edit `config.yaml.example` and rename to `config.yaml`.

View File

@@ -4,13 +4,15 @@ import (
"fmt"
"github.com/jinzhu/configor"
log "github.com/sirupsen/logrus"
)
var Configuration = struct {
Host string `yaml:"host"`
MacaroonPath string `yaml:"macaroon_path"`
TLSPath string `yaml:"tls_path"`
Accept []string `yaml:"accept"`
Host string `yaml:"host"`
MacaroonPath string `yaml:"macaroon_path"`
TLSPath string `yaml:"tls_path"`
Accept []string `yaml:"accept"`
RejectMessage string `yaml:"reject_message"`
}{}
func init() {
@@ -25,7 +27,13 @@ func checkConfig() {
if Configuration.Host == "" {
panic(fmt.Errorf("no host specified in config.yaml"))
}
if len(Configuration.Accept) == 0 {
panic(fmt.Errorf("no accepted pubkeys specified in config.yaml"))
}
if len(Configuration.RejectMessage) > 500 {
log.Warnf("reject message is too long. Trimming to 500 characters.")
Configuration.RejectMessage = Configuration.RejectMessage[:500]
}
}

View File

@@ -1,6 +1,7 @@
host: "127.0.0.1:10009"
macaroon_path: "/home/bitcoin/.lnd/data/chain/bitcoin/regtest/admin.macaroon"
tls_path: "/home/bitcoin/.lnd/tls.cert"
reject_message: "Contact me at user@email.com to be added to the white list."
accept:
- "03de70865239e99460041e127647b37101b9eb335b3c22de95c944671f0dabc2d0"
- "0307299a290529c5ccb3a5e3bd2eb504daf64cc65c6d65b582c01cbd7e5ede14b6"

15
main.go
View File

@@ -3,6 +3,7 @@ package main
import (
"context"
"encoding/hex"
"fmt"
"io/ioutil"
"github.com/lightningnetwork/lnd/lnrpc"
@@ -45,6 +46,11 @@ func getClientConnection(ctx context.Context) (*grpc.ClientConn, error) {
return conn, nil
}
func trimPubKey(pubkey []byte) string {
return fmt.Sprintf("%s...%s", hex.EncodeToString(pubkey)[:6], hex.EncodeToString(pubkey)[len(hex.EncodeToString(pubkey))-6:])
}
func main() {
conn, err := getClientConnection(context.Background())
if err != nil {
@@ -55,7 +61,7 @@ func main() {
if err != nil {
panic(err)
}
log.Infof("Listening for incoming channel requests...")
log.Infof("Listening for incoming channel requests")
for {
req := lnrpc.ChannelAcceptRequest{}
err = acceptClient.RecvMsg(&req)
@@ -74,7 +80,7 @@ func main() {
res := lnrpc.ChannelAcceptResponse{}
if accept {
log.Infof("Accepting channel request from %s", hex.EncodeToString(req.NodePubkey))
log.Infof("Accepting channel request from %s", trimPubKey(req.NodePubkey))
res = lnrpc.ChannelAcceptResponse{Accept: true,
PendingChanId: req.PendingChanId,
CsvDelay: req.CsvDelay,
@@ -85,8 +91,9 @@ func main() {
}
} else {
log.Infof("Rejecting channel request from %s", hex.EncodeToString(req.NodePubkey))
res = lnrpc.ChannelAcceptResponse{Accept: false}
log.Infof("Rejecting channel request from %s", trimPubKey(req.NodePubkey))
res = lnrpc.ChannelAcceptResponse{Accept: false,
Error: Configuration.RejectMessage}
}
err = acceptClient.Send(&res)
if err != nil {