Merge pull request #1 from ziggie1984/toml_support

pull/11/head
rkfg 2 years ago committed by GitHub
commit 974e938313
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,38 @@
connect = "192.168.178.22"
macaroon_dir = "."
macaroon_filename = "admin.macaroon"
"network"= "mainnet"
"tlscert"= "./tls.cert"
"econ_ratio"= 0.4
"amount"= 100000
"min_amount"= 50000
"probe_steps"= 5
"pfrom"= 40
"pto"= 40
"stat"= "stats.csv"
"exclude_channels_in"= [
# River Financial
821913529170526209,
#southxchange
821280210377179136
]
"exclude_channels_out"= [
#nicehash
794863344113680384,
#bfx-lnd1
817004209683890177,
#HOPPINGSQUIRREL
806323553821196289
]
"exclude_channels"= [
#Kraken
830099393243185153
]
"exclude_nodes"= [
#hash.stream
"0363749dbdb99321177082935bf7c36978fc46c725c5c452d48d721ab31e7682c2",
#Boltz
"026165850492521f4ac8abd9bd8088123446d126f648ca35e60f88177dc149ceb2"
]

@ -3,6 +3,7 @@ module github.com/rkfg/regolancer
go 1.18
require (
github.com/BurntSushi/toml v0.3.1
github.com/fatih/color v1.13.0
github.com/jessevdk/go-flags v1.5.0
github.com/lightninglabs/lndclient v0.15.1-0

@ -6,8 +6,10 @@ import (
"log"
"math/rand"
"os"
"strings"
"time"
"github.com/BurntSushi/toml"
"github.com/jessevdk/go-flags"
"github.com/lightninglabs/lndclient"
"github.com/lightningnetwork/lnd/lnrpc"
@ -22,23 +24,23 @@ var params struct {
Config string `short:"f" long:"config" description:"config file path"`
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"`
MacaroonDir string `long:"macaroon-dir" description:"path to the macaroon directory" required:"false" json:"macaroon_dir" toml:"macaroon_dir"`
MacaroonFilename string `long:"macaroon-filename" description:"macaroon filename" json:"macaroon_filename" toml:"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"`
FromPerc int64 `long:"pfrom" description:"channels with less than this inbound liquidity percentage will be considered as source channels" json:"pfrom" toml:"pfrom"`
ToPerc int64 `long:"pto" description:"channels with less than this outbound liquidity percentage will be considered as target channels" json:"pto" toml:"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 `short:"r" 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-steps" description:"if the payment fails at the last hop try to probe lower amount using this many steps" json:"probe_steps"`
MinAmount int64 `long:"min-amount" description:"if probing is enabled this will be the minimum amount to try" json:"min_amount"`
ExcludeChannelsIn []uint64 `short:"i" long:"exclude-channel-in" description:"don't use this channel as incoming (can be specified multiple times)" json:"exclude_channels_in"`
ExcludeChannelsOut []uint64 `short:"o" long:"exclude-channel-out" description:"don't use this channel as outgoing (can be specified multiple times)" json:"exclude_channels_out"`
ExcludeChannels []uint64 `short:"e" long:"exclude-channel" description:"don't use this channel at all (can be specified multiple times)" json:"exclude_channels"`
ExcludeNodes []string `short:"d" long:"exclude-node" description:"don't use this node for routing (can be specified multiple times)" json:"exclude_nodes"`
ToChannel uint64 `long:"to" description:"try only this channel as target (should satisfy other constraints too)" json:"to"`
FromChannel uint64 `long:"from" description:"try only this channel as source (should satisfy other constraints too)" json:"from"`
StatFilename string `short:"s" long:"stat" description:"save successful rebalance information to the specified CSV file" json:"stat"`
EconRatio float64 `short:"r" 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" toml:"econ_ratio"`
ProbeSteps int `short:"b" long:"probe-steps" description:"if the payment fails at the last hop try to probe lower amount using this many steps" json:"probe_steps" toml:"probe_steps"`
MinAmount int64 `long:"min-amount" description:"if probing is enabled this will be the minimum amount to try" json:"min_amount" toml:"min_amount"`
ExcludeChannelsIn []uint64 `short:"i" long:"exclude-channel-in" description:"don't use this channel as incoming (can be specified multiple times)" json:"exclude_channels_in" toml:"exclude_channels_in"`
ExcludeChannelsOut []uint64 `short:"o" long:"exclude-channel-out" description:"don't use this channel as outgoing (can be specified multiple times)" json:"exclude_channels_out" toml:"exclude_channels_out"`
ExcludeChannels []uint64 `short:"e" long:"exclude-channel" description:"don't use this channel at all (can be specified multiple times)" json:"exclude_channels" toml:"exclude_channels"`
ExcludeNodes []string `short:"d" long:"exclude-node" description:"don't use this node for routing (can be specified multiple times)" json:"exclude_nodes" toml:"exclude_nodes"`
ToChannel uint64 `long:"to" description:"try only this channel as target (should satisfy other constraints too)" json:"to" toml:"to"`
FromChannel uint64 `long:"from" description:"try only this channel as source (should satisfy other constraints too)" json:"from" toml:"from"`
StatFilename string `short:"s" long:"stat" description:"save successful rebalance information to the specified CSV file" json:"stat" toml:"stat"`
}
type failedRoute struct {
@ -69,17 +71,26 @@ type regolancer struct {
func loadConfig() {
flags.NewParser(&mainParams, flags.PrintErrors|flags.IgnoreUnknown).Parse()
if mainParams.Config == "" {
return
}
f, err := os.Open(mainParams.Config)
if err != nil {
log.Fatalf("Error opening config file %s: %s", mainParams.Config, err)
if strings.Contains(mainParams.Config, ".toml") {
_, err := toml.DecodeFile(mainParams.Config, &params)
if err != nil {
log.Fatalf("Error opening config file %s: %s", mainParams.Config, err)
}
} else {
defer f.Close()
err = json.NewDecoder(f).Decode(&params)
f, err := os.Open(mainParams.Config)
if err != nil {
log.Fatalf("Error reading config file %s: %s", mainParams.Config, err)
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)
}
}
}
}

Loading…
Cancel
Save