Skip to content

Commit 614d619

Browse files
committed
loopd: retrieve historic withdrawal info
1 parent 5718f11 commit 614d619

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

loopd/daemon.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,10 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
604604
depositManager = deposit.NewManager(depoCfg)
605605

606606
// Static address deposit withdrawal manager setup.
607+
withdrawalStore := withdraw.NewSqlStore(
608+
loopdb.NewTypedStore[withdraw.Querier](baseDb),
609+
depositStore,
610+
)
607611
withdrawalCfg := &withdraw.ManagerConfig{
608612
StaticAddressServerClient: staticAddressClient,
609613
AddressManager: staticAddressManager,
@@ -612,6 +616,7 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
612616
ChainParams: d.lnd.ChainParams,
613617
ChainNotifier: d.lnd.ChainNotifier,
614618
Signer: d.lnd.Signer,
619+
Store: withdrawalStore,
615620
}
616621
withdrawalManager = withdraw.NewManager(withdrawalCfg, blockHeight)
617622

loopd/swapclient_server.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1673,6 +1673,53 @@ func (s *swapClientServer) ListStaticAddressDeposits(ctx context.Context,
16731673
}, nil
16741674
}
16751675

1676+
// ListStaticAddressWithdrawals returns a list of all finalized withdrawal
1677+
// transactions.
1678+
func (s *swapClientServer) ListStaticAddressWithdrawals(ctx context.Context,
1679+
_ *looprpc.ListStaticAddressWithdrawalRequest) (
1680+
*looprpc.ListStaticAddressWithdrawalResponse, error) {
1681+
1682+
withdrawals, err := s.withdrawalManager.GetAllWithdrawals(ctx)
1683+
if err != nil {
1684+
return nil, err
1685+
}
1686+
1687+
if len(withdrawals) == 0 {
1688+
return &looprpc.ListStaticAddressWithdrawalResponse{}, nil
1689+
}
1690+
1691+
clientWithdrawals := make(
1692+
[]*looprpc.StaticAddressWithdrawal, 0, len(withdrawals),
1693+
)
1694+
for _, w := range withdrawals {
1695+
deposits := make([]*looprpc.Deposit, 0, len(w.Deposits))
1696+
for _, d := range w.Deposits {
1697+
deposits = append(deposits, &looprpc.Deposit{
1698+
Id: d.ID[:],
1699+
Outpoint: d.OutPoint.String(),
1700+
Value: int64(d.Value),
1701+
ConfirmationHeight: d.ConfirmationHeight,
1702+
State: toClientDepositState(
1703+
d.GetState(),
1704+
),
1705+
})
1706+
}
1707+
withdrawal := &looprpc.StaticAddressWithdrawal{
1708+
TxId: w.TxID.String(),
1709+
Deposits: deposits,
1710+
TotalDepositAmountSatoshis: int64(w.TotalDepositAmount),
1711+
WithdrawnAmountSatoshis: int64(w.WithdrawnAmount),
1712+
ChangeAmountSatoshis: int64(w.ChangeAmount),
1713+
ConfirmationHeight: uint32(w.ConfirmationHeight),
1714+
}
1715+
clientWithdrawals = append(clientWithdrawals, withdrawal)
1716+
}
1717+
1718+
return &looprpc.ListStaticAddressWithdrawalResponse{
1719+
Withdrawals: clientWithdrawals,
1720+
}, nil
1721+
}
1722+
16761723
// ListStaticAddressSwaps returns a list of all swaps that are currently pending
16771724
// or previously succeeded.
16781725
func (s *swapClientServer) ListStaticAddressSwaps(ctx context.Context,

0 commit comments

Comments
 (0)