Skip to content

Commit 37a6235

Browse files
committed
staticaddr: get deposit block height from lnd client
1 parent af503bd commit 37a6235

File tree

2 files changed

+11
-38
lines changed

2 files changed

+11
-38
lines changed

loopd/daemon.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,7 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
606606
ChainParams: d.lnd.ChainParams,
607607
ChainNotifier: d.lnd.ChainNotifier,
608608
Signer: d.lnd.Signer,
609+
LndClient: d.lnd.Client,
609610
}
610611
depositManager = deposit.NewManager(depoCfg)
611612

staticaddr/deposit/manager.go

Lines changed: 10 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ type ManagerConfig struct {
6868

6969
// Signer is the signer client that is used to sign transactions.
7070
Signer lndclient.SignerClient
71+
72+
// LndClient is used to add invoices and select hop hints.
73+
LndClient lndclient.LightningClient
7174
}
7275

7376
// Manager manages the address state machines.
@@ -280,11 +283,6 @@ func (m *Manager) reconcileDeposits(ctx context.Context) error {
280283
func (m *Manager) createNewDeposit(ctx context.Context,
281284
utxo *lnwallet.Utxo) (*Deposit, error) {
282285

283-
blockHeight, err := m.getBlockHeight(ctx, utxo)
284-
if err != nil {
285-
return nil, err
286-
}
287-
288286
// Get the sweep pk script.
289287
addr, err := m.cfg.WalletKit.NextAddr(
290288
ctx, lnwallet.DefaultAccountName,
@@ -303,12 +301,18 @@ func (m *Manager) createNewDeposit(ctx context.Context,
303301
if err != nil {
304302
return nil, err
305303
}
304+
305+
info, err := m.cfg.LndClient.GetInfo(ctx)
306+
if err != nil {
307+
return nil, err
308+
}
309+
306310
deposit := &Deposit{
307311
ID: id,
308312
state: Deposited,
309313
OutPoint: utxo.OutPoint,
310314
Value: utxo.Value,
311-
ConfirmationHeight: int64(blockHeight),
315+
ConfirmationHeight: int64(info.BlockHeight),
312316
TimeOutSweepPkScript: timeoutSweepPkScript,
313317
}
314318

@@ -324,38 +328,6 @@ func (m *Manager) createNewDeposit(ctx context.Context,
324328
return deposit, nil
325329
}
326330

327-
// getBlockHeight retrieves the block height of a given utxo.
328-
func (m *Manager) getBlockHeight(ctx context.Context,
329-
utxo *lnwallet.Utxo) (uint32, error) {
330-
331-
addressParams, err := m.cfg.AddressManager.GetStaticAddressParameters(
332-
ctx,
333-
)
334-
if err != nil {
335-
return 0, fmt.Errorf("couldn't get confirmation height for "+
336-
"deposit, %w", err)
337-
}
338-
339-
notifChan, errChan, err := m.cfg.ChainNotifier.RegisterConfirmationsNtfn( //nolint:lll
340-
ctx, &utxo.OutPoint.Hash, addressParams.PkScript, MinConfs,
341-
int32(m.initiationHeight),
342-
)
343-
if err != nil {
344-
return 0, err
345-
}
346-
347-
select {
348-
case tx := <-notifChan:
349-
return tx.BlockHeight, nil
350-
351-
case err := <-errChan:
352-
return 0, err
353-
354-
case <-ctx.Done():
355-
return 0, ctx.Err()
356-
}
357-
}
358-
359331
// filterNewDeposits filters the given utxos for new deposits that we haven't
360332
// seen before.
361333
func (m *Manager) filterNewDeposits(utxos []*lnwallet.Utxo) []*lnwallet.Utxo {

0 commit comments

Comments
 (0)