Skip to content

Commit

Permalink
Merge pull request #47 from Impa10r/v1.4.7
Browse files Browse the repository at this point in the history
v1.4.7
  • Loading branch information
Impa10r authored May 22, 2024
2 parents 9fd2eaa + a4f959f commit e0d1a01
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 49 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"type": "go",
"request": "launch",
"mode": "auto",
"buildFlags": "-tags cln",
"buildFlags": "-tags lnd",
"program": "${workspaceFolder}/cmd/psweb/",
"showLog": false,
"envFile": "${workspaceFolder}/.env",
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Versions

## 1.4.7

- Remove resthost from peerswap.conf
- Fix panic in appendInvoices
- Add revenue and costs to tooltips

## 1.4.6

- Estimate swap fees before submitting
Expand Down
20 changes: 8 additions & 12 deletions cmd/psweb/config/cln.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func LoadPS() {
user := GetPeerswapCLNSetting("Bitcoin", "rpcuser")
password := GetPeerswapCLNSetting("Bitcoin", "rpcpassword")

if host == "" && user == "" && password == "" {
if host == "" || user == "" || password == "" {
Config.BitcoinHost = GetBlockIoHost()
Config.BitcoinUser = ""
Config.BitcoinPass = ""
Expand Down Expand Up @@ -182,22 +182,18 @@ func GetPeerswapCLNSetting(section, searchVariable string) string {
}
// Convert the content to a string
fileContent := string(content)
value := ""

// Search section
if sectionIndex := strings.Index(fileContent, "["+section+"]"); sectionIndex > -1 {
// Search variable should start from new line '\n' and be followed with '='
if index := strings.Index(fileContent[sectionIndex:], "\n"+searchVariable+"="); index > 0 {
startIndex := sectionIndex + index + len(searchVariable) + 2
for _, char := range fileContent[startIndex:] {
if char == '\n' || char == '\r' {
break
}
if char != '"' {
value += string(char)
lines := strings.Split(string(fileContent[sectionIndex:]), "\n")
for _, line := range lines {
if parts := strings.Split(line, "="); len(parts) > 1 {
if parts[0] == searchVariable {
// Remove double quotes
return strings.ReplaceAll(strings.TrimSpace(parts[1]), `"`, "")
}
}
}
}
return value
return ""
}
27 changes: 8 additions & 19 deletions cmd/psweb/config/lnd.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ func SavePS() {

//key, default, new value, env key
t += setPeerswapdVariable("host", "localhost:42069", Config.RpcHost, "")
t += setPeerswapdVariable("resthost", "localhost:42070", "", "")
// remove resthost
// t += setPeerswapdVariable("resthost", "localhost:42070", "", "")
t += setPeerswapdVariable("lnd.host", "localhost:10009", "", "LND_HOST")
t += setPeerswapdVariable("lnd.tlscertpath", filepath.Join(Config.LightningDir, "tls.cert"), "", "")
t += setPeerswapdVariable("lnd.macaroonpath", filepath.Join(Config.LightningDir, "data", "chain", "bitcoin", Config.Chain, "admin.macaroon"), "", "LND_MACAROONPATH")
Expand Down Expand Up @@ -182,27 +183,15 @@ func getConfSetting(searchVariable, filePath string) string {
log.Println("Error reading file", filePath, err)
return ""
}
// Convert the content to a string
fileContent := string(content)

index := 0

// try the start of the file
if fileContent[:len(searchVariable)+1] != searchVariable+"=" {
// variables should start from new line '\n'
index = strings.Index(fileContent, "\n"+searchVariable+"=") + 1
}

if index > -1 {
startIndex := index + len(searchVariable) + 1
value := ""
for _, char := range fileContent[startIndex:] {
if char == '\n' || char == '\r' || char == ' ' {
break
lines := strings.Split(string(content), "\n")
for _, line := range lines {
if parts := strings.Split(line, "="); len(parts) > 1 {
if parts[0] == searchVariable {
return strings.TrimSpace(parts[1])
}
value += string(char)
}
return value
}
// not found
return ""
}
19 changes: 10 additions & 9 deletions cmd/psweb/ln/cln.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ import (
)

const (
Implementation = "CLN"
fileRPC = "lightning-rpc"
SwapFeeReserveLBTC = uint64(000)
Implementation = "CLN"
fileRPC = "lightning-rpc"
// Liquid balance to reserve in auto swap-ins
// https://github.com/ElementsProject/peerswap/blob/master/clightning/clightning_commands.go#L392
SwapFeeReserveLBTC = uint64(0)
SwapFeeReserveBTC = uint64(2000)
)

Expand Down Expand Up @@ -894,15 +896,15 @@ func fetchPaymentsStats(client *glightning.Lightning, timeStamp uint64, channelI
continue
}
if inv.Invoices[0].PaidAt > timeStamp {
if len(inv.Invoices[0].Label) > 7 {
if inv.Invoices[0].Label[:8] == "peerswap" {
if parts := strings.Split(inv.Invoices[0].Label, " "); len(parts) > 4 {
if parts[0] == "peerswap" {
// find swap id
parts := strings.Split(inv.Invoices[0].Label, " ")
if parts[2] == "fee" && len(parts[4]) > 0 {
// save rebate payment
SwapRebates[parts[4]] = int64(htlc.AmountMsat) / 1000
}
} else {
// only account for non-peerswap related
invoicedMsat += htlc.AmountMsat
}
}
Expand All @@ -929,10 +931,9 @@ func fetchPaymentsStats(client *glightning.Lightning, timeStamp uint64, channelI
invoice, err := zpay32.Decode(pmt.Payments[0].Bolt11, harnessNetParams)
if err == nil {
if invoice.Description != nil {
if len(*invoice.Description) > 7 {
if (*invoice.Description)[:8] == "peerswap" {
if parts := strings.Split(*invoice.Description, " "); len(parts) > 4 {
if parts[0] == "peerswap" {
// find swap id
parts := strings.Split(*invoice.Description, " ")
if parts[2] == "fee" && len(parts[4]) > 0 {
// save rebate payment
SwapRebates[parts[4]] = int64(htlc.AmountMsat) / 1000
Expand Down
11 changes: 5 additions & 6 deletions cmd/psweb/ln/lnd.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import (
const (
Implementation = "LND"
// Liquid balance to reserve in auto swap-ins
// https://github.com/ElementsProject/peerswap/blob/master/peerswaprpc/server.go#L234
SwapFeeReserveLBTC = uint64(1000)
SwapFeeReserveBTC = uint64(2000)
)
Expand Down Expand Up @@ -796,10 +797,9 @@ func appendPayment(payment *lnrpc.Payment) {
invoice, err := zpay32.Decode(payment.PaymentRequest, harnessNetParams)
if err == nil {
if invoice.Description != nil {
if len(*invoice.Description) > 7 {
if (*invoice.Description)[:8] == "peerswap" {
if parts := strings.Split(*invoice.Description, " "); len(parts) > 4 {
if parts[0] == "peerswap" {
// find swap id
parts := strings.Split(*invoice.Description, " ")
if parts[2] == "fee" && len(parts[4]) > 0 {
// save rebate payment
SwapRebates[parts[4]] = int64(payment.ValueMsat) / 1000
Expand Down Expand Up @@ -1035,10 +1035,9 @@ func appendInvoice(invoice *lnrpc.Invoice) {
}
// only append settled htlcs
if invoice.State == lnrpc.Invoice_SETTLED {
if len(invoice.Memo) > 7 {
if invoice.Memo[:8] == "peerswap" {
if parts := strings.Split(invoice.Memo, " "); len(parts) > 4 {
if parts[0] == "peerswap" {
// find swap id
parts := strings.Split(invoice.Memo, " ")
if parts[2] == "fee" && len(parts[4]) > 0 {
// save rebate payment
SwapRebates[parts[4]] = int64(invoice.AmtPaidMsat) / 1000
Expand Down
8 changes: 7 additions & 1 deletion cmd/psweb/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (

const (
// App version tag
version = "v1.4.6"
version = "v1.4.7"
)

type SwapParams struct {
Expand Down Expand Up @@ -2040,10 +2040,16 @@ func convertPeersToHTMLTable(peers []*peerswaprpc.PeerSwapPeer, allowlistedPeers

if stats.FeeSat > 0 {
flowText += "\nRevenue: +" + formatWithThousandSeparators(stats.FeeSat)
if stats.RoutedOut > 0 {
flowText += "\nRevenue PPM: " + formatWithThousandSeparators(stats.FeeSat*1_000_000/stats.RoutedOut)
}
}

if stats.PaidCost > 0 {
flowText += "\nCosts: -" + formatWithThousandSeparators(stats.PaidCost)
if stats.PaidOut > 0 {
flowText += "\nCosts PPM: " + formatWithThousandSeparators(stats.PaidCost*1_000_000/stats.PaidOut)
}
}

tooltip += flowText
Expand Down
2 changes: 1 addition & 1 deletion cmd/psweb/templates/liquid.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
<div class="control">
<label class="checkbox is-large">
<input type="checkbox" name="autoSwapEnabled" {{if .AutoSwapEnabled}}checked{{end}}>
<strong>&nbsp&nbspEnable Automatic Swap-Ins 🤖</strong>
<strong>&nbsp&nbspEnable Automatic Liquid Swap-Ins 🤖</strong>
</label>
</div>
</div>
Expand Down

0 comments on commit e0d1a01

Please sign in to comment.