@@ -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
@@ -1461,6 +1463,42 @@ 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 (ctx context.Context ,
1469+ in * looprpc.StaticAddressLoopInRequest ) (
1470+ * looprpc.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 .MaxSwapFeeSatoshis ),
1482+ Label : in .Label ,
1483+ Initiator : in .Initiator ,
1484+ Private : in .Private ,
1485+ RouteHints : routeHints ,
1486+ PaymentTimeoutSeconds : in .PaymentTimeoutSeconds ,
1487+ }
1488+
1489+ if in .LastHop != nil {
1490+ lastHop , err := route .NewVertexFromBytes (in .LastHop )
1491+ if err != nil {
1492+ return nil , err
1493+ }
1494+ req .LastHop = & lastHop
1495+ }
1496+
1497+ s .staticLoopInManager .DeliverLoopInRequest (ctx , req )
1498+
1499+ return & looprpc.StaticAddressLoopInResponse {}, nil
1500+ }
1501+
14641502func (s * swapClientServer ) depositSummary (ctx context.Context ,
14651503 deposits []* deposit.Deposit , stateFilter looprpc.DepositState ,
14661504 outpointsFilter []string ) (* looprpc.StaticAddressSummaryResponse ,
@@ -1472,6 +1510,8 @@ func (s *swapClientServer) depositSummary(ctx context.Context,
14721510 valueDeposited int64
14731511 valueExpired int64
14741512 valueWithdrawn int64
1513+ valueLoopedIn int64
1514+ htlcTimeoutSwept int64
14751515 )
14761516
14771517 // Value unconfirmed.
@@ -1497,6 +1537,12 @@ func (s *swapClientServer) depositSummary(ctx context.Context,
14971537
14981538 case deposit .Withdrawn :
14991539 valueWithdrawn += value
1540+
1541+ case deposit .LoopedIn :
1542+ valueLoopedIn += value
1543+
1544+ case deposit .HtlcTimeoutSwept :
1545+ htlcTimeoutSwept += value
15001546 }
15011547 }
15021548
@@ -1525,7 +1571,7 @@ func (s *swapClientServer) depositSummary(ctx context.Context,
15251571 return true
15261572 }
15271573
1528- return d .GetState () == toServerState (stateFilter )
1574+ return d .IsInState ( toServerState (stateFilter ) )
15291575 }
15301576 clientDeposits = filter (deposits , f )
15311577 }
@@ -1543,13 +1589,15 @@ func (s *swapClientServer) depositSummary(ctx context.Context,
15431589 }
15441590
15451591 return & looprpc.StaticAddressSummaryResponse {
1546- StaticAddress : address .String (),
1547- TotalNumDeposits : uint32 (totalNumDeposits ),
1548- ValueUnconfirmedSatoshis : valueUnconfirmed ,
1549- ValueDepositedSatoshis : valueDeposited ,
1550- ValueExpiredSatoshis : valueExpired ,
1551- ValueWithdrawnSatoshis : valueWithdrawn ,
1552- FilteredDeposits : clientDeposits ,
1592+ StaticAddress : address .String (),
1593+ TotalNumDeposits : uint32 (totalNumDeposits ),
1594+ ValueUnconfirmedSatoshis : valueUnconfirmed ,
1595+ ValueDepositedSatoshis : valueDeposited ,
1596+ ValueExpiredSatoshis : valueExpired ,
1597+ ValueWithdrawnSatoshis : valueWithdrawn ,
1598+ ValueLoopedInSatoshis : valueLoopedIn ,
1599+ ValueHtlcTimeoutSweepsSatoshis : htlcTimeoutSwept ,
1600+ FilteredDeposits : clientDeposits ,
15531601 }, nil
15541602}
15551603
@@ -1592,6 +1640,18 @@ func toClientState(state fsm.StateType) looprpc.DepositState {
15921640 case deposit .PublishExpirySweep :
15931641 return looprpc .DepositState_PUBLISH_EXPIRED
15941642
1643+ case deposit .LoopingIn :
1644+ return looprpc .DepositState_LOOPING_IN
1645+
1646+ case deposit .LoopedIn :
1647+ return looprpc .DepositState_LOOPED_IN
1648+
1649+ case deposit .SweepHtlcTimeout :
1650+ return looprpc .DepositState_SWEEP_HTLC_TIMEOUT
1651+
1652+ case deposit .HtlcTimeoutSwept :
1653+ return looprpc .DepositState_HTLC_TIMEOUT_SWEPT
1654+
15951655 case deposit .WaitForExpirySweep :
15961656 return looprpc .DepositState_WAIT_FOR_EXPIRY_SWEEP
15971657
@@ -1620,6 +1680,18 @@ func toServerState(state looprpc.DepositState) fsm.StateType {
16201680 case looprpc .DepositState_PUBLISH_EXPIRED :
16211681 return deposit .PublishExpirySweep
16221682
1683+ case looprpc .DepositState_LOOPING_IN :
1684+ return deposit .LoopingIn
1685+
1686+ case looprpc .DepositState_LOOPED_IN :
1687+ return deposit .LoopedIn
1688+
1689+ case looprpc .DepositState_SWEEP_HTLC_TIMEOUT :
1690+ return deposit .SweepHtlcTimeout
1691+
1692+ case looprpc .DepositState_HTLC_TIMEOUT_SWEPT :
1693+ return deposit .HtlcTimeoutSwept
1694+
16231695 case looprpc .DepositState_WAIT_FOR_EXPIRY_SWEEP :
16241696 return deposit .WaitForExpirySweep
16251697
0 commit comments