Skip to content

Commit bfde515

Browse files
authored
Merge pull request #105 from Impa10r/v5.0.1
v5.0.1
2 parents 7c908b8 + 8691257 commit bfde515

6 files changed

Lines changed: 59 additions & 29 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Versions
22

3+
## 5.0.1
4+
5+
- Show correct fee rate in Telegram notifications
6+
- Show all times in the local time zone
7+
- Fix default user folder on MacOS
8+
- Add a dedicated Global Premiums page
9+
310
## 5.0.0
411

512
- Change versioning to match PeerSwap protocol version

cmd/psweb/config/common.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"encoding/json"
55
"log"
66
"os"
7-
"os/user"
87
"path/filepath"
98
)
109

@@ -59,12 +58,14 @@ var Config Configuration
5958

6059
func Load(dataDir string, network string) {
6160

62-
// Get the current user's information
63-
currentUser, err := user.Current()
64-
if err != nil {
65-
log.Fatalln(err)
61+
// env gets priority
62+
if os.Getenv("NETWORK") != "" {
63+
network = os.Getenv("NETWORK")
6664
}
6765

66+
// Get the current user's information
67+
currentUser := os.Getenv("USER")
68+
6869
// load defaults first
6970
Config.AllowSwapRequests = true
7071
Config.ColorScheme = "dark" // dark or light
@@ -73,8 +74,8 @@ func Load(dataDir string, network string) {
7374
Config.BitcoinSwaps = true
7475
Config.LocalMempool = ""
7576
Config.ListenPort = "1984"
76-
Config.ElementsDir = filepath.Join(currentUser.HomeDir, ".elements")
77-
Config.ElementsDirMapped = filepath.Join(currentUser.HomeDir, ".elements")
77+
Config.ElementsDir = filepath.Join("home", currentUser, ".elements")
78+
Config.ElementsDirMapped = filepath.Join("home", currentUser, ".elements")
7879
Config.ElementsWallet = "peerswap"
7980
Config.ElementsHost = "http://127.0.0.1"
8081
Config.ElementsPort = "18884"
@@ -90,7 +91,7 @@ func Load(dataDir string, network string) {
9091
Config.SecureConnection = false
9192
Config.SecurePort = "1985"
9293

93-
if network != "mainnet" {
94+
if network != "mainnet" && network != "bitcoin" {
9495
Config.NodeApi = "https://mempool.space/" + network + "/lightning/node"
9596
Config.BitcoinApi = "https://mempool.space/" + network
9697
Config.LiquidApi = "https://liquid.network/testnet"
@@ -114,8 +115,13 @@ func Load(dataDir string, network string) {
114115
Config.ElementsHost = os.Getenv("ELEMENTS_HOST")
115116
}
116117

118+
homeFolder := filepath.Join("/home", currentUser)
119+
if currentUser == "root" {
120+
homeFolder = "/root"
121+
}
122+
117123
// different defaults for LND and CLN
118-
loadDefaults(currentUser.HomeDir, dataDir, network)
124+
loadDefaults(homeFolder, dataDir, network)
119125

120126
// load config from peerswap.conf
121127
LoadPS()

cmd/psweb/handlers.go

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,21 @@ func bitcoinHandler(w http.ResponseWriter, r *http.Request) {
924924
eta = "Past due"
925925
}
926926

927+
client, cleanup, err := ps.GetClient(config.Config.RpcHost)
928+
if err != nil {
929+
redirectWithError(w, r, "/config?", err)
930+
return
931+
}
932+
defer cleanup()
933+
934+
res, err := ps.ListPeers(client)
935+
if err != nil {
936+
log.Printf("unable to connect to RPC server: %v", err)
937+
redirectWithError(w, r, "/config?", err)
938+
return
939+
}
940+
peers := res.GetPeers()
941+
927942
data := Page{
928943
Authenticated: config.Config.SecureConnection && config.Config.Password != "",
929944
ErrorMessage: errorMessage,
@@ -952,7 +967,7 @@ func bitcoinHandler(w http.ResponseWriter, r *http.Request) {
952967
BitcoinAddress: addr,
953968
AdvertiseEnabled: ln.AdvertiseBitcoinBalance,
954969
BitcoinSwaps: config.Config.BitcoinSwaps,
955-
CanClaimJoin: hasDiscountedvSize,
970+
CanClaimJoin: hasDiscountedvSize && len(peers) > 0,
956971
IsClaimJoin: config.Config.PeginClaimJoin,
957972
ClaimJoinStatus: ln.ClaimStatus,
958973
HasClaimJoinPending: ln.ClaimJoinHandler != "",
@@ -1174,12 +1189,10 @@ func peginHandler(w http.ResponseWriter, r *http.Request) {
11741189

11751190
if isPegin {
11761191
log.Println("New Peg-in TxId:", res.TxId, "RawHex:", res.RawHex, "Claim script:", claimScript)
1177-
duration := time.Duration(10*peginBlocks) * time.Minute
1178-
eta := time.Now().Add(duration).Format("3:04 PM")
1179-
telegramSendMessage(fmt.Sprintf("⏰ Started peg in %s sats, fee rate: %0.2f s/vb, ETA: %s, TxId: `%s`", formatWithThousandSeparators(uint64(res.AmountSat)), config.Config.PeginFeeRate, eta, res.TxId))
1192+
telegramSendMessage(fmt.Sprintf("⏰ Started peg in %s sats, fee rate: %0.2f s/vb, TxId: `%s`", formatWithThousandSeparators(uint64(res.AmountSat)), res.ExactSatVb, res.TxId))
11801193
} else {
11811194
log.Println("BTC withdrawal pending, TxId:", res.TxId, "RawHex:", res.RawHex)
1182-
telegramSendMessage(fmt.Sprintf("⛓️ BTC withdrawal pending: %s sats, fee rate: %0.2f s/vb, TxId: `%s`", formatWithThousandSeparators(uint64(res.AmountSat)), config.Config.PeginFeeRate, res.TxId))
1195+
telegramSendMessage(fmt.Sprintf("⛓️ BTC withdrawal pending: %s sats, fee rate: %0.2f s/vb, TxId: `%s`", formatWithThousandSeparators(uint64(res.AmountSat)), res.ExactSatVb, res.TxId))
11831196
}
11841197
config.Config.PeginAmount = res.AmountSat
11851198
config.Config.PeginTxId = res.TxId
@@ -1630,7 +1643,7 @@ func updateHandler(w http.ResponseWriter, r *http.Request) {
16301643
swapData += swap.Id
16311644
swapData += `</td></tr>
16321645
<tr><td style="text-align: right">Created At:</td><td >`
1633-
swapData += time.Unix(swap.CreatedAt, 0).UTC().Format("2006-01-02 15:04:05")
1646+
swapData += time.Unix(swap.CreatedAt, 0).Format("2006-01-02 15:04:05")
16341647
swapData += `</td></tr>
16351648
<tr><td style="text-align: right">Asset:</td><td>`
16361649
swapData += swap.Asset
@@ -2112,9 +2125,7 @@ func submitHandler(w http.ResponseWriter, r *http.Request) {
21122125
ln.ClaimStatus = "Awaiting funding tx to confirm"
21132126

21142127
log.Println("External Funding TxId:", txid)
2115-
duration := time.Duration(10*(int32(peginBlocks)-tx.Confirmations)) * time.Minute
2116-
eta := time.Now().Add(duration).Format("3:04 PM")
2117-
telegramSendMessage("⏰ Started peg in " + formatWithThousandSeparators(uint64(config.Config.PeginAmount)) + " sats. ETA: " + eta + ". TxId: `" + txid + "`")
2128+
telegramSendMessage("⏰ Started peg in " + formatWithThousandSeparators(uint64(config.Config.PeginAmount)) + " sats. External funding TxId: `" + txid + "`")
21182129
}
21192130

21202131
config.Save()

cmd/psweb/main-lnd.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,8 @@ func main() {
3535
os.Exit(0)
3636
}
3737

38-
network := "mainnet"
39-
if os.Getenv("NETWORK") != "" {
40-
network = os.Getenv("NETWORK")
41-
}
42-
4338
// loading from config file or creating default one
44-
config.Load(*dataDir, network)
39+
config.Load(*dataDir, "mainnet")
4540

4641
if *password != "" {
4742
// enable HTTPS

cmd/psweb/main.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import (
3434

3535
const (
3636
// App VERSION tag
37-
VERSION = "v5.0.0"
37+
VERSION = "v5.0.1"
3838
// Unusable BTC balance
3939
ANCHOR_RESERVE = 25_000
4040
// assume creatediscountct=1 for mainnet in elements.conf
@@ -1210,10 +1210,11 @@ func checkPegin() {
12101210

12111211
if confs > 0 {
12121212
if config.Config.PeginClaimScript == "" {
1213+
// regular BTC withdrawal
12131214
log.Println("BTC withdrawal complete, txId: " + config.Config.PeginTxId)
12141215
telegramSendMessage("💸 BTC withdrawal complete. TxId: `" + config.Config.PeginTxId + "`")
12151216
} else if confs >= int32(peginBlocks) && ln.MyRole == "none" {
1216-
// claim individual peg-in
1217+
// pegin matured, claim individual peg-in
12171218
failed := false
12181219
proof := ""
12191220
txid := ""
@@ -1247,6 +1248,13 @@ func checkPegin() {
12471248
telegramSendMessage("💸 Peg-in complete! Liquid TxId: `" + txid + "`")
12481249
}
12491250
} else {
1251+
if ln.ClaimStatus == "Awaiting funding tx to confirm" {
1252+
// funding tx confirmed
1253+
ln.ClaimStatus = "Funding tx confirmed, awaiting maturity"
1254+
db.Save("ClaimJoin", "ClaimStatus", ln.ClaimStatus)
1255+
telegramSendMessage(ln.ClaimStatus + ", ETA: " + time.Now().Add(time.Hour*17).Format("3:04 PM"))
1256+
}
1257+
12501258
if config.Config.PeginClaimJoin {
12511259
if ln.MyRole == "none" {
12521260
claimHeight := currentBlockHeight + peginBlocks - uint32(confs)
@@ -1274,7 +1282,7 @@ func checkPegin() {
12741282
return
12751283
}
12761284

1277-
// stop trying after one attempt
1285+
// stop trying after one attempt to claim
12781286
config.Config.PeginTxId = ""
12791287
config.Save()
12801288
}

cmd/psweb/telegram.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func telegramStart() {
9696
} else {
9797
if config.Config.PeginTxId != "external" {
9898
confs, _ := peginConfirmations(config.Config.PeginTxId)
99-
if config.Config.PeginClaimJoin {
99+
if config.Config.PeginClaimJoin && ln.ClaimBlockHeight > 0 {
100100
bh := ln.GetBlockHeight()
101101
duration := time.Duration(10*(ln.ClaimBlockHeight-bh)) * time.Minute
102102
if ln.ClaimBlockHeight == 0 {
@@ -121,11 +121,14 @@ func telegramStart() {
121121
t = "⛓️ BTC withdrawal pending: "
122122
}
123123
t += formatWithThousandSeparators(uint64(config.Config.PeginAmount)) + " sats, Confs: " + strconv.Itoa(int(confs))
124-
t += fmt.Sprintf(", sat/vb: %0.2f", config.Config.PeginFeeRate)
125124
if config.Config.PeginClaimScript != "" {
126125
t += "/102, ETA: " + eta
127126
}
128127
t += ". TxId: `" + config.Config.PeginTxId + "`"
128+
if confs == 0 {
129+
t += fmt.Sprintf(", sat/vb: %0.2f", config.Config.PeginFeeRate)
130+
}
131+
129132
}
130133
} else {
131134
t = "Awaiting external funding to a peg-in address"

0 commit comments

Comments
 (0)