@@ -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,44 @@ 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+ req := & loop.StaticAddressLoopInRequest {
1480+ DepositOutpoints : in .Outpoints ,
1481+ MaxSwapFee : btcutil .Amount (in .MaxSwapFee ),
1482+ Label : in .Label ,
1483+ Initiator : in .Initiator ,
1484+ Private : in .Private ,
1485+ RouteHints : routeHints ,
1486+ }
1487+
1488+ if in .LastHop != nil {
1489+ lastHop , err := route .NewVertexFromBytes (in .LastHop )
1490+ if err != nil {
1491+ return nil , err
1492+ }
1493+ req .LastHop = & lastHop
1494+ }
1495+
1496+ err = s .staticLoopInManager .InitiateLoopIn (req )
1497+ if err != nil {
1498+ return nil , err
1499+ }
1500+
1501+ return & clientrpc.StaticAddressLoopInResponse {}, nil
1502+ }
1503+
14641504func (s * swapClientServer ) depositSummary (ctx context.Context ,
14651505 deposits []* deposit.Deposit , stateFilter clientrpc.DepositState ,
14661506 outpointsFilter []string ) (* clientrpc.StaticAddressSummaryResponse ,
@@ -1472,6 +1512,8 @@ func (s *swapClientServer) depositSummary(ctx context.Context,
14721512 valueDeposited int64
14731513 valueExpired int64
14741514 valueWithdrawn int64
1515+ valueLoopedIn int64
1516+ htlcTimeoutSwept int64
14751517 )
14761518
14771519 // Value unconfirmed.
@@ -1497,6 +1539,12 @@ func (s *swapClientServer) depositSummary(ctx context.Context,
14971539
14981540 case deposit .Withdrawn :
14991541 valueWithdrawn += value
1542+
1543+ case deposit .LoopedIn :
1544+ valueLoopedIn += value
1545+
1546+ case deposit .HtlcTimeoutSwept :
1547+ htlcTimeoutSwept += value
15001548 }
15011549 }
15021550
@@ -1525,7 +1573,7 @@ func (s *swapClientServer) depositSummary(ctx context.Context,
15251573 return true
15261574 }
15271575
1528- return d .GetState () == toServerState (stateFilter )
1576+ return d .IsInState ( toServerState (stateFilter ) )
15291577 }
15301578 clientDeposits = filter (deposits , f )
15311579 }
@@ -1543,13 +1591,15 @@ func (s *swapClientServer) depositSummary(ctx context.Context,
15431591 }
15441592
15451593 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 ,
1594+ StaticAddress : address .String (),
1595+ TotalNumDeposits : uint32 (totalNumDeposits ),
1596+ ValueUnconfirmed : valueUnconfirmed ,
1597+ ValueDeposited : valueDeposited ,
1598+ ValueExpired : valueExpired ,
1599+ ValueWithdrawn : valueWithdrawn ,
1600+ ValueLoopedIn : valueLoopedIn ,
1601+ ValueHtlcTimeoutSweeps : htlcTimeoutSwept ,
1602+ FilteredDeposits : clientDeposits ,
15531603 }, nil
15541604}
15551605
@@ -1592,6 +1642,18 @@ func toClientState(state fsm.StateType) clientrpc.DepositState {
15921642 case deposit .PublishExpiredDeposit :
15931643 return clientrpc .DepositState_PUBLISH_EXPIRED
15941644
1645+ case deposit .LoopingIn :
1646+ return clientrpc .DepositState_LOOPING_IN
1647+
1648+ case deposit .LoopedIn :
1649+ return clientrpc .DepositState_LOOPED_IN
1650+
1651+ case deposit .SweepHtlcTimeout :
1652+ return clientrpc .DepositState_SWEEP_HTLC_TIMEOUT
1653+
1654+ case deposit .HtlcTimeoutSwept :
1655+ return clientrpc .DepositState_HTLC_TIMEOUT_SWEPT
1656+
15951657 case deposit .WaitForExpirySweep :
15961658 return clientrpc .DepositState_WAIT_FOR_EXPIRY_SWEEP
15971659
@@ -1617,6 +1679,18 @@ func toServerState(state clientrpc.DepositState) fsm.StateType {
16171679 case clientrpc .DepositState_WITHDRAWN :
16181680 return deposit .Withdrawn
16191681
1682+ case clientrpc .DepositState_LOOPING_IN :
1683+ return deposit .LoopingIn
1684+
1685+ case clientrpc .DepositState_LOOPED_IN :
1686+ return deposit .LoopedIn
1687+
1688+ case clientrpc .DepositState_SWEEP_HTLC_TIMEOUT :
1689+ return deposit .SweepHtlcTimeout
1690+
1691+ case clientrpc .DepositState_HTLC_TIMEOUT_SWEPT :
1692+ return deposit .HtlcTimeoutSwept
1693+
16201694 case clientrpc .DepositState_PUBLISH_EXPIRED :
16211695 return deposit .PublishExpiredDeposit
16221696
0 commit comments