Skip to content

Commit 4a85935

Browse files
authored
Merge pull request #109 from Impa10r/v5.0.2
v5.0.2
2 parents bfde515 + 63ed386 commit 4a85935

3 files changed

Lines changed: 23 additions & 43 deletions

File tree

CHANGELOG.md

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

3+
## 5.0.2
4+
5+
- Count only unlocked outputs as available Liquid balance
6+
37
## 5.0.1
48

59
- Show correct fee rate in Telegram notifications

cmd/psweb/handlers.go

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,7 @@ func indexHandler(w http.ResponseWriter, r *http.Request) {
5151
}
5252
swaps := res.GetSwaps()
5353

54-
res2, err := ps.LiquidGetBalance(client)
55-
if err != nil {
56-
redirectWithError(w, r, "/config?", err)
57-
return
58-
}
59-
60-
satAmount := res2.GetSatAmount()
54+
satAmount := getUnlockedLbtcBalance()
6155

6256
// Lightning RPC client
6357
cl, clean, er := ln.GetClient()
@@ -254,14 +248,7 @@ func peerHandler(w http.ResponseWriter, r *http.Request) {
254248
allowlistedPeers := res2.GetAllowlistedPeers()
255249
suspiciousPeers := res2.GetSuspiciousPeerList()
256250

257-
res3, err := ps.LiquidGetBalance(client)
258-
if err != nil {
259-
log.Printf("unable to connect to RPC server: %v", err)
260-
redirectWithError(w, r, "/config?", err)
261-
return
262-
}
263-
264-
satAmount := res3.GetSatAmount()
251+
satAmount := getUnlockedLbtcBalance()
265252

266253
res4, err := ps.ListActiveSwaps(client)
267254
if err != nil {
@@ -1931,21 +1918,7 @@ func liquidHandler(w http.ResponseWriter, r *http.Request) {
19311918
addr = keys[0]
19321919
}
19331920

1934-
client, cleanup, err := ps.GetClient(config.Config.RpcHost)
1935-
if err != nil {
1936-
redirectWithError(w, r, "/config?", err)
1937-
return
1938-
}
1939-
defer cleanup()
1940-
1941-
res2, err := ps.LiquidGetBalance(client)
1942-
if err != nil {
1943-
log.Printf("unable to connect to RPC server: %v", err)
1944-
redirectWithError(w, r, "/?", err)
1945-
return
1946-
}
1947-
1948-
satAmount := res2.GetSatAmount()
1921+
satAmount := getUnlockedLbtcBalance()
19491922

19501923
var candidate AutoSwapParams
19511924

cmd/psweb/main.go

Lines changed: 16 additions & 13 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.1"
37+
VERSION = "v5.0.2"
3838
// Unusable BTC balance
3939
ANCHOR_RESERVE = 25_000
4040
// assume creatediscountct=1 for mainnet in elements.conf
@@ -406,6 +406,7 @@ func liquidBackup(force bool) {
406406
return
407407
}
408408

409+
// we don't care if some UTXOs may be locked
409410
satAmount := res2.GetSatAmount()
410411

411412
// do not backup if the sat amount did not change
@@ -1507,12 +1508,7 @@ func executeAutoSwap() {
15071508
return
15081509
}
15091510

1510-
res, err := ps.LiquidGetBalance(client)
1511-
if err != nil {
1512-
return
1513-
}
1514-
1515-
satAmount := res.GetSatAmount()
1511+
satAmount := getUnlockedLbtcBalance()
15161512

15171513
if satAmount < config.Config.AutoSwapThresholdAmount {
15181514
return
@@ -1815,11 +1811,6 @@ func advertiseBalances() {
18151811
}
18161812
defer cleanup()
18171813

1818-
res2, err := ps.LiquidGetBalance(client)
1819-
if err != nil {
1820-
return
1821-
}
1822-
18231814
res3, err := ps.ListPeers(client)
18241815
if err != nil {
18251816
return
@@ -1837,7 +1828,8 @@ func advertiseBalances() {
18371828
bitcoinBalance -= ANCHOR_RESERVE
18381829
}
18391830

1840-
liquidBalance := res2.GetSatAmount()
1831+
liquidBalance := getUnlockedLbtcBalance()
1832+
18411833
// Elements does not permit sending the whole balance, haircut it
18421834
if liquidBalance >= uint64(SwapLbtcDustReserve) {
18431835
liquidBalance -= uint64(SwapLbtcDustReserve)
@@ -1972,3 +1964,14 @@ func pollBalances() {
19721964
log.Println("Polled peers for balances")
19731965
}
19741966
}
1967+
1968+
// returns spendable Liquid BTC balance
1969+
func getUnlockedLbtcBalance() (liquidBalance uint64) {
1970+
var utxosLBTC []liquid.UTXO
1971+
// this list excludes locked outputs
1972+
liquid.ListUnspent(&utxosLBTC, elementsBitcoinId)
1973+
for _, utxo := range utxosLBTC {
1974+
liquidBalance += toSats(utxo.Amount)
1975+
}
1976+
return
1977+
}

0 commit comments

Comments
 (0)