@@ -28,6 +28,7 @@ import (
2828 clientrpc "github.com/lightninglabs/loop/looprpc"
2929 "github.com/lightninglabs/loop/staticaddr/address"
3030 "github.com/lightninglabs/loop/staticaddr/deposit"
31+ "github.com/lightninglabs/loop/staticaddr/loopin"
3132 "github.com/lightninglabs/loop/staticaddr/withdraw"
3233 "github.com/lightninglabs/loop/swap"
3334 looprpc "github.com/lightninglabs/loop/swapserverrpc"
@@ -91,6 +92,7 @@ type swapClientServer struct {
9192 staticAddressManager * address.Manager
9293 depositManager * deposit.Manager
9394 withdrawalManager * withdraw.Manager
95+ staticLoopInManager * loopin.Manager
9496 swaps map [lntypes.Hash ]loop.SwapInfo
9597 subscribers map [int ]chan <- interface {}
9698 statusChan chan loop.SwapInfo
@@ -1461,6 +1463,45 @@ func (s *swapClientServer) GetStaticAddressSummary(ctx context.Context,
14611463 )
14621464}
14631465
1466+ // StaticAddressLoopIn initiates a loop-in request using static address
1467+ // deposits.
1468+ func (s * swapClientServer ) StaticAddressLoopIn (_ context.Context ,
1469+ in * clientrpc.StaticAddressLoopInRequest ) (
1470+ * clientrpc.StaticAddressLoopInResponse , error ) {
1471+
1472+ log .Infof ("Static loop-in request received" )
1473+
1474+ routeHints , err := unmarshallRouteHints (in .RouteHints )
1475+ if err != nil {
1476+ return nil , err
1477+ }
1478+
1479+ var lastHop route.Vertex
1480+ if in .LastHop != nil {
1481+ lastHop , err = route .NewVertexFromBytes (in .LastHop )
1482+ if err != nil {
1483+ return nil , err
1484+ }
1485+ }
1486+
1487+ req := & loop.StaticAddressLoopInRequest {
1488+ DepositOutpoints : in .Outpoints ,
1489+ MaxSwapFee : btcutil .Amount (in .MaxSwapFee ),
1490+ LastHop : & lastHop ,
1491+ Label : in .Label ,
1492+ Initiator : in .Initiator ,
1493+ Private : in .Private ,
1494+ RouteHints : routeHints ,
1495+ }
1496+
1497+ err = s .staticLoopInManager .InitiateLoopIn (req )
1498+ if err != nil {
1499+ return nil , err
1500+ }
1501+
1502+ return & clientrpc.StaticAddressLoopInResponse {}, nil
1503+ }
1504+
14641505func (s * swapClientServer ) depositSummary (ctx context.Context ,
14651506 deposits []* deposit.Deposit , stateFilter clientrpc.DepositState ,
14661507 outpointsFilter []string ) (* clientrpc.StaticAddressSummaryResponse ,
@@ -1472,6 +1513,8 @@ func (s *swapClientServer) depositSummary(ctx context.Context,
14721513 valueDeposited int64
14731514 valueExpired int64
14741515 valueWithdrawn int64
1516+ valueLoopedIn int64
1517+ htlcTimeoutSwept int64
14751518 )
14761519
14771520 // Value unconfirmed.
@@ -1497,6 +1540,12 @@ func (s *swapClientServer) depositSummary(ctx context.Context,
14971540
14981541 case deposit .Withdrawn :
14991542 valueWithdrawn += value
1543+
1544+ case deposit .LoopedIn :
1545+ valueLoopedIn += value
1546+
1547+ case deposit .HtlcTimeoutSwept :
1548+ htlcTimeoutSwept += value
15001549 }
15011550 }
15021551
@@ -1525,7 +1574,7 @@ func (s *swapClientServer) depositSummary(ctx context.Context,
15251574 return true
15261575 }
15271576
1528- return d .GetState () == toServerState (stateFilter )
1577+ return d .IsInState ( toServerState (stateFilter ) )
15291578 }
15301579 clientDeposits = filter (deposits , f )
15311580 }
@@ -1543,13 +1592,15 @@ func (s *swapClientServer) depositSummary(ctx context.Context,
15431592 }
15441593
15451594 return & clientrpc.StaticAddressSummaryResponse {
1546- StaticAddress : address .String (),
1547- TotalNumDeposits : uint32 (totalNumDeposits ),
1548- ValueUnconfirmed : valueUnconfirmed ,
1549- ValueDeposited : valueDeposited ,
1550- ValueExpired : valueExpired ,
1551- ValueWithdrawn : valueWithdrawn ,
1552- FilteredDeposits : clientDeposits ,
1595+ StaticAddress : address .String (),
1596+ TotalNumDeposits : uint32 (totalNumDeposits ),
1597+ ValueUnconfirmed : valueUnconfirmed ,
1598+ ValueDeposited : valueDeposited ,
1599+ ValueExpired : valueExpired ,
1600+ ValueWithdrawn : valueWithdrawn ,
1601+ ValueLoopedIn : valueLoopedIn ,
1602+ ValueHtlcTimeoutSweeps : htlcTimeoutSwept ,
1603+ FilteredDeposits : clientDeposits ,
15531604 }, nil
15541605}
15551606
@@ -1592,6 +1643,18 @@ func toClientState(state fsm.StateType) clientrpc.DepositState {
15921643 case deposit .PublishExpiredDeposit :
15931644 return clientrpc .DepositState_PUBLISH_EXPIRED
15941645
1646+ case deposit .LoopingIn :
1647+ return clientrpc .DepositState_LOOPING_IN
1648+
1649+ case deposit .LoopedIn :
1650+ return clientrpc .DepositState_LOOPED_IN
1651+
1652+ case deposit .SweepHtlcTimout :
1653+ return clientrpc .DepositState_SWEEP_HTLC_TIMEOUT
1654+
1655+ case deposit .HtlcTimeoutSwept :
1656+ return clientrpc .DepositState_HTLC_TIMEOUT_SWEPT
1657+
15951658 case deposit .WaitForExpirySweep :
15961659 return clientrpc .DepositState_WAIT_FOR_EXPIRY_SWEEP
15971660
@@ -1617,6 +1680,18 @@ func toServerState(state clientrpc.DepositState) fsm.StateType {
16171680 case clientrpc .DepositState_WITHDRAWN :
16181681 return deposit .Withdrawn
16191682
1683+ case clientrpc .DepositState_LOOPING_IN :
1684+ return deposit .LoopingIn
1685+
1686+ case clientrpc .DepositState_LOOPED_IN :
1687+ return deposit .LoopedIn
1688+
1689+ case clientrpc .DepositState_SWEEP_HTLC_TIMEOUT :
1690+ return deposit .SweepHtlcTimout
1691+
1692+ case clientrpc .DepositState_HTLC_TIMEOUT_SWEPT :
1693+ return deposit .HtlcTimeoutSwept
1694+
16201695 case clientrpc .DepositState_PUBLISH_EXPIRED :
16211696 return deposit .PublishExpiredDeposit
16221697
0 commit comments