utxonursery: configure using SweepInput function

As a preparation for mocking sweeper, this commit modifies the
utxonursery config to take a function pointer instead of the full
sweeper struct.
This commit is contained in:
Joost Jager
2018-12-19 12:49:01 +01:00
parent 2f17030e8c
commit 74e9852e3d
3 changed files with 8 additions and 9 deletions

View File

@ -636,7 +636,7 @@ func newServer(listenAddrs []net.Addr, chanDB *channeldb.DB, cc *chainControl,
Notifier: cc.chainNotifier, Notifier: cc.chainNotifier,
PublishTransaction: cc.wallet.PublishTransaction, PublishTransaction: cc.wallet.PublishTransaction,
Store: utxnStore, Store: utxnStore,
Sweeper: s.sweeper, SweepInput: s.sweeper.SweepInput,
}) })
// Construct a closure that wraps the htlcswitch's CloseLink method. // Construct a closure that wraps the htlcswitch's CloseLink method.

View File

@ -195,9 +195,8 @@ type NurseryConfig struct {
// maintained about the utxo nursery's incubating outputs. // maintained about the utxo nursery's incubating outputs.
Store NurseryStore Store NurseryStore
// Sweeper provides functionality to generate sweep transactions. // Sweep sweeps an input back to the wallet.
// Nursery uses this to sweep final outputs back into the wallet. SweepInput func(input sweep.Input) (chan sweep.Result, error)
Sweeper *sweep.UtxoSweeper
} }
// utxoNursery is a system dedicated to incubating time-locked outputs created // utxoNursery is a system dedicated to incubating time-locked outputs created
@ -803,7 +802,7 @@ func (u *utxoNursery) sweepMatureOutputs(classHeight uint32,
// passed in with disastruous consequences. // passed in with disastruous consequences.
local := output local := output
resultChan, err := u.cfg.Sweeper.SweepInput(&local) resultChan, err := u.cfg.SweepInput(&local)
if err != nil { if err != nil {
return err return err
} }

View File

@ -488,9 +488,9 @@ func createNurseryTestContext(t *testing.T,
CloseHeight: 0, CloseHeight: 0,
}, nil }, nil
}, },
Store: storeIntercepter, Store: storeIntercepter,
ChainIO: chainIO, ChainIO: chainIO,
Sweeper: sweeper, SweepInput: sweeper.SweepInput,
PublishTransaction: func(tx *wire.MsgTx) error { PublishTransaction: func(tx *wire.MsgTx) error {
return publishFunc(tx, "nursery") return publishFunc(tx, "nursery")
}, },
@ -556,7 +556,7 @@ func createNurseryTestContext(t *testing.T,
} }
/// Restart nursery. /// Restart nursery.
nurseryCfg.Sweeper = ctx.sweeper nurseryCfg.SweepInput = ctx.sweeper.SweepInput
ctx.nursery = newUtxoNursery(&nurseryCfg) ctx.nursery = newUtxoNursery(&nurseryCfg)
ctx.nursery.Start() ctx.nursery.Start()