From 271f870354d5bb0ff6105be78757595c4a72201a Mon Sep 17 00:00:00 2001
From: Impa10r
Date: Thu, 4 Jul 2024 20:41:54 +0200
Subject: [PATCH 01/13] Publish branch
---
CHANGELOG.md | 4 ++++
cmd/psweb/ln/lnd.go | 2 ++
cmd/psweb/main.go | 2 +-
3 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 160bd75..b71b25d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,9 @@
# Versions
+## 1.6.1
+
+- Fix forwards subscription to add channel IDs
+
## 1.6.0
- Make New Swap form inputs more intuitive
diff --git a/cmd/psweb/ln/lnd.go b/cmd/psweb/ln/lnd.go
index c579c3e..9f27014 100644
--- a/cmd/psweb/ln/lnd.go
+++ b/cmd/psweb/ln/lnd.go
@@ -944,6 +944,8 @@ func subscribeForwards(ctx context.Context, client routerrpc.RouterClient) error
forwardingEvent.AmtIn = info.IncomingAmtMsat / 1000
forwardingEvent.AmtOut = info.OutgoingAmtMsat / 1000
forwardingEvent.TimestampNs = htlcEvent.TimestampNs
+ forwardingEvent.ChanIdIn = htlcEvent.IncomingChannelId
+ forwardingEvent.ChanIdOut = htlcEvent.OutgoingChannelId
htlc.forwardingEvent = forwardingEvent
diff --git a/cmd/psweb/main.go b/cmd/psweb/main.go
index 8c75db4..f5a3d53 100644
--- a/cmd/psweb/main.go
+++ b/cmd/psweb/main.go
@@ -35,7 +35,7 @@ import (
const (
// App version tag
- version = "v1.6.0"
+ version = "v1.6.1"
)
type SwapParams struct {
From 028611e2ede0fa3cbef1c103255e3665545bb137 Mon Sep 17 00:00:00 2001
From: Impa10r
Date: Thu, 4 Jul 2024 23:18:07 +0200
Subject: [PATCH 02/13] Fix fee
---
cmd/psweb/ln/lnd.go | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/cmd/psweb/ln/lnd.go b/cmd/psweb/ln/lnd.go
index 9f27014..33de390 100644
--- a/cmd/psweb/ln/lnd.go
+++ b/cmd/psweb/ln/lnd.go
@@ -939,6 +939,7 @@ func subscribeForwards(ctx context.Context, client routerrpc.RouterClient) error
forwardingEvent := new(lnrpc.ForwardingEvent)
forwardingEvent.FeeMsat = info.IncomingAmtMsat - info.OutgoingAmtMsat
+ forwardingEvent.Fee = forwardingEvent.FeeMsat / 1000
forwardingEvent.AmtInMsat = info.IncomingAmtMsat
forwardingEvent.AmtOutMsat = info.OutgoingAmtMsat
forwardingEvent.AmtIn = info.IncomingAmtMsat / 1000
@@ -1894,12 +1895,10 @@ func PlotPPM(channelId uint64) *[]DataPoint {
// ignore small forwards
if e.AmtOutMsat > ignoreForwardsMsat {
plot = append(plot, DataPoint{
- TS: e.TimestampNs / 1_000_000_000,
- Amount: e.AmtOut,
- Fee: e.Fee,
- PPM: e.FeeMsat * 1_000_000 / e.AmtOutMsat,
- ChanIdIn: e.ChanIdIn,
- ChanIdOut: e.ChanIdOut,
+ TS: e.TimestampNs / 1_000_000_000,
+ Amount: e.AmtOut,
+ Fee: e.Fee,
+ PPM: e.FeeMsat * 1_000_000 / e.AmtOutMsat,
})
}
}
From aeee4cc824bff65bd88b4bf878c0148b0cce64d6 Mon Sep 17 00:00:00 2001
From: Impa10r
Date: Thu, 4 Jul 2024 23:21:37 +0200
Subject: [PATCH 03/13] Fix rounding
---
cmd/psweb/utils.go | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/cmd/psweb/utils.go b/cmd/psweb/utils.go
index d22fba6..e8227df 100644
--- a/cmd/psweb/utils.go
+++ b/cmd/psweb/utils.go
@@ -144,13 +144,13 @@ func toMil(num uint64) string {
if num == 0 {
return "-"
}
- if num >= 10_000_000 {
+ if num >= 9_500_000 {
return fmt.Sprintf("%d", num/1_000_000) + "m"
}
- if num >= 100_000 {
+ if num >= 99_500 {
return fmt.Sprintf("%.1f", float32(num)/1_000_000) + "m"
}
- if num >= 1_000 {
+ if num >= 500 {
return fmt.Sprintf("%.1f", float32(num)/1_000) + "k"
}
return formatWithThousandSeparators(num)
From e3d3e370b9b4507a7bafa095254eb38865b080ee Mon Sep 17 00:00:00 2001
From: Impa10r
Date: Thu, 4 Jul 2024 23:37:05 +0200
Subject: [PATCH 04/13] Closed channel alias
---
cmd/psweb/main.go | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/cmd/psweb/main.go b/cmd/psweb/main.go
index f5a3d53..149e5aa 100644
--- a/cmd/psweb/main.go
+++ b/cmd/psweb/main.go
@@ -1107,6 +1107,10 @@ func getNodeAlias(key string) string {
return alias
}
+ if key == "" {
+ return ""
+ }
+
// try lightning
alias = ln.GetAlias(key)
From 7c2bc94b4b08412e3b71f9b04083481f60970595 Mon Sep 17 00:00:00 2001
From: Impa10r
Date: Thu, 4 Jul 2024 23:39:41 +0200
Subject: [PATCH 05/13] Change closed channel string
---
cmd/psweb/main.go | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/cmd/psweb/main.go b/cmd/psweb/main.go
index 149e5aa..d8f088c 100644
--- a/cmd/psweb/main.go
+++ b/cmd/psweb/main.go
@@ -1108,7 +1108,7 @@ func getNodeAlias(key string) string {
}
if key == "" {
- return ""
+ return "* closed channel *"
}
// try lightning
From 7a58f6bea66e622f07673fd4827ce009e2f4bbec Mon Sep 17 00:00:00 2001
From: Impa10r
Date: Thu, 4 Jul 2024 23:45:41 +0200
Subject: [PATCH 06/13] Show defaults for a closed channel id
---
cmd/psweb/handlers.go | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/cmd/psweb/handlers.go b/cmd/psweb/handlers.go
index ead7977..e70a24b 100644
--- a/cmd/psweb/handlers.go
+++ b/cmd/psweb/handlers.go
@@ -901,6 +901,11 @@ func afHandler(w http.ResponseWriter, r *http.Request) {
}
}
+ if peerId == "" {
+ // non-existing channel
+ channelId = 0
+ }
+
// sort by LocalPct ascending
sort.Slice(channelList, func(i, j int) bool {
return channelList[i].LocalPct < channelList[j].LocalPct
From 14176a0025c55b271f1a09ff019ef2ee8e8e9f05 Mon Sep 17 00:00:00 2001
From: Impa10r
Date: Fri, 5 Jul 2024 00:24:09 +0200
Subject: [PATCH 07/13] Show PPM in Forwards log
---
cmd/psweb/templates/af.gohtml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/cmd/psweb/templates/af.gohtml b/cmd/psweb/templates/af.gohtml
index 90437f4..fa5886e 100644
--- a/cmd/psweb/templates/af.gohtml
+++ b/cmd/psweb/templates/af.gohtml
@@ -275,7 +275,7 @@
In |
Out |
Amt |
- Fee |
+ PPM |
@@ -285,7 +285,7 @@
{{.AliasIn}} |
{{.AliasOut}} |
{{m .Amount}} |
- {{fmt .Fee}} |
+ {{fmt .PPM}} |
{{end}}
From 86207af6da9a2575daba05b2b0ad6ff3014d6f49 Mon Sep 17 00:00:00 2001
From: Impa10r
Date: Fri, 5 Jul 2024 00:46:59 +0200
Subject: [PATCH 08/13] Format fee with msats
---
cmd/psweb/handlers.go | 2 +-
cmd/psweb/ln/cln.go | 6 +++---
cmd/psweb/ln/common.go | 2 +-
cmd/psweb/ln/lnd.go | 6 +++---
cmd/psweb/main.go | 1 +
cmd/psweb/templates/af.gohtml | 2 +-
cmd/psweb/utils.go | 17 +++++++++++++++++
7 files changed, 27 insertions(+), 9 deletions(-)
diff --git a/cmd/psweb/handlers.go b/cmd/psweb/handlers.go
index e70a24b..53f1947 100644
--- a/cmd/psweb/handlers.go
+++ b/cmd/psweb/handlers.go
@@ -928,7 +928,7 @@ func afHandler(w http.ResponseWriter, r *http.Request) {
// bubble square area reflects amount
for i, p := range *chart {
(*chart)[i].R = uint64(math.Sqrt(float64(p.Amount) / 10_000))
- (*chart)[i].Label = "Routed: " + formatWithThousandSeparators(p.Amount) + ", Fee: " + formatWithThousandSeparators(p.Fee) + ", PPM: " + formatWithThousandSeparators(p.PPM)
+ (*chart)[i].Label = "Routed: " + formatWithThousandSeparators(p.Amount) + ", Fee: " + formatFloat(p.Fee) + ", PPM: " + formatWithThousandSeparators(p.PPM)
}
var feeLog []FeeLog
diff --git a/cmd/psweb/ln/cln.go b/cmd/psweb/ln/cln.go
index d6095d7..7b745ff 100644
--- a/cmd/psweb/ln/cln.go
+++ b/cmd/psweb/ln/cln.go
@@ -1223,7 +1223,7 @@ func PlotPPM(channelId uint64) *[]DataPoint {
plot = append(plot, DataPoint{
TS: uint64(e.ResolvedTime),
Amount: e.OutMsat / 1000,
- Fee: e.FeeMsat / 1000,
+ Fee: float64(e.FeeMsat) / 1000,
PPM: e.FeeMsat * 1_000_000 / e.OutMsat,
})
}
@@ -1246,7 +1246,7 @@ func ForwardsLog(channelId uint64, fromTS int64) *[]DataPoint {
log = append(log, DataPoint{
TS: uint64(e.ResolvedTime),
Amount: e.OutMsat / 1000,
- Fee: e.FeeMsat / 1000,
+ Fee: float64(e.FeeMsat) / 1000,
PPM: e.FeeMsat * 1_000_000 / e.OutMsat,
ChanIdIn: ConvertClnToLndChannelId(e.InChannel),
ChanIdOut: chId,
@@ -1262,7 +1262,7 @@ func ForwardsLog(channelId uint64, fromTS int64) *[]DataPoint {
log = append(log, DataPoint{
TS: uint64(e.ResolvedTime),
Amount: e.OutMsat / 1000,
- Fee: e.FeeMsat / 1000,
+ Fee: float64(e.FeeMsat) / 1000,
PPM: e.FeeMsat * 1_000_000 / e.OutMsat,
ChanIdIn: channelId,
ChanIdOut: ConvertClnToLndChannelId(e.OutChannel),
diff --git a/cmd/psweb/ln/common.go b/cmd/psweb/ln/common.go
index 0f8d42d..0eb1b9e 100644
--- a/cmd/psweb/ln/common.go
+++ b/cmd/psweb/ln/common.go
@@ -132,7 +132,7 @@ type AutoFeeEvent struct {
type DataPoint struct {
TS uint64
Amount uint64
- Fee uint64
+ Fee float64
PPM uint64
R uint64
Label string
diff --git a/cmd/psweb/ln/lnd.go b/cmd/psweb/ln/lnd.go
index 33de390..9635db0 100644
--- a/cmd/psweb/ln/lnd.go
+++ b/cmd/psweb/ln/lnd.go
@@ -1897,7 +1897,7 @@ func PlotPPM(channelId uint64) *[]DataPoint {
plot = append(plot, DataPoint{
TS: e.TimestampNs / 1_000_000_000,
Amount: e.AmtOut,
- Fee: e.Fee,
+ Fee: float64(e.FeeMsat) / 1000,
PPM: e.FeeMsat * 1_000_000 / e.AmtOutMsat,
})
}
@@ -1921,7 +1921,7 @@ func ForwardsLog(channelId uint64, fromTS int64) *[]DataPoint {
log = append(log, DataPoint{
TS: e.TimestampNs / 1_000_000_000,
Amount: e.AmtOut,
- Fee: e.Fee,
+ Fee: float64(e.FeeMsat) / 1000,
PPM: e.FeeMsat * 1_000_000 / e.AmtOutMsat,
ChanIdIn: e.ChanIdIn,
ChanIdOut: e.ChanIdOut,
@@ -1937,7 +1937,7 @@ func ForwardsLog(channelId uint64, fromTS int64) *[]DataPoint {
log = append(log, DataPoint{
TS: e.TimestampNs / 1_000_000_000,
Amount: e.AmtOut,
- Fee: e.Fee,
+ Fee: float64(e.FeeMsat) / 1000,
PPM: e.FeeMsat * 1_000_000 / e.AmtOutMsat,
ChanIdIn: e.ChanIdIn,
ChanIdOut: e.ChanIdOut,
diff --git a/cmd/psweb/main.go b/cmd/psweb/main.go
index d8f088c..b9d4a46 100644
--- a/cmd/psweb/main.go
+++ b/cmd/psweb/main.go
@@ -142,6 +142,7 @@ func main() {
"u": toUint,
"fmt": formatWithThousandSeparators,
"fs": formatSigned,
+ "ff": formatFloat,
"m": toMil,
"last": last,
}).
diff --git a/cmd/psweb/templates/af.gohtml b/cmd/psweb/templates/af.gohtml
index fa5886e..b6002e7 100644
--- a/cmd/psweb/templates/af.gohtml
+++ b/cmd/psweb/templates/af.gohtml
@@ -285,7 +285,7 @@
{{.AliasIn}} |
{{.AliasOut}} |
{{m .Amount}} |
- {{fmt .PPM}} |
+ {{fmt .PPM}} |
{{end}}
diff --git a/cmd/psweb/utils.go b/cmd/psweb/utils.go
index e8227df..e167739 100644
--- a/cmd/psweb/utils.go
+++ b/cmd/psweb/utils.go
@@ -2,8 +2,10 @@ package main
import (
"fmt"
+ "math"
"os"
"strconv"
+ "strings"
"time"
)
@@ -47,6 +49,21 @@ func stringIsInSlice(whatToFind string, whereToSearch []string) bool {
return false
}
+// formats 1234.567 as 1,234.567
+func formatFloat(number float64) string {
+ integerPart := uint64(math.Trunc(number))
+ decimalPart := number - float64(integerPart)
+
+ // Format the integer part with commas
+ formattedIntegerPart := formatWithThousandSeparators(uint64(integerPart))
+
+ if decimalPart == 0 {
+ return formattedIntegerPart
+ } else {
+ return formattedIntegerPart + strings.TrimPrefix(fmt.Sprintf("%.3f", decimalPart), "0")
+ }
+}
+
// formats 100000 as 100,000
func formatWithThousandSeparators(n uint64) string {
if n == 0 {
From 38767178b13aa2ba74211b33cddb6b1249d9accc Mon Sep 17 00:00:00 2001
From: Impa10r
Date: Fri, 5 Jul 2024 00:52:24 +0200
Subject: [PATCH 09/13] Format with commas
---
cmd/psweb/handlers.go | 8 ++++----
cmd/psweb/templates/af.gohtml | 8 ++++----
2 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/cmd/psweb/handlers.go b/cmd/psweb/handlers.go
index 53f1947..0afe928 100644
--- a/cmd/psweb/handlers.go
+++ b/cmd/psweb/handlers.go
@@ -810,8 +810,8 @@ type FeeLog struct {
TimeStamp int64
TimeUTC string
TimeAgo string
- OldRate int
- NewRate int
+ OldRate int64
+ NewRate int64
IsInbound bool
IsManual bool
}
@@ -953,8 +953,8 @@ func afHandler(w http.ResponseWriter, r *http.Request) {
TimeAgo: timeAgo,
Alias: getNodeAlias(peerNodeId[id]),
ChannelId: id,
- OldRate: event.OldRate,
- NewRate: event.NewRate,
+ OldRate: int64(event.OldRate),
+ NewRate: int64(event.NewRate),
IsInbound: event.IsInbound,
IsManual: event.IsManual,
})
diff --git a/cmd/psweb/templates/af.gohtml b/cmd/psweb/templates/af.gohtml
index b6002e7..ee14a78 100644
--- a/cmd/psweb/templates/af.gohtml
+++ b/cmd/psweb/templates/af.gohtml
@@ -239,8 +239,8 @@
Time |
Peer |
- Old |
- New |
+ Old |
+ New |
D |
S |
@@ -250,7 +250,7 @@
{{.TimeAgo}} |
{{.Alias}} |
- {{.OldRate}} |
+ {{fs .OldRate}} |
- {{.NewRate}} |
+ {{fs .NewRate}}
I{{else}} title="Outbound">O{{end}} |
M{{else}} title="Auto">A{{end}} |
From 488d6f4709a34b1e30edba6e2e54d82d23ec8dd6 Mon Sep 17 00:00:00 2001
From: Impa10r
Date: Fri, 5 Jul 2024 18:34:37 +0200
Subject: [PATCH 10/13] Add Update All
---
CHANGELOG.md | 1 +
cmd/psweb/handlers.go | 179 +++++++++++++++++++++-------------
cmd/psweb/ln/common.go | 2 +-
cmd/psweb/static/styles.css | 4 +
cmd/psweb/templates/af.gohtml | 33 ++++++-
5 files changed, 146 insertions(+), 73 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b71b25d..a97b19c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,7 @@
## 1.6.1
+- AutoFee: add Update All to set a paramereter to all custome rules
- Fix forwards subscription to add channel IDs
## 1.6.0
diff --git a/cmd/psweb/handlers.go b/cmd/psweb/handlers.go
index 0afe928..930958c 100644
--- a/cmd/psweb/handlers.go
+++ b/cmd/psweb/handlers.go
@@ -11,6 +11,7 @@ import (
"net/http"
"os"
"path/filepath"
+ "reflect"
"sort"
"strconv"
"strings"
@@ -1513,98 +1514,136 @@ func submitHandler(w http.ResponseWriter, r *http.Request) {
return
}
- rule := &ln.AutoFeeDefaults
- msg := ""
+ var newRule ln.AutoFeeParams
- if r.FormValue("update_button") != "" {
- // channelId == 0 means default rule
- msg = "Default rule updated"
+ newRule.FailedBumpPPM, err = strconv.Atoi(r.FormValue("failBump"))
+ if err != nil {
+ redirectWithError(w, r, "/af?", err)
+ return
+ }
- if channelId > 0 {
- // custom rule
- msg = "Custom rule updated"
- if ln.AutoFee[channelId] == nil {
- // add new
- ln.AutoFee[channelId] = new(ln.AutoFeeParams)
- msg = "Custom rule added"
- }
- rule = ln.AutoFee[channelId]
- }
+ newRule.FailedMoveThreshold, err = strconv.Atoi(r.FormValue("failedMoveThreshold"))
+ if err != nil {
+ redirectWithError(w, r, "/af?", err)
+ return
+ }
- rule.FailedBumpPPM, err = strconv.Atoi(r.FormValue("failBump"))
- if err != nil {
- redirectWithError(w, r, "/af?", err)
- return
- }
+ newRule.LowLiqPct, err = strconv.Atoi(r.FormValue("lowLiqPct"))
+ if err != nil {
+ redirectWithError(w, r, "/af?", err)
+ return
+ }
- rule.FailedMoveThreshold, err = strconv.Atoi(r.FormValue("failedMoveThreshold"))
- if err != nil {
- redirectWithError(w, r, "/af?", err)
- return
- }
+ newRule.LowLiqRate, err = strconv.Atoi(r.FormValue("lowLiqRate"))
+ if err != nil {
+ redirectWithError(w, r, "/af?", err)
+ return
+ }
- rule.LowLiqPct, err = strconv.Atoi(r.FormValue("lowLiqPct"))
- if err != nil {
- redirectWithError(w, r, "/af?", err)
- return
- }
+ newRule.NormalRate, err = strconv.Atoi(r.FormValue("normalRate"))
+ if err != nil {
+ redirectWithError(w, r, "/af?", err)
+ return
+ }
- rule.LowLiqRate, err = strconv.Atoi(r.FormValue("lowLiqRate"))
- if err != nil {
- redirectWithError(w, r, "/af?", err)
- return
- }
+ newRule.ExcessPct, err = strconv.Atoi(r.FormValue("excessPct"))
+ if err != nil {
+ redirectWithError(w, r, "/af?", err)
+ return
+ }
- rule.NormalRate, err = strconv.Atoi(r.FormValue("normalRate"))
- if err != nil {
- redirectWithError(w, r, "/af?", err)
- return
- }
+ newRule.ExcessRate, err = strconv.Atoi(r.FormValue("excessRate"))
+ if err != nil {
+ redirectWithError(w, r, "/af?", err)
+ return
+ }
- rule.ExcessPct, err = strconv.Atoi(r.FormValue("excessPct"))
- if err != nil {
- redirectWithError(w, r, "/af?", err)
- return
- }
+ newRule.InactivityDays, err = strconv.Atoi(r.FormValue("inactivityDays"))
+ if err != nil {
+ redirectWithError(w, r, "/af?", err)
+ return
+ }
- rule.ExcessRate, err = strconv.Atoi(r.FormValue("excessRate"))
- if err != nil {
- redirectWithError(w, r, "/af?", err)
- return
- }
+ newRule.InactivityDropPPM, err = strconv.Atoi(r.FormValue("inactivityDropPPM"))
+ if err != nil {
+ redirectWithError(w, r, "/af?", err)
+ return
+ }
- rule.InactivityDays, err = strconv.Atoi(r.FormValue("inactivityDays"))
- if err != nil {
- redirectWithError(w, r, "/af?", err)
- return
- }
+ newRule.InactivityDropPct, err = strconv.Atoi(r.FormValue("inactivityDropPct"))
+ if err != nil {
+ redirectWithError(w, r, "/af?", err)
+ return
+ }
- rule.InactivityDropPPM, err = strconv.Atoi(r.FormValue("inactivityDropPPM"))
- if err != nil {
- redirectWithError(w, r, "/af?", err)
- return
- }
+ newRule.CoolOffHours, err = strconv.Atoi(r.FormValue("coolOffHours"))
+ if err != nil {
+ redirectWithError(w, r, "/af?", err)
+ return
+ }
- rule.InactivityDropPct, err = strconv.Atoi(r.FormValue("inactivityDropPct"))
+ if ln.HasInboundFees() {
+ newRule.LowLiqDiscount, err = strconv.Atoi(r.FormValue("lowLiqDiscount"))
if err != nil {
redirectWithError(w, r, "/af?", err)
return
}
+ }
+ rule := &ln.AutoFeeDefaults
+ msg := ""
+ updateAll := false
- rule.CoolOffHours, err = strconv.Atoi(r.FormValue("coolOffHours"))
- if err != nil {
- redirectWithError(w, r, "/af?", err)
- return
+ if _, isCustom := ln.AutoFeeRule(channelId); isCustom {
+ updateAll = r.FormValue("update_all") != ""
+ }
+
+ if updateAll {
+ msg = "All custom rules updated:"
+ old := reflect.ValueOf(*ln.AutoFee[channelId])
+ new := reflect.ValueOf(newRule)
+
+ for _, rulePtr := range ln.AutoFee {
+ if rulePtr == nil {
+ continue
+ }
+ // Use Elem() to get the underlying struct from the pointer
+ current := reflect.ValueOf(rulePtr).Elem()
+ typeOfS := current.Type()
+ // find what was updated
+ for i := 0; i < old.NumField(); i++ {
+ if old.Field(i).Int() != new.Field(i).Int() {
+ if current.Field(i).CanSet() {
+ current.Field(i).SetInt(new.Field(i).Int())
+ msg += fmt.Sprintf(" %s=%v", typeOfS.Field(i).Name, new.Field(i).Interface())
+ } else {
+ redirectWithError(w, r, "/af?", errors.New("unable to set the value of "+typeOfS.Field(i).Name))
+ return
+ }
+ }
+ }
}
- if ln.HasInboundFees() {
- rule.LowLiqDiscount, err = strconv.Atoi(r.FormValue("lowLiqDiscount"))
- if err != nil {
- redirectWithError(w, r, "/af?", err)
- return
+ // persist to db
+ db.Save("AutoFees", "AutoFee", ln.AutoFee)
+
+ } else if r.FormValue("update_button") != "" {
+ // channelId == 0 means default rule
+ msg = "Default rule updated"
+
+ if channelId > 0 {
+ // custom rule
+ msg = "Custom rule updated"
+ if ln.AutoFee[channelId] == nil {
+ // add new
+ ln.AutoFee[channelId] = new(ln.AutoFeeParams)
+ msg = "Custom rule added"
}
+ rule = ln.AutoFee[channelId]
}
+ // clone the new data
+ *rule = newRule
+
// persist to db
if channelId > 0 {
db.Save("AutoFees", "AutoFee", ln.AutoFee)
diff --git a/cmd/psweb/ln/common.go b/cmd/psweb/ln/common.go
index 0eb1b9e..edda55b 100644
--- a/cmd/psweb/ln/common.go
+++ b/cmd/psweb/ln/common.go
@@ -230,7 +230,7 @@ func stringIsInSlice(whatToFind string, whereToSearch []string) bool {
func AutoFeeRule(channelId uint64) (*AutoFeeParams, bool) {
params := &AutoFeeDefaults
isCustom := false
- if AutoFee[channelId] != nil {
+ if channelId > 0 && AutoFee[channelId] != nil {
// channel has custom parameters
params = AutoFee[channelId]
isCustom = true
diff --git a/cmd/psweb/static/styles.css b/cmd/psweb/static/styles.css
index e08c728..9b3b07e 100644
--- a/cmd/psweb/static/styles.css
+++ b/cmd/psweb/static/styles.css
@@ -163,6 +163,10 @@ input[type="number"] {
font-size: 2em;
}
+.highlight {
+ background-color: #b4d8f0;
+}
+
input[type=checkbox] {
transform: scale(1.5);
cursor: pointer;
diff --git a/cmd/psweb/templates/af.gohtml b/cmd/psweb/templates/af.gohtml
index ee14a78..de37801 100644
--- a/cmd/psweb/templates/af.gohtml
+++ b/cmd/psweb/templates/af.gohtml
@@ -75,7 +75,7 @@
style="color:{{if eq .ColorScheme "dark"}}pink{{else}}red{{end}}"
{{end}}>{{.LocalPct}}% local, Current fee rate: {{fs .FeeRate}}{{if .HasInboundFees}}, Inbound rate: {{.InboundRate}}{{end}}
{{end}}
-