@@ -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,42 @@ 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+ s .staticLoopInManager .DeliverLoopInRequest (ctx , req )
1495+
1496+ return & looprpc.StaticAddressLoopInResponse {}, nil
1497+ }
1498+
14611499func (s * swapClientServer ) depositSummary (ctx context.Context ,
14621500 deposits []* deposit.Deposit , stateFilter looprpc.DepositState ,
14631501 outpointsFilter []string ) (* looprpc.StaticAddressSummaryResponse ,
@@ -1469,6 +1507,8 @@ func (s *swapClientServer) depositSummary(ctx context.Context,
14691507 valueDeposited int64
14701508 valueExpired int64
14711509 valueWithdrawn int64
1510+ valueLoopedIn int64
1511+ htlcTimeoutSwept int64
14721512 )
14731513
14741514 // Value unconfirmed.
@@ -1494,6 +1534,12 @@ func (s *swapClientServer) depositSummary(ctx context.Context,
14941534
14951535 case deposit .Withdrawn :
14961536 valueWithdrawn += value
1537+
1538+ case deposit .LoopedIn :
1539+ valueLoopedIn += value
1540+
1541+ case deposit .HtlcTimeoutSwept :
1542+ htlcTimeoutSwept += value
14971543 }
14981544 }
14991545
@@ -1522,7 +1568,7 @@ func (s *swapClientServer) depositSummary(ctx context.Context,
15221568 return true
15231569 }
15241570
1525- return d .GetState () == toServerState (stateFilter )
1571+ return d .IsInState ( toServerState (stateFilter ) )
15261572 }
15271573 clientDeposits = filter (deposits , f )
15281574 }
@@ -1540,13 +1586,15 @@ func (s *swapClientServer) depositSummary(ctx context.Context,
15401586 }
15411587
15421588 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 ,
1589+ StaticAddress : address .String (),
1590+ TotalNumDeposits : uint32 (totalNumDeposits ),
1591+ ValueUnconfirmedSatoshis : valueUnconfirmed ,
1592+ ValueDepositedSatoshis : valueDeposited ,
1593+ ValueExpiredSatoshis : valueExpired ,
1594+ ValueWithdrawnSatoshis : valueWithdrawn ,
1595+ ValueLoopedInSatoshis : valueLoopedIn ,
1596+ ValueHtlcTimeoutSweepsSatoshis : htlcTimeoutSwept ,
1597+ FilteredDeposits : clientDeposits ,
15501598 }, nil
15511599}
15521600
@@ -1589,6 +1637,18 @@ func toClientState(state fsm.StateType) looprpc.DepositState {
15891637 case deposit .PublishExpirySweep :
15901638 return looprpc .DepositState_PUBLISH_EXPIRED
15911639
1640+ case deposit .LoopingIn :
1641+ return looprpc .DepositState_LOOPING_IN
1642+
1643+ case deposit .LoopedIn :
1644+ return looprpc .DepositState_LOOPED_IN
1645+
1646+ case deposit .SweepHtlcTimeout :
1647+ return looprpc .DepositState_SWEEP_HTLC_TIMEOUT
1648+
1649+ case deposit .HtlcTimeoutSwept :
1650+ return looprpc .DepositState_HTLC_TIMEOUT_SWEPT
1651+
15921652 case deposit .WaitForExpirySweep :
15931653 return looprpc .DepositState_WAIT_FOR_EXPIRY_SWEEP
15941654
@@ -1617,6 +1677,18 @@ func toServerState(state looprpc.DepositState) fsm.StateType {
16171677 case looprpc .DepositState_PUBLISH_EXPIRED :
16181678 return deposit .PublishExpirySweep
16191679
1680+ case looprpc .DepositState_LOOPING_IN :
1681+ return deposit .LoopingIn
1682+
1683+ case looprpc .DepositState_LOOPED_IN :
1684+ return deposit .LoopedIn
1685+
1686+ case looprpc .DepositState_SWEEP_HTLC_TIMEOUT :
1687+ return deposit .SweepHtlcTimeout
1688+
1689+ case looprpc .DepositState_HTLC_TIMEOUT_SWEPT :
1690+ return deposit .HtlcTimeoutSwept
1691+
16201692 case looprpc .DepositState_WAIT_FOR_EXPIRY_SWEEP :
16211693 return deposit .WaitForExpirySweep
16221694
0 commit comments