@@ -1778,6 +1778,22 @@ func (s *swapClientServer) WithdrawDeposits(ctx context.Context,
17781778 }, err
17791779}
17801780
1781+ // confirmedDeposits filters the given deposits and returns only those that have
1782+ // a positive confirmation height, i.e. deposits that have been confirmed
1783+ // on-chain.
1784+ func confirmedDeposits (deposits []* deposit.Deposit ) []* deposit.Deposit {
1785+ confirmed := make ([]* deposit.Deposit , 0 , len (deposits ))
1786+ for _ , d := range deposits {
1787+ if d .ConfirmationHeight <= 0 {
1788+ continue
1789+ }
1790+
1791+ confirmed = append (confirmed , d )
1792+ }
1793+
1794+ return confirmed
1795+ }
1796+
17811797// ListStaticAddressDeposits returns a list of all sufficiently confirmed
17821798// deposits behind the static address and displays properties like value,
17831799// state or blocks til expiry.
@@ -1951,9 +1967,10 @@ func (s *swapClientServer) ListStaticAddressSwaps(ctx context.Context,
19511967 protoDeposits = make ([]* looprpc.Deposit , 0 , len (ds ))
19521968 for _ , d := range ds {
19531969 state := toClientDepositState (d .GetState ())
1954- blocksUntilExpiry := d .ConfirmationHeight +
1955- int64 (addrParams .Expiry ) -
1956- int64 (lndInfo .BlockHeight )
1970+ blocksUntilExpiry := depositBlocksUntilExpiry (
1971+ d .ConfirmationHeight , addrParams .Expiry ,
1972+ int64 (lndInfo .BlockHeight ),
1973+ )
19571974
19581975 pd := & looprpc.Deposit {
19591976 Id : d .ID [:],
@@ -2015,23 +2032,16 @@ func (s *swapClientServer) GetStaticAddressSummary(ctx context.Context,
20152032 htlcTimeoutSwept int64
20162033 )
20172034
2018- // Value unconfirmed.
2019- utxos , err := s .staticAddressManager .ListUnspent (
2020- ctx , 0 , deposit .MinConfs - 1 ,
2021- )
2022- if err != nil {
2023- return nil , err
2024- }
2025- for _ , u := range utxos {
2026- valueUnconfirmed += int64 (u .Value )
2027- }
2028-
2029- // Confirmed total values by category.
2035+ // Total values by category.
20302036 for _ , d := range allDeposits {
20312037 value := int64 (d .Value )
20322038 switch d .GetState () {
20332039 case deposit .Deposited :
2034- valueDeposited += value
2040+ if d .ConfirmationHeight <= 0 {
2041+ valueUnconfirmed += value
2042+ } else {
2043+ valueDeposited += value
2044+ }
20352045
20362046 case deposit .Expired :
20372047 valueExpired += value
@@ -2174,13 +2184,27 @@ func (s *swapClientServer) populateBlocksUntilExpiry(ctx context.Context,
21742184 return err
21752185 }
21762186 for i := range len (deposits ) {
2177- deposits [i ].BlocksUntilExpiry =
2178- deposits [i ].ConfirmationHeight +
2179- int64 (params .Expiry ) - bestBlockHeight
2187+ deposits [i ].BlocksUntilExpiry = depositBlocksUntilExpiry (
2188+ deposits [i ].ConfirmationHeight , params .Expiry ,
2189+ bestBlockHeight ,
2190+ )
21802191 }
21812192 return nil
21822193}
21832194
2195+ // depositBlocksUntilExpiry returns the remaining blocks until a deposit
2196+ // expires. Unconfirmed deposits return the full CSV value because the timeout
2197+ // has not started yet.
2198+ func depositBlocksUntilExpiry (confirmationHeight int64 , expiry uint32 ,
2199+ bestBlockHeight int64 ) int64 {
2200+
2201+ if confirmationHeight <= 0 {
2202+ return int64 (expiry )
2203+ }
2204+
2205+ return confirmationHeight + int64 (expiry ) - bestBlockHeight
2206+ }
2207+
21842208// StaticOpenChannel initiates an open channel request using static address
21852209// deposits.
21862210func (s * swapClientServer ) StaticOpenChannel (ctx context.Context ,
0 commit comments