@@ -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
@@ -1458,6 +1460,52 @@ func (s *swapClientServer) GetStaticAddressSummary(ctx context.Context,
14581460 )
14591461}
14601462
1463+ // StaticAddressLoopIn initiates a loop-in request using static address
1464+ // deposits.
1465+ func (s * swapClientServer ) StaticAddressLoopIn (ctx context.Context ,
1466+ in * looprpc.StaticAddressLoopInRequest ) (
1467+ * looprpc.StaticAddressLoopInResponse , error ) {
1468+
1469+ log .Infof ("Static loop-in request received" )
1470+
1471+ routeHints , err := unmarshallRouteHints (in .RouteHints )
1472+ if err != nil {
1473+ return nil , err
1474+ }
1475+
1476+ req := & loop.StaticAddressLoopInRequest {
1477+ DepositOutpoints : in .Outpoints ,
1478+ MaxSwapFee : btcutil .Amount (in .MaxSwapFeeSatoshis ),
1479+ Label : in .Label ,
1480+ Initiator : in .Initiator ,
1481+ Private : in .Private ,
1482+ RouteHints : routeHints ,
1483+ PaymentTimeoutSeconds : in .PaymentTimeoutSeconds ,
1484+ }
1485+
1486+ if in .LastHop != nil {
1487+ lastHop , err := route .NewVertexFromBytes (in .LastHop )
1488+ if err != nil {
1489+ return nil , err
1490+ }
1491+ req .LastHop = & lastHop
1492+ }
1493+
1494+ errChan := s .staticLoopInManager .DeliverLoopInRequest (ctx , req )
1495+ select {
1496+ case err = <- errChan :
1497+
1498+ case <- ctx .Done ():
1499+ err = ctx .Err ()
1500+ }
1501+
1502+ if err != nil {
1503+ return nil , err
1504+ }
1505+
1506+ return & looprpc.StaticAddressLoopInResponse {}, nil
1507+ }
1508+
14611509func (s * swapClientServer ) depositSummary (ctx context.Context ,
14621510 deposits []* deposit.Deposit , stateFilter looprpc.DepositState ,
14631511 outpointsFilter []string ) (* looprpc.StaticAddressSummaryResponse ,
@@ -1469,6 +1517,8 @@ func (s *swapClientServer) depositSummary(ctx context.Context,
14691517 valueDeposited int64
14701518 valueExpired int64
14711519 valueWithdrawn int64
1520+ valueLoopedIn int64
1521+ htlcTimeoutSwept int64
14721522 )
14731523
14741524 // Value unconfirmed.
@@ -1494,6 +1544,12 @@ func (s *swapClientServer) depositSummary(ctx context.Context,
14941544
14951545 case deposit .Withdrawn :
14961546 valueWithdrawn += value
1547+
1548+ case deposit .LoopedIn :
1549+ valueLoopedIn += value
1550+
1551+ case deposit .HtlcTimeoutSwept :
1552+ htlcTimeoutSwept += value
14971553 }
14981554 }
14991555
@@ -1522,7 +1578,7 @@ func (s *swapClientServer) depositSummary(ctx context.Context,
15221578 return true
15231579 }
15241580
1525- return d .GetState () == toServerState (stateFilter )
1581+ return d .IsInState ( toServerState (stateFilter ) )
15261582 }
15271583 clientDeposits = filter (deposits , f )
15281584 }
@@ -1540,13 +1596,15 @@ func (s *swapClientServer) depositSummary(ctx context.Context,
15401596 }
15411597
15421598 return & looprpc.StaticAddressSummaryResponse {
1543- StaticAddress : address .String (),
1544- TotalNumDeposits : uint32 (totalNumDeposits ),
1545- ValueUnconfirmedSatoshis : valueUnconfirmed ,
1546- ValueDepositedSatoshis : valueDeposited ,
1547- ValueExpiredSatoshis : valueExpired ,
1548- ValueWithdrawnSatoshis : valueWithdrawn ,
1549- FilteredDeposits : clientDeposits ,
1599+ StaticAddress : address .String (),
1600+ TotalNumDeposits : uint32 (totalNumDeposits ),
1601+ ValueUnconfirmedSatoshis : valueUnconfirmed ,
1602+ ValueDepositedSatoshis : valueDeposited ,
1603+ ValueExpiredSatoshis : valueExpired ,
1604+ ValueWithdrawnSatoshis : valueWithdrawn ,
1605+ ValueLoopedInSatoshis : valueLoopedIn ,
1606+ ValueHtlcTimeoutSweepsSatoshis : htlcTimeoutSwept ,
1607+ FilteredDeposits : clientDeposits ,
15501608 }, nil
15511609}
15521610
@@ -1589,6 +1647,18 @@ func toClientState(state fsm.StateType) looprpc.DepositState {
15891647 case deposit .PublishExpirySweep :
15901648 return looprpc .DepositState_PUBLISH_EXPIRED
15911649
1650+ case deposit .LoopingIn :
1651+ return looprpc .DepositState_LOOPING_IN
1652+
1653+ case deposit .LoopedIn :
1654+ return looprpc .DepositState_LOOPED_IN
1655+
1656+ case deposit .SweepHtlcTimeout :
1657+ return looprpc .DepositState_SWEEP_HTLC_TIMEOUT
1658+
1659+ case deposit .HtlcTimeoutSwept :
1660+ return looprpc .DepositState_HTLC_TIMEOUT_SWEPT
1661+
15921662 case deposit .WaitForExpirySweep :
15931663 return looprpc .DepositState_WAIT_FOR_EXPIRY_SWEEP
15941664
@@ -1617,6 +1687,18 @@ func toServerState(state looprpc.DepositState) fsm.StateType {
16171687 case looprpc .DepositState_PUBLISH_EXPIRED :
16181688 return deposit .PublishExpirySweep
16191689
1690+ case looprpc .DepositState_LOOPING_IN :
1691+ return deposit .LoopingIn
1692+
1693+ case looprpc .DepositState_LOOPED_IN :
1694+ return deposit .LoopedIn
1695+
1696+ case looprpc .DepositState_SWEEP_HTLC_TIMEOUT :
1697+ return deposit .SweepHtlcTimeout
1698+
1699+ case looprpc .DepositState_HTLC_TIMEOUT_SWEPT :
1700+ return deposit .HtlcTimeoutSwept
1701+
16201702 case looprpc .DepositState_WAIT_FOR_EXPIRY_SWEEP :
16211703 return deposit .WaitForExpirySweep
16221704
0 commit comments