contractcourt: decouple waitForHeight from commit sweep resolver
To make it usable from other resolvers.
This commit is contained in:
parent
65e50f6952
commit
5f613147ad
@ -10,6 +10,7 @@ import (
|
|||||||
"github.com/btcsuite/btcd/txscript"
|
"github.com/btcsuite/btcd/txscript"
|
||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/btcsuite/btcutil"
|
"github.com/btcsuite/btcutil"
|
||||||
|
"github.com/lightningnetwork/lnd/chainntnfs"
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
"github.com/lightningnetwork/lnd/channeldb"
|
||||||
"github.com/lightningnetwork/lnd/input"
|
"github.com/lightningnetwork/lnd/input"
|
||||||
"github.com/lightningnetwork/lnd/lnwallet"
|
"github.com/lightningnetwork/lnd/lnwallet"
|
||||||
@ -79,10 +80,12 @@ func (c *commitSweepResolver) ResolverKey() []byte {
|
|||||||
|
|
||||||
// waitForHeight registers for block notifications and waits for the provided
|
// waitForHeight registers for block notifications and waits for the provided
|
||||||
// block height to be reached.
|
// block height to be reached.
|
||||||
func (c *commitSweepResolver) waitForHeight(waitHeight uint32) error {
|
func waitForHeight(waitHeight uint32, notifier chainntnfs.ChainNotifier,
|
||||||
|
quit <-chan struct{}) error {
|
||||||
|
|
||||||
// Register for block epochs. After registration, the current height
|
// Register for block epochs. After registration, the current height
|
||||||
// will be sent on the channel immediately.
|
// will be sent on the channel immediately.
|
||||||
blockEpochs, err := c.Notifier.RegisterBlockEpochNtfn(nil)
|
blockEpochs, err := notifier.RegisterBlockEpochNtfn(nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -99,7 +102,7 @@ func (c *commitSweepResolver) waitForHeight(waitHeight uint32) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
case <-c.quit:
|
case <-quit:
|
||||||
return errResolverShuttingDown
|
return errResolverShuttingDown
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -169,7 +172,7 @@ func (c *commitSweepResolver) Resolve() (ContractResolver, error) {
|
|||||||
|
|
||||||
// We only need to wait for the block before the block that
|
// We only need to wait for the block before the block that
|
||||||
// unlocks the spend path.
|
// unlocks the spend path.
|
||||||
err := c.waitForHeight(unlockHeight - 1)
|
err := waitForHeight(unlockHeight-1, c.Notifier, c.quit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user