watchtower: convert JusticeKit to interface
In this commit, we convert the `JusticeKit` struct to an interface. Then, we add two implementations of that interface: 1) The `legacyJusticeKit` which implements all the methods of `JusticeKit` 2) The `anchorJusticKit` which wraps the `legacyJusticeKit` and just re-implements the `ToRemoteOutputSpendInfo` method since.
This commit is contained in:
14 files changed
+666
-520
No files matched your search
@@ -172,3 +172,42 @@ func (c CommitmentType) ParseRawSig(witness wire.TxWitness) (lnwire.Sig,
|
||||
c)
|
||||
}
|
||||
}
|
||||
|
||||
// NewJusticeKit can be used to construct a new JusticeKit depending on the
|
||||
// CommitmentType.
|
||||
func (c CommitmentType) NewJusticeKit(sweepScript []byte,
|
||||
breachInfo *lnwallet.BreachRetribution, withToRemote bool) (JusticeKit,
|
||||
error) {
|
||||
|
||||
switch c {
|
||||
case LegacyCommitment, LegacyTweaklessCommitment:
|
||||
return newLegacyJusticeKit(
|
||||
sweepScript, breachInfo, withToRemote,
|
||||
), nil
|
||||
|
||||
case AnchorCommitment:
|
||||
return newAnchorJusticeKit(
|
||||
sweepScript, breachInfo, withToRemote,
|
||||
), nil
|
||||
|
||||
default:
|
||||
return nil, fmt.Errorf("unknown commitment type: %v", c)
|
||||
}
|
||||
}
|
||||
|
||||
// EmptyJusticeKit returns the appropriate empty justice kit for the given
|
||||
// CommitmentType.
|
||||
func (c CommitmentType) EmptyJusticeKit() (JusticeKit, error) {
|
||||
switch c {
|
||||
case LegacyTweaklessCommitment, LegacyCommitment:
|
||||
return &legacyJusticeKit{}, nil
|
||||
|
||||
case AnchorCommitment:
|
||||
return &anchorJusticeKit{
|
||||
legacyJusticeKit: legacyJusticeKit{},
|
||||
}, nil
|
||||
|
||||
default:
|
||||
return nil, fmt.Errorf("unknown commitment type: %v", c)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user