lnwallet+peer: move internalKeyForAddr to lnwallet package

This way we can re-use it. We also make it slightly more generalized.
This commit is contained in:
Olaoluwa Osuntokun committed 2024-10-02 18:09:52 -07:00
1 parent f74d1ce53b
commit e0ced8e629
5 files changed
+160 -79

No files matched your search

+3 -3
View File
@@ -318,7 +318,7 @@ type UtxoSweeper struct {
type UtxoSweeperConfig struct {
// GenSweepScript generates a P2WKH script belonging to the wallet where
// funds can be swept.
GenSweepScript func() ([]byte, error)
GenSweepScript func() fn.Result[lnwallet.AddrWithKey]
// FeeEstimator is used when crafting sweep transactions to estimate
// the necessary fee relative to the expected size of the sweep
@@ -803,11 +803,11 @@ func (s *UtxoSweeper) signalResult(pi *SweeperInput, result Result) {
func (s *UtxoSweeper) sweep(set InputSet) error {
// Generate an output script if there isn't an unused script available.
if s.currentOutputScript == nil {
pkScript, err := s.cfg.GenSweepScript()
pkScript, err := s.cfg.GenSweepScript().Unpack()
if err != nil {
return fmt.Errorf("gen sweep script: %w", err)
}
s.currentOutputScript = pkScript
s.currentOutputScript = pkScript.DeliveryAddress
}
// Create a fee bump request and ask the publisher to broadcast it. The
+6 -2
View File
@@ -12,6 +12,7 @@ import (
"github.com/lightningnetwork/lnd/chainntnfs"
"github.com/lightningnetwork/lnd/fn"
"github.com/lightningnetwork/lnd/input"
"github.com/lightningnetwork/lnd/lnwallet"
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
@@ -667,8 +668,11 @@ func TestSweepPendingInputs(t *testing.T) {
Wallet: wallet,
Aggregator: aggregator,
Publisher: publisher,
GenSweepScript: func() ([]byte, error) {
return testPubKey.SerializeCompressed(), nil
GenSweepScript: func() fn.Result[lnwallet.AddrWithKey] {
//nolint:lll
return fn.Ok(lnwallet.AddrWithKey{
DeliveryAddress: testPubKey.SerializeCompressed(),
})
},
NoDeadlineConfTarget: uint32(DefaultDeadlineDelta),
})