Support config

pull/1/head
rkfg 2 years ago
parent 1ce3c14e3f
commit 652c186cf0

@ -2,6 +2,7 @@ package main
import (
"context"
"encoding/json"
"log"
"math/rand"
"os"
@ -13,18 +14,22 @@ import (
"github.com/lightningnetwork/lnd/lnrpc/routerrpc"
)
var mainParams struct {
Config string `short:"f" long:"config" description:"config file path"`
}
var params struct {
Connect string `short:"c" long:"connect" description:"connect to lnd using host:port" default:"127.0.0.1:10009"`
TLSCert string `short:"t" long:"tlscert" description:"path to tls.cert to connect" required:"false"`
MacaroonDir string `long:"macaroon.dir" description:"path to the macaroon directory" required:"false"`
MacaroonFilename string `long:"macaroon.filename" description:"macaroon filename" default:"admin.macaroon"`
Network string `short:"n" long:"network" description:"bitcoin network to use" default:"mainnet"`
FromPerc int64 `long:"pfrom" description:"channels with less than this inbound liquidity percentage will be considered as source channels" default:"50"`
ToPerc int64 `long:"pto" description:"channels with less than this outbound liquidity percentage will be considered as target channels" default:"50"`
Perc int64 `short:"p" long:"perc" description:"use this value as both pfrom and pto from above" default:"0"`
Amount int64 `short:"a" long:"amount" description:"amount to rebalance" default:"0"`
EconRatio float64 `long:"econ-ratio" description:"economical ratio for fee limit calculation as a multiple of target channel fee (for example, 0.5 means you want to pay at max half the fee you might earn for routing out of the target channel)" default:"1"`
ProbeSteps int `short:"b" long:"probe" description:"if the payment fails at the last hop try to probe lower amount using binary search" default:"0"`
Connect string `short:"c" long:"connect" description:"connect to lnd using host:port" json:"connect"`
TLSCert string `short:"t" long:"tlscert" description:"path to tls.cert to connect" required:"false" json:"tlscert"`
MacaroonDir string `long:"macaroon.dir" description:"path to the macaroon directory" required:"false" json:"macaroon.dir"`
MacaroonFilename string `long:"macaroon.filename" description:"macaroon filename" json:"macaroon.filename"`
Network string `short:"n" long:"network" description:"bitcoin network to use" json:"network"`
FromPerc int64 `long:"pfrom" description:"channels with less than this inbound liquidity percentage will be considered as source channels" json:"pfrom"`
ToPerc int64 `long:"pto" description:"channels with less than this outbound liquidity percentage will be considered as target channels" json:"pto"`
Perc int64 `short:"p" long:"perc" description:"use this value as both pfrom and pto from above" json:"perc"`
Amount int64 `short:"a" long:"amount" description:"amount to rebalance" json:"amount"`
EconRatio float64 `long:"econ-ratio" description:"economical ratio for fee limit calculation as a multiple of target channel fee (for example, 0.5 means you want to pay at max half the fee you might earn for routing out of the target channel)" json:"econ_ratio"`
ProbeSteps int `short:"b" long:"probe" description:"if the payment fails at the last hop try to probe lower amount using binary search" json:"probe_steps"`
}
type regolancer struct {
@ -38,12 +43,45 @@ type regolancer struct {
chanCache map[uint64]*lnrpc.ChannelEdge
}
func loadConfig() {
flags.Parse(&mainParams)
if mainParams.Config == "" {
return
}
f, err := os.Open(mainParams.Config)
if err != nil {
log.Fatalf("Error opening config file %s: %s", mainParams.Config, err)
} else {
defer f.Close()
err = json.NewDecoder(f).Decode(&params)
if err != nil {
log.Fatalf("Error reading config file %s: %s", mainParams.Config, err)
}
}
}
func main() {
_, err := flags.Parse(&params)
rand.Seed(time.Now().UnixNano())
loadConfig()
_, err := flags.NewParser(&params, flags.Default|flags.IgnoreUnknown).Parse()
if err != nil {
os.Exit(1)
}
rand.Seed(time.Now().UnixNano())
if params.Connect == "" {
params.Connect = "127.0.0.1:10009"
}
if params.MacaroonFilename == "" {
params.MacaroonFilename = "admin.macaroon"
}
if params.FromPerc == 0 {
params.FromPerc = 50
}
if params.ToPerc == 0 {
params.ToPerc = 50
}
if params.EconRatio == 0 {
params.EconRatio = 1
}
if params.Perc > 0 {
params.FromPerc = params.Perc
params.ToPerc = params.Perc

Loading…
Cancel
Save