mirror of
https://github.com/callebtc/electronwall.git
synced 2026-02-01 05:14:52 +01:00
config
This commit is contained in:
@@ -11,4 +11,4 @@ go build .
|
||||
```
|
||||
|
||||
## Config
|
||||
Edit `config.yaml`
|
||||
Edit `config.yaml.example` and rename to `config.yaml`.
|
||||
|
||||
16
config.go
16
config.go
@@ -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]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
15
main.go
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user