multi: create channeldb/models package

Add a new subpackage to `lnd/channeldb` to hold some of the types that
are used in the package itself and in other packages that should not
depend on `channeldb`.
This commit is contained in:
positiveblue
2022-11-18 03:15:22 -08:00
parent c602ac07e7
commit 383cb40f8d
29 changed files with 400 additions and 315 deletions

View File

@@ -3,7 +3,7 @@ package invoices
import (
"time"
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/channeldb/models"
"github.com/lightningnetwork/lnd/lntypes"
)
@@ -11,14 +11,14 @@ import (
type HtlcResolution interface {
// CircuitKey returns the circuit key for the htlc that we have a
// resolution for.
CircuitKey() channeldb.CircuitKey
CircuitKey() models.CircuitKey
}
// HtlcFailResolution is an implementation of the HtlcResolution interface
// which is returned when a htlc is failed.
type HtlcFailResolution struct {
// circuitKey is the key of the htlc for which we have a resolution.
circuitKey channeldb.CircuitKey
circuitKey models.CircuitKey
// AcceptHeight is the original height at which the htlc was accepted.
AcceptHeight int32
@@ -28,8 +28,8 @@ type HtlcFailResolution struct {
}
// NewFailResolution returns a htlc failure resolution.
func NewFailResolution(key channeldb.CircuitKey,
acceptHeight int32, outcome FailResolutionResult) *HtlcFailResolution {
func NewFailResolution(key models.CircuitKey, acceptHeight int32,
outcome FailResolutionResult) *HtlcFailResolution {
return &HtlcFailResolution{
circuitKey: key,
@@ -42,7 +42,7 @@ func NewFailResolution(key channeldb.CircuitKey,
// resolution for.
//
// Note: it is part of the HtlcResolution interface.
func (f *HtlcFailResolution) CircuitKey() channeldb.CircuitKey {
func (f *HtlcFailResolution) CircuitKey() models.CircuitKey {
return f.circuitKey
}
@@ -53,7 +53,7 @@ type HtlcSettleResolution struct {
Preimage lntypes.Preimage
// circuitKey is the key of the htlc for which we have a resolution.
circuitKey channeldb.CircuitKey
circuitKey models.CircuitKey
// acceptHeight is the original height at which the htlc was accepted.
AcceptHeight int32
@@ -65,7 +65,7 @@ type HtlcSettleResolution struct {
// NewSettleResolution returns a htlc resolution which is associated with a
// settle.
func NewSettleResolution(preimage lntypes.Preimage,
key channeldb.CircuitKey, acceptHeight int32,
key models.CircuitKey, acceptHeight int32,
outcome SettleResolutionResult) *HtlcSettleResolution {
return &HtlcSettleResolution{
@@ -80,7 +80,7 @@ func NewSettleResolution(preimage lntypes.Preimage,
// resolution for.
//
// Note: it is part of the HtlcResolution interface.
func (s *HtlcSettleResolution) CircuitKey() channeldb.CircuitKey {
func (s *HtlcSettleResolution) CircuitKey() models.CircuitKey {
return s.circuitKey
}
@@ -92,7 +92,7 @@ func (s *HtlcSettleResolution) CircuitKey() channeldb.CircuitKey {
// acceptResolution, a nil resolution should be surfaced.
type htlcAcceptResolution struct {
// circuitKey is the key of the htlc for which we have a resolution.
circuitKey channeldb.CircuitKey
circuitKey models.CircuitKey
// autoRelease signals that the htlc should be automatically released
// after a timeout.
@@ -107,7 +107,7 @@ type htlcAcceptResolution struct {
// newAcceptResolution returns a htlc resolution which is associated with a
// htlc accept.
func newAcceptResolution(key channeldb.CircuitKey,
func newAcceptResolution(key models.CircuitKey,
outcome acceptResolutionResult) *htlcAcceptResolution {
return &htlcAcceptResolution{
@@ -120,6 +120,6 @@ func newAcceptResolution(key channeldb.CircuitKey,
// resolution for.
//
// Note: it is part of the HtlcResolution interface.
func (a *htlcAcceptResolution) CircuitKey() channeldb.CircuitKey {
func (a *htlcAcceptResolution) CircuitKey() models.CircuitKey {
return a.circuitKey
}