@@ -28,6 +28,7 @@ import (
2828 "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 "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
@@ -1464,6 +1466,52 @@ func (s *swapClientServer) GetStaticAddressSummary(ctx context.Context,
14641466 )
14651467}
14661468
1469+ // StaticAddressLoopIn initiates a loop-in request using static address
1470+ // deposits.
1471+ func (s * swapClientServer ) StaticAddressLoopIn (ctx context.Context ,
1472+ in * looprpc.StaticAddressLoopInRequest ) (
1473+ * looprpc.StaticAddressLoopInResponse , error ) {
1474+
1475+ log .Infof ("Static loop-in request received" )
1476+
1477+ routeHints , err := unmarshallRouteHints (in .RouteHints )
1478+ if err != nil {
1479+ return nil , err
1480+ }
1481+
1482+ req := & loop.StaticAddressLoopInRequest {
1483+ DepositOutpoints : in .Outpoints ,
1484+ MaxSwapFee : btcutil .Amount (in .MaxSwapFeeSatoshis ),
1485+ Label : in .Label ,
1486+ Initiator : in .Initiator ,
1487+ Private : in .Private ,
1488+ RouteHints : routeHints ,
1489+ PaymentTimeoutSeconds : in .PaymentTimeoutSeconds ,
1490+ }
1491+
1492+ if in .LastHop != nil {
1493+ lastHop , err := route .NewVertexFromBytes (in .LastHop )
1494+ if err != nil {
1495+ return nil , err
1496+ }
1497+ req .LastHop = & lastHop
1498+ }
1499+
1500+ errChan := s .staticLoopInManager .DeliverLoopInRequest (ctx , req )
1501+ select {
1502+ case err = <- errChan :
1503+
1504+ case <- ctx .Done ():
1505+ err = ctx .Err ()
1506+ }
1507+
1508+ if err != nil {
1509+ return nil , err
1510+ }
1511+
1512+ return & looprpc.StaticAddressLoopInResponse {}, nil
1513+ }
1514+
14671515func (s * swapClientServer ) depositSummary (ctx context.Context ,
14681516 deposits []* deposit.Deposit , stateFilter looprpc.DepositState ,
14691517 outpointsFilter []string ) (* looprpc.StaticAddressSummaryResponse ,
@@ -1475,6 +1523,8 @@ func (s *swapClientServer) depositSummary(ctx context.Context,
14751523 valueDeposited int64
14761524 valueExpired int64
14771525 valueWithdrawn int64
1526+ valueLoopedIn int64
1527+ htlcTimeoutSwept int64
14781528 )
14791529
14801530 // Value unconfirmed.
@@ -1500,6 +1550,12 @@ func (s *swapClientServer) depositSummary(ctx context.Context,
15001550
15011551 case deposit .Withdrawn :
15021552 valueWithdrawn += value
1553+
1554+ case deposit .LoopedIn :
1555+ valueLoopedIn += value
1556+
1557+ case deposit .HtlcTimeoutSwept :
1558+ htlcTimeoutSwept += value
15031559 }
15041560 }
15051561
@@ -1528,7 +1584,7 @@ func (s *swapClientServer) depositSummary(ctx context.Context,
15281584 return true
15291585 }
15301586
1531- return d .GetState () == toServerState (stateFilter )
1587+ return d .IsInState ( toServerState (stateFilter ) )
15321588 }
15331589 clientDeposits = filter (deposits , f )
15341590 }
@@ -1546,13 +1602,15 @@ func (s *swapClientServer) depositSummary(ctx context.Context,
15461602 }
15471603
15481604 return & looprpc.StaticAddressSummaryResponse {
1549- StaticAddress : address .String (),
1550- TotalNumDeposits : uint32 (totalNumDeposits ),
1551- ValueUnconfirmedSatoshis : valueUnconfirmed ,
1552- ValueDepositedSatoshis : valueDeposited ,
1553- ValueExpiredSatoshis : valueExpired ,
1554- ValueWithdrawnSatoshis : valueWithdrawn ,
1555- FilteredDeposits : clientDeposits ,
1605+ StaticAddress : address .String (),
1606+ TotalNumDeposits : uint32 (totalNumDeposits ),
1607+ ValueUnconfirmedSatoshis : valueUnconfirmed ,
1608+ ValueDepositedSatoshis : valueDeposited ,
1609+ ValueExpiredSatoshis : valueExpired ,
1610+ ValueWithdrawnSatoshis : valueWithdrawn ,
1611+ ValueLoopedInSatoshis : valueLoopedIn ,
1612+ ValueHtlcTimeoutSweepsSatoshis : htlcTimeoutSwept ,
1613+ FilteredDeposits : clientDeposits ,
15561614 }, nil
15571615}
15581616
@@ -1595,6 +1653,18 @@ func toClientState(state fsm.StateType) looprpc.DepositState {
15951653 case deposit .PublishExpirySweep :
15961654 return looprpc .DepositState_PUBLISH_EXPIRED
15971655
1656+ case deposit .LoopingIn :
1657+ return looprpc .DepositState_LOOPING_IN
1658+
1659+ case deposit .LoopedIn :
1660+ return looprpc .DepositState_LOOPED_IN
1661+
1662+ case deposit .SweepHtlcTimeout :
1663+ return looprpc .DepositState_SWEEP_HTLC_TIMEOUT
1664+
1665+ case deposit .HtlcTimeoutSwept :
1666+ return looprpc .DepositState_HTLC_TIMEOUT_SWEPT
1667+
15981668 case deposit .WaitForExpirySweep :
15991669 return looprpc .DepositState_WAIT_FOR_EXPIRY_SWEEP
16001670
@@ -1623,6 +1693,18 @@ func toServerState(state looprpc.DepositState) fsm.StateType {
16231693 case looprpc .DepositState_PUBLISH_EXPIRED :
16241694 return deposit .PublishExpirySweep
16251695
1696+ case looprpc .DepositState_LOOPING_IN :
1697+ return deposit .LoopingIn
1698+
1699+ case looprpc .DepositState_LOOPED_IN :
1700+ return deposit .LoopedIn
1701+
1702+ case looprpc .DepositState_SWEEP_HTLC_TIMEOUT :
1703+ return deposit .SweepHtlcTimeout
1704+
1705+ case looprpc .DepositState_HTLC_TIMEOUT_SWEPT :
1706+ return deposit .HtlcTimeoutSwept
1707+
16261708 case looprpc .DepositState_WAIT_FOR_EXPIRY_SWEEP :
16271709 return deposit .WaitForExpirySweep
16281710
0 commit comments