@@ -38,6 +38,7 @@ import (
3838 "github.com/lightninglabs/taproot-assets/rfqmath"
3939 "github.com/lightningnetwork/lnd/lnrpc/walletrpc"
4040 "github.com/lightningnetwork/lnd/lntypes"
41+ "github.com/lightningnetwork/lnd/lnwallet"
4142 "github.com/lightningnetwork/lnd/queue"
4243 "github.com/lightningnetwork/lnd/routing/route"
4344 "github.com/lightningnetwork/lnd/zpay32"
@@ -1914,78 +1915,122 @@ func (s *swapClientServer) GetStaticAddressSummary(ctx context.Context,
19141915 _ * looprpc.StaticAddressSummaryRequest ) (
19151916 * looprpc.StaticAddressSummaryResponse , error ) {
19161917
1918+ summaries := make (map [string ]* looprpc.StaticAddressSummary )
1919+
19171920 allDeposits , err := s .depositManager .GetAllDeposits (ctx )
19181921 if err != nil {
19191922 return nil , err
19201923 }
19211924
1922- var (
1923- totalNumDeposits = len (allDeposits )
1924- valueUnconfirmed int64
1925- valueDeposited int64
1926- valueExpired int64
1927- valueWithdrawn int64
1928- valueLoopedIn int64
1929- htlcTimeoutSwept int64
1930- )
1925+ pkScriptDepositMap := make (map [string ][]* deposit.Deposit )
1926+ for _ , d := range allDeposits {
1927+ pkScript := string (d .AddressParams .PkScript )
1928+ pkScriptDepositMap [pkScript ] = append (
1929+ pkScriptDepositMap [pkScript ], d ,
1930+ )
1931+ }
19311932
1932- // Value unconfirmed.
1933- utxos , err := s .staticAddressManager .ListUnspent (
1934- ctx , 0 , deposit .MinConfs - 1 ,
1935- )
1933+ network , err := s .network .ChainParams ()
19361934 if err != nil {
19371935 return nil , err
19381936 }
1939- for _ , u := range utxos {
1940- valueUnconfirmed += int64 (u .Value )
1941- }
1937+ var deprecatedSummary looprpc.StaticAddressSummary
1938+ for pkScript , deposits := range pkScriptDepositMap {
1939+ if len (deposits ) == 0 {
1940+ continue
1941+ }
19421942
1943- // Confirmed total values by category.
1944- for _ , d := range allDeposits {
1945- value := int64 (d .Value )
1946- switch d .GetState () {
1947- case deposit .Deposited :
1948- valueDeposited += value
1943+ address , err := deposits [0 ].AddressParams .TaprootAddress (network )
1944+ if err != nil {
1945+ return nil , err
1946+ }
1947+ summary := looprpc.StaticAddressSummary {
1948+ StaticAddress : address ,
1949+ RelativeExpiryBlocks : uint64 (deposits [0 ].AddressParams .Expiry ),
1950+ TotalNumDeposits : uint32 (len (deposits )),
1951+ }
1952+
1953+ for _ , d := range deposits {
1954+ value := int64 (d .Value )
1955+ switch d .GetState () {
1956+ case deposit .Deposited :
1957+ summary .ValueDepositedSatoshis += value
19491958
1950- case deposit .Expired :
1951- valueExpired += value
1959+ case deposit .Expired :
1960+ summary . ValueExpiredSatoshis += value
19521961
1953- case deposit .Withdrawn :
1954- valueWithdrawn += value
1962+ case deposit .Withdrawn :
1963+ summary . ValueWithdrawnSatoshis += value
19551964
1956- case deposit .LoopedIn :
1957- valueLoopedIn += value
1965+ case deposit .LoopedIn :
1966+ summary . ValueLoopedInSatoshis += value
19581967
1959- case deposit .HtlcTimeoutSwept :
1960- htlcTimeoutSwept += value
1968+ case deposit .HtlcTimeoutSwept :
1969+ summary .ValueHtlcTimeoutSweepsSatoshis += value
1970+ }
19611971 }
1972+
1973+ if deposits [0 ].AddressID == 1 {
1974+ deprecatedSummary = summary
1975+ }
1976+
1977+ summaries [pkScript ] = & summary
19621978 }
19631979
1964- params , err := s .staticAddressManager .GetStaticAddressParameters (ctx )
1980+ preDepositedMap := make (map [string ][]* lnwallet.Utxo )
1981+ preDepositedUtxos , err := s .staticAddressManager .ListUnspent (
1982+ ctx , 0 , deposit .MinConfs - 1 ,
1983+ )
19651984 if err != nil {
19661985 return nil , err
19671986 }
19681987
1969- network , err := s .network .ChainParams ()
1970- if err != nil {
1971- return nil , err
1988+ for _ , utxo := range preDepositedUtxos {
1989+ pkScript := string (utxo .PkScript )
1990+ preDepositedMap [pkScript ] = append (
1991+ preDepositedMap [pkScript ], utxo ,
1992+ )
19721993 }
19731994
1974- address , err := params .TaprootAddress (network )
1975- if err != nil {
1976- return nil , err
1995+ for pkScript , utxos := range preDepositedMap {
1996+ notDepositedValue := int64 (0 )
1997+ for _ , utxo := range utxos {
1998+ notDepositedValue += int64 (utxo .Value )
1999+ }
2000+
2001+ if _ , ok := summaries [pkScript ]; ok {
2002+ summaries [pkScript ].ValueUnconfirmedSatoshis =
2003+ notDepositedValue
2004+ } else {
2005+ params := s .staticAddressManager .GetParameters ([]byte (pkScript ))
2006+ staticAddress , err := params .TaprootAddress (network )
2007+ if err != nil {
2008+ return nil , err
2009+ }
2010+ summaries [pkScript ] = & looprpc.StaticAddressSummary {
2011+ StaticAddress : staticAddress ,
2012+ RelativeExpiryBlocks : uint64 (params .Expiry ),
2013+ ValueUnconfirmedSatoshis : notDepositedValue ,
2014+ }
2015+ }
2016+ }
2017+
2018+ results := make ([]* looprpc.StaticAddressSummary , 0 , len (summaries ))
2019+ for _ , summary := range summaries {
2020+ results = append (results , summary )
19772021 }
19782022
19792023 return & looprpc.StaticAddressSummaryResponse {
1980- StaticAddress : address ,
1981- RelativeExpiryBlocks : uint64 (params .Expiry ),
1982- TotalNumDeposits : uint32 (totalNumDeposits ),
1983- ValueUnconfirmedSatoshis : valueUnconfirmed ,
1984- ValueDepositedSatoshis : valueDeposited ,
1985- ValueExpiredSatoshis : valueExpired ,
1986- ValueWithdrawnSatoshis : valueWithdrawn ,
1987- ValueLoopedInSatoshis : valueLoopedIn ,
1988- ValueHtlcTimeoutSweepsSatoshis : htlcTimeoutSwept ,
2024+ StaticAddress : deprecatedSummary .StaticAddress ,
2025+ RelativeExpiryBlocks : deprecatedSummary .RelativeExpiryBlocks ,
2026+ TotalNumDeposits : deprecatedSummary .TotalNumDeposits ,
2027+ ValueUnconfirmedSatoshis : deprecatedSummary .ValueUnconfirmedSatoshis ,
2028+ ValueDepositedSatoshis : deprecatedSummary .ValueDepositedSatoshis ,
2029+ ValueExpiredSatoshis : deprecatedSummary .ValueExpiredSatoshis ,
2030+ ValueWithdrawnSatoshis : deprecatedSummary .ValueWithdrawnSatoshis ,
2031+ ValueLoopedInSatoshis : deprecatedSummary .ValueLoopedInSatoshis ,
2032+ ValueHtlcTimeoutSweepsSatoshis : deprecatedSummary .ValueHtlcTimeoutSweepsSatoshis ,
2033+ PerAddressSummaries : results ,
19892034 }, nil
19902035}
19912036
0 commit comments