mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-10-10 17:23:16 +02:00
multi: move Input interface and related code
This commit is a step to split the lnwallet package. It puts the Input interface and implementations in a separate package along with all their dependencies from lnwallet.
This commit is contained in:
@@ -8,8 +8,6 @@ import (
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/lightningnetwork/lnd/sweep"
|
||||
|
||||
"github.com/btcsuite/btcd/txscript"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/btcsuite/btcutil"
|
||||
@@ -17,7 +15,9 @@ import (
|
||||
|
||||
"github.com/lightningnetwork/lnd/chainntnfs"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/lightningnetwork/lnd/input"
|
||||
"github.com/lightningnetwork/lnd/lnwallet"
|
||||
"github.com/lightningnetwork/lnd/sweep"
|
||||
)
|
||||
|
||||
// SUMMARY OF OUTPUT STATES
|
||||
@@ -196,7 +196,7 @@ type NurseryConfig struct {
|
||||
Store NurseryStore
|
||||
|
||||
// Sweep sweeps an input back to the wallet.
|
||||
SweepInput func(input sweep.Input) (chan sweep.Result, error)
|
||||
SweepInput func(input input.Input) (chan sweep.Result, error)
|
||||
}
|
||||
|
||||
// utxoNursery is a system dedicated to incubating time-locked outputs created
|
||||
@@ -368,7 +368,7 @@ func (u *utxoNursery) IncubateOutputs(chanPoint wire.OutPoint,
|
||||
&commitResolution.SelfOutPoint,
|
||||
&chanPoint,
|
||||
commitResolution.MaturityDelay,
|
||||
lnwallet.CommitmentTimeLock,
|
||||
input.CommitmentTimeLock,
|
||||
&commitResolution.SelfOutputSignDesc,
|
||||
0,
|
||||
)
|
||||
@@ -389,7 +389,7 @@ func (u *utxoNursery) IncubateOutputs(chanPoint wire.OutPoint,
|
||||
for _, htlcRes := range incomingHtlcs {
|
||||
htlcOutput := makeKidOutput(
|
||||
&htlcRes.ClaimOutpoint, &chanPoint, htlcRes.CsvDelay,
|
||||
lnwallet.HtlcAcceptedSuccessSecondLevel,
|
||||
input.HtlcAcceptedSuccessSecondLevel,
|
||||
&htlcRes.SweepSignDesc, 0,
|
||||
)
|
||||
|
||||
@@ -421,7 +421,7 @@ func (u *utxoNursery) IncubateOutputs(chanPoint wire.OutPoint,
|
||||
// indicate this is actually a CLTV output.
|
||||
htlcOutput := makeKidOutput(
|
||||
&htlcRes.ClaimOutpoint, &chanPoint, 0,
|
||||
lnwallet.HtlcOfferedRemoteTimeout,
|
||||
input.HtlcOfferedRemoteTimeout,
|
||||
&htlcRes.SweepSignDesc, htlcRes.Expiry,
|
||||
)
|
||||
kidOutputs = append(kidOutputs, htlcOutput)
|
||||
@@ -533,13 +533,13 @@ func (u *utxoNursery) NurseryReport(
|
||||
// Preschool outputs are awaiting the
|
||||
// confirmation of the commitment transaction.
|
||||
switch kid.WitnessType() {
|
||||
case lnwallet.CommitmentTimeLock:
|
||||
case input.CommitmentTimeLock:
|
||||
report.AddLimboCommitment(&kid)
|
||||
|
||||
// An HTLC output on our commitment transaction
|
||||
// where the second-layer transaction hasn't
|
||||
// yet confirmed.
|
||||
case lnwallet.HtlcAcceptedSuccessSecondLevel:
|
||||
case input.HtlcAcceptedSuccessSecondLevel:
|
||||
report.AddLimboStage1SuccessHtlc(&kid)
|
||||
}
|
||||
|
||||
@@ -549,13 +549,13 @@ func (u *utxoNursery) NurseryReport(
|
||||
// We can distinguish them via their witness
|
||||
// types.
|
||||
switch kid.WitnessType() {
|
||||
case lnwallet.CommitmentTimeLock:
|
||||
case input.CommitmentTimeLock:
|
||||
// The commitment transaction has been
|
||||
// confirmed, and we are waiting the CSV
|
||||
// delay to expire.
|
||||
report.AddLimboCommitment(&kid)
|
||||
|
||||
case lnwallet.HtlcOfferedRemoteTimeout:
|
||||
case input.HtlcOfferedRemoteTimeout:
|
||||
// This is an HTLC output on the
|
||||
// commitment transaction of the remote
|
||||
// party. The CLTV timelock has
|
||||
@@ -563,9 +563,9 @@ func (u *utxoNursery) NurseryReport(
|
||||
// it.
|
||||
report.AddLimboDirectHtlc(&kid)
|
||||
|
||||
case lnwallet.HtlcAcceptedSuccessSecondLevel:
|
||||
case input.HtlcAcceptedSuccessSecondLevel:
|
||||
fallthrough
|
||||
case lnwallet.HtlcOfferedTimeoutSecondLevel:
|
||||
case input.HtlcOfferedTimeoutSecondLevel:
|
||||
// The htlc timeout or success
|
||||
// transaction has confirmed, and the
|
||||
// CSV delay has begun ticking.
|
||||
@@ -578,17 +578,17 @@ func (u *utxoNursery) NurseryReport(
|
||||
// will contribute towards the recovered
|
||||
// balance.
|
||||
switch kid.WitnessType() {
|
||||
case lnwallet.CommitmentTimeLock:
|
||||
case input.CommitmentTimeLock:
|
||||
// The commitment output was
|
||||
// successfully swept back into a
|
||||
// regular p2wkh output.
|
||||
report.AddRecoveredCommitment(&kid)
|
||||
|
||||
case lnwallet.HtlcAcceptedSuccessSecondLevel:
|
||||
case input.HtlcAcceptedSuccessSecondLevel:
|
||||
fallthrough
|
||||
case lnwallet.HtlcOfferedTimeoutSecondLevel:
|
||||
case input.HtlcOfferedTimeoutSecondLevel:
|
||||
fallthrough
|
||||
case lnwallet.HtlcOfferedRemoteTimeout:
|
||||
case input.HtlcOfferedRemoteTimeout:
|
||||
// This htlc output successfully
|
||||
// resides in a p2wkh output belonging
|
||||
// to the user.
|
||||
@@ -1301,7 +1301,7 @@ func makeBabyOutput(chanPoint *wire.OutPoint,
|
||||
|
||||
htlcOutpoint := htlcResolution.ClaimOutpoint
|
||||
blocksToMaturity := htlcResolution.CsvDelay
|
||||
witnessType := lnwallet.HtlcOfferedTimeoutSecondLevel
|
||||
witnessType := input.HtlcOfferedTimeoutSecondLevel
|
||||
|
||||
kid := makeKidOutput(
|
||||
&htlcOutpoint, chanPoint, blocksToMaturity, witnessType,
|
||||
@@ -1380,15 +1380,15 @@ type kidOutput struct {
|
||||
}
|
||||
|
||||
func makeKidOutput(outpoint, originChanPoint *wire.OutPoint,
|
||||
blocksToMaturity uint32, witnessType lnwallet.WitnessType,
|
||||
signDescriptor *lnwallet.SignDescriptor,
|
||||
blocksToMaturity uint32, witnessType input.WitnessType,
|
||||
signDescriptor *input.SignDescriptor,
|
||||
absoluteMaturity uint32) kidOutput {
|
||||
|
||||
// This is an HTLC either if it's an incoming HTLC on our commitment
|
||||
// transaction, or is an outgoing HTLC on the commitment transaction of
|
||||
// the remote peer.
|
||||
isHtlc := (witnessType == lnwallet.HtlcAcceptedSuccessSecondLevel ||
|
||||
witnessType == lnwallet.HtlcOfferedRemoteTimeout)
|
||||
isHtlc := (witnessType == input.HtlcAcceptedSuccessSecondLevel ||
|
||||
witnessType == input.HtlcOfferedRemoteTimeout)
|
||||
|
||||
// heightHint can be safely set to zero here, because after this
|
||||
// function returns, nursery will set a proper confirmation height in
|
||||
@@ -1464,7 +1464,7 @@ func (k *kidOutput) Encode(w io.Writer) error {
|
||||
return err
|
||||
}
|
||||
|
||||
return lnwallet.WriteSignDescriptor(w, k.SignDesc())
|
||||
return input.WriteSignDescriptor(w, k.SignDesc())
|
||||
}
|
||||
|
||||
// Decode takes a byte array representation of a kidOutput and converts it to an
|
||||
@@ -1509,9 +1509,9 @@ func (k *kidOutput) Decode(r io.Reader) error {
|
||||
if _, err := r.Read(scratch[:2]); err != nil {
|
||||
return err
|
||||
}
|
||||
k.witnessType = lnwallet.WitnessType(byteOrder.Uint16(scratch[:2]))
|
||||
k.witnessType = input.WitnessType(byteOrder.Uint16(scratch[:2]))
|
||||
|
||||
return lnwallet.ReadSignDescriptor(r, &k.signDesc)
|
||||
return input.ReadSignDescriptor(r, &k.signDesc)
|
||||
}
|
||||
|
||||
// TODO(bvu): copied from channeldb, remove repetition
|
||||
@@ -1551,4 +1551,4 @@ func readOutpoint(r io.Reader, o *wire.OutPoint) error {
|
||||
// Compile-time constraint to ensure kidOutput implements the
|
||||
// Input interface.
|
||||
|
||||
var _ sweep.Input = (*kidOutput)(nil)
|
||||
var _ input.Input = (*kidOutput)(nil)
|
||||
|
Reference in New Issue
Block a user