@@ -32,11 +32,12 @@ import (
3232 "github.com/lightninglabs/loop/staticaddr/address"
3333 "github.com/lightninglabs/loop/staticaddr/deposit"
3434 "github.com/lightninglabs/loop/staticaddr/loopin"
35+ "github.com/lightninglabs/loop/staticaddr/openchannel"
36+ "github.com/lightninglabs/loop/staticaddr/staticutil"
3537 "github.com/lightninglabs/loop/staticaddr/withdraw"
3638 "github.com/lightninglabs/loop/swap"
3739 "github.com/lightninglabs/loop/swapserverrpc"
3840 "github.com/lightninglabs/taproot-assets/rfqmath"
39- "github.com/lightningnetwork/lnd/lnrpc"
4041 "github.com/lightningnetwork/lnd/lnrpc/walletrpc"
4142 "github.com/lightningnetwork/lnd/lntypes"
4243 "github.com/lightningnetwork/lnd/queue"
@@ -98,6 +99,7 @@ type swapClientServer struct {
9899 depositManager * deposit.Manager
99100 withdrawalManager * withdraw.Manager
100101 staticLoopInManager * loopin.Manager
102+ openChannelManager * openchannel.Manager
101103 assetClient * assets.TapdClient
102104 swaps map [lntypes.Hash ]loop.SwapInfo
103105 subscribers map [int ]chan <- interface {}
@@ -1753,7 +1755,7 @@ func (s *swapClientServer) WithdrawDeposits(ctx context.Context,
17531755 }
17541756
17551757 case isUtxoSelected :
1756- outpoints , err = toServerOutpoints (req .Outpoints )
1758+ outpoints , err = staticutil . ToWireOutpoints (req .Outpoints )
17571759 if err != nil {
17581760 return nil , err
17591761 }
@@ -1998,13 +2000,14 @@ func (s *swapClientServer) GetStaticAddressSummary(ctx context.Context,
19982000 }
19992001
20002002 var (
2001- totalNumDeposits = len (allDeposits )
2002- valueUnconfirmed int64
2003- valueDeposited int64
2004- valueExpired int64
2005- valueWithdrawn int64
2006- valueLoopedIn int64
2007- htlcTimeoutSwept int64
2003+ totalNumDeposits = len (allDeposits )
2004+ valueUnconfirmed int64
2005+ valueDeposited int64
2006+ valueExpired int64
2007+ valueWithdrawn int64
2008+ valueLoopedIn int64
2009+ valueChannelsOpened int64
2010+ htlcTimeoutSwept int64
20082011 )
20092012
20102013 // Value unconfirmed.
@@ -2036,6 +2039,9 @@ func (s *swapClientServer) GetStaticAddressSummary(ctx context.Context,
20362039
20372040 case deposit .HtlcTimeoutSwept :
20382041 htlcTimeoutSwept += value
2042+
2043+ case deposit .ChannelPublished :
2044+ valueChannelsOpened += value
20392045 }
20402046 }
20412047
@@ -2060,6 +2066,7 @@ func (s *swapClientServer) GetStaticAddressSummary(ctx context.Context,
20602066 ValueExpiredSatoshis : valueExpired ,
20612067 ValueWithdrawnSatoshis : valueWithdrawn ,
20622068 ValueLoopedInSatoshis : valueLoopedIn ,
2069+ ValueChannelsOpened : valueChannelsOpened ,
20632070 ValueHtlcTimeoutSweepsSatoshis : htlcTimeoutSwept ,
20642071 }, nil
20652072}
@@ -2169,6 +2176,35 @@ func (s *swapClientServer) populateBlocksUntilExpiry(ctx context.Context,
21692176 return nil
21702177}
21712178
2179+ // StaticOpenChannel initiates an open channel request using static address
2180+ // deposits.
2181+ func (s * swapClientServer ) StaticOpenChannel (ctx context.Context ,
2182+ req * looprpc.StaticOpenChannelRequest ) (* looprpc.StaticOpenChannelResponse ,
2183+ error ) {
2184+
2185+ infof ("Static open channel request received" )
2186+
2187+ if req == nil || req .OpenChannelRequest == nil {
2188+ return & looprpc.StaticOpenChannelResponse {},
2189+ fmt .Errorf ("missing open channel request" )
2190+ }
2191+
2192+ chanOpenTxHash , err := s .openChannelManager .DeliverOpenChannelRequest (
2193+ ctx , req .OpenChannelRequest ,
2194+ )
2195+
2196+ var (
2197+ txHash string
2198+ )
2199+ if chanOpenTxHash != nil {
2200+ txHash = chanOpenTxHash .String ()
2201+ }
2202+
2203+ return & looprpc.StaticOpenChannelResponse {
2204+ ChannelOpenTxHash : txHash ,
2205+ }, err
2206+ }
2207+
21722208type filterFunc func (deposits * deposit.Deposit ) bool
21732209
21742210func filter (deposits []* deposit.Deposit , f filterFunc ) []* looprpc.Deposit {
@@ -2222,6 +2258,12 @@ func toClientDepositState(state fsm.StateType) looprpc.DepositState {
22222258 case deposit .LoopedIn :
22232259 return looprpc .DepositState_LOOPED_IN
22242260
2261+ case deposit .OpeningChannel :
2262+ return looprpc .DepositState_OPENING_CHANNEL
2263+
2264+ case deposit .ChannelPublished :
2265+ return looprpc .DepositState_CHANNEL_PUBLISHED
2266+
22252267 case deposit .SweepHtlcTimeout :
22262268 return looprpc .DepositState_SWEEP_HTLC_TIMEOUT
22272269
@@ -2301,6 +2343,12 @@ func toServerState(state looprpc.DepositState) fsm.StateType {
23012343 case looprpc .DepositState_LOOPED_IN :
23022344 return deposit .LoopedIn
23032345
2346+ case looprpc .DepositState_OPENING_CHANNEL :
2347+ return deposit .OpeningChannel
2348+
2349+ case looprpc .DepositState_CHANNEL_PUBLISHED :
2350+ return deposit .ChannelPublished
2351+
23042352 case looprpc .DepositState_SWEEP_HTLC_TIMEOUT :
23052353 return deposit .SweepHtlcTimeout
23062354
@@ -2318,23 +2366,6 @@ func toServerState(state looprpc.DepositState) fsm.StateType {
23182366 }
23192367}
23202368
2321- func toServerOutpoints (outpoints []* lnrpc.OutPoint ) ([]wire.OutPoint ,
2322- error ) {
2323-
2324- var serverOutpoints []wire.OutPoint
2325- for _ , o := range outpoints {
2326- outpointStr := fmt .Sprintf ("%s:%d" , o .TxidStr , o .OutputIndex )
2327- newOutpoint , err := wire .NewOutPointFromString (outpointStr )
2328- if err != nil {
2329- return nil , err
2330- }
2331-
2332- serverOutpoints = append (serverOutpoints , * newOutpoint )
2333- }
2334-
2335- return serverOutpoints , nil
2336- }
2337-
23382369func rpcAutoloopReason (reason liquidity.Reason ) (looprpc.AutoReason , error ) {
23392370 switch reason {
23402371 case liquidity .ReasonNone :
0 commit comments