server+utxonursery: generate pkscript closures
This commit moves the newSweepPkScript function previously in the nursery to be a helper function within the server. Additionally, the function now returns a closure that satisfies the configuration interfaces of several other subsystems. As a result, the configuration sites contain much less boilerplate, as it's now encapsulated in the newSweepPkScriptGen helper.
This commit is contained in:
parent
efcdefee39
commit
7c0a03c7c8
34
server.go
34
server.go
@ -20,6 +20,7 @@ import (
|
||||
"github.com/btcsuite/btcd/btcec"
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
"github.com/btcsuite/btcd/connmgr"
|
||||
"github.com/btcsuite/btcd/txscript"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/btcsuite/btcutil"
|
||||
"github.com/coreos/bbolt"
|
||||
@ -730,9 +731,7 @@ func newServer(listenAddrs []net.Addr, chanDB *channeldb.DB,
|
||||
|
||||
s.sweeper = sweep.New(&sweep.UtxoSweeperConfig{
|
||||
FeeEstimator: cc.feeEstimator,
|
||||
GenSweepScript: func() ([]byte, error) {
|
||||
return newSweepPkScript(cc.wallet)
|
||||
},
|
||||
GenSweepScript: newSweepPkScriptGen(cc.wallet),
|
||||
Signer: cc.wallet.Cfg.Signer,
|
||||
PublishTransaction: cc.wallet.PublishTransaction,
|
||||
NewBatchTimer: func() <-chan time.Time {
|
||||
@ -775,9 +774,7 @@ func newServer(listenAddrs []net.Addr, chanDB *channeldb.DB,
|
||||
ChainHash: *activeNetParams.GenesisHash,
|
||||
IncomingBroadcastDelta: DefaultIncomingBroadcastDelta,
|
||||
OutgoingBroadcastDelta: DefaultOutgoingBroadcastDelta,
|
||||
NewSweepAddr: func() ([]byte, error) {
|
||||
return newSweepPkScript(cc.wallet)
|
||||
},
|
||||
NewSweepAddr: newSweepPkScriptGen(cc.wallet),
|
||||
PublishTx: cc.wallet.PublishTransaction,
|
||||
DeliverResolutionMsg: func(msgs ...contractcourt.ResolutionMsg) error {
|
||||
for _, msg := range msgs {
|
||||
@ -854,9 +851,7 @@ func newServer(listenAddrs []net.Addr, chanDB *channeldb.DB,
|
||||
CloseLink: closeLink,
|
||||
DB: chanDB,
|
||||
Estimator: s.cc.feeEstimator,
|
||||
GenSweepScript: func() ([]byte, error) {
|
||||
return newSweepPkScript(cc.wallet)
|
||||
},
|
||||
GenSweepScript: newSweepPkScriptGen(cc.wallet),
|
||||
Notifier: cc.chainNotifier,
|
||||
PublishTransaction: cc.wallet.PublishTransaction,
|
||||
ContractBreaches: contractBreaches,
|
||||
@ -1076,9 +1071,7 @@ func newServer(listenAddrs []net.Addr, chanDB *channeldb.DB,
|
||||
|
||||
s.towerClient, err = wtclient.New(&wtclient.Config{
|
||||
Signer: cc.wallet.Cfg.Signer,
|
||||
NewAddress: func() ([]byte, error) {
|
||||
return newSweepPkScript(cc.wallet)
|
||||
},
|
||||
NewAddress: newSweepPkScriptGen(cc.wallet),
|
||||
SecretKeyRing: s.cc.keyRing,
|
||||
Dial: cfg.net.Dial,
|
||||
AuthDial: wtclient.AuthDial,
|
||||
@ -3233,3 +3226,20 @@ func (s *server) applyChannelUpdate(update *lnwire.ChannelUpdate) error {
|
||||
return ErrServerShuttingDown
|
||||
}
|
||||
}
|
||||
|
||||
// newSweepPkScriptGen creates closure that generates a new public key script
|
||||
// which should be used to sweep any funds into the on-chain wallet.
|
||||
// Specifically, the script generated is a version 0, pay-to-witness-pubkey-hash
|
||||
// (p2wkh) output.
|
||||
func newSweepPkScriptGen(
|
||||
wallet lnwallet.WalletController) func() ([]byte, error) {
|
||||
|
||||
return func() ([]byte, error) {
|
||||
sweepAddr, err := wallet.NewAddress(lnwallet.WitnessPubKey, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return txscript.PayToAddrScript(sweepAddr)
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ import (
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/btcsuite/btcd/txscript"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/btcsuite/btcutil"
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
@ -1231,19 +1230,6 @@ func (u *utxoNursery) closeAndRemoveIfMature(chanPoint *wire.OutPoint) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// newSweepPkScript creates a new public key script which should be used to
|
||||
// sweep any time-locked, or contested channel funds into the wallet.
|
||||
// Specifically, the script generated is a version 0, pay-to-witness-pubkey-hash
|
||||
// (p2wkh) output.
|
||||
func newSweepPkScript(wallet lnwallet.WalletController) ([]byte, error) {
|
||||
sweepAddr, err := wallet.NewAddress(lnwallet.WitnessPubKey, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return txscript.PayToAddrScript(sweepAddr)
|
||||
}
|
||||
|
||||
// babyOutput represents a two-stage CSV locked output, and is used to track
|
||||
// htlc outputs through incubation. The first stage requires broadcasting a
|
||||
// presigned timeout txn that spends from the CLTV locked output on the
|
||||
|
Loading…
Reference in New Issue
Block a user