@@ -34,7 +34,7 @@ import (
3434
3535const (
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