mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-10-11 04:53:02 +02:00
multi: move payment related code into own package
This commit moves most of the code into its own package. It is the smallest code move possible without moving import cycles and keeping the changes to the code base as small as possible during refactor.
This commit is contained in:
@@ -252,7 +252,7 @@ type initArgs struct {
|
||||
}
|
||||
|
||||
type registerAttemptArgs struct {
|
||||
a *channeldb.HTLCAttemptInfo
|
||||
a *paymentsdb.HTLCAttemptInfo
|
||||
}
|
||||
|
||||
type settleAttemptArgs struct {
|
||||
@@ -260,7 +260,7 @@ type settleAttemptArgs struct {
|
||||
}
|
||||
|
||||
type failAttemptArgs struct {
|
||||
reason *channeldb.HTLCFailInfo
|
||||
reason *paymentsdb.HTLCFailInfo
|
||||
}
|
||||
|
||||
type failPaymentArgs struct {
|
||||
@@ -269,7 +269,7 @@ type failPaymentArgs struct {
|
||||
|
||||
type testPayment struct {
|
||||
info channeldb.PaymentCreationInfo
|
||||
attempts []channeldb.HTLCAttempt
|
||||
attempts []paymentsdb.HTLCAttempt
|
||||
}
|
||||
|
||||
type mockControlTowerOld struct {
|
||||
@@ -355,7 +355,7 @@ func (m *mockControlTowerOld) DeleteFailedAttempts(phash lntypes.Hash) error {
|
||||
}
|
||||
|
||||
func (m *mockControlTowerOld) RegisterAttempt(phash lntypes.Hash,
|
||||
a *channeldb.HTLCAttemptInfo) error {
|
||||
a *paymentsdb.HTLCAttemptInfo) error {
|
||||
|
||||
if m.registerAttempt != nil {
|
||||
m.registerAttempt <- registerAttemptArgs{a}
|
||||
@@ -400,7 +400,7 @@ func (m *mockControlTowerOld) RegisterAttempt(phash lntypes.Hash,
|
||||
}
|
||||
|
||||
// Add attempt to payment.
|
||||
p.attempts = append(p.attempts, channeldb.HTLCAttempt{
|
||||
p.attempts = append(p.attempts, paymentsdb.HTLCAttempt{
|
||||
HTLCAttemptInfo: *a,
|
||||
})
|
||||
m.payments[phash] = p
|
||||
@@ -409,8 +409,8 @@ func (m *mockControlTowerOld) RegisterAttempt(phash lntypes.Hash,
|
||||
}
|
||||
|
||||
func (m *mockControlTowerOld) SettleAttempt(phash lntypes.Hash,
|
||||
pid uint64, settleInfo *channeldb.HTLCSettleInfo) (
|
||||
*channeldb.HTLCAttempt, error) {
|
||||
pid uint64, settleInfo *paymentsdb.HTLCSettleInfo) (
|
||||
*paymentsdb.HTLCAttempt, error) {
|
||||
|
||||
if m.settleAttempt != nil {
|
||||
m.settleAttempt <- settleAttemptArgs{settleInfo.Preimage}
|
||||
@@ -442,7 +442,7 @@ func (m *mockControlTowerOld) SettleAttempt(phash lntypes.Hash,
|
||||
|
||||
// Mark the payment successful on first settled attempt.
|
||||
m.successful[phash] = struct{}{}
|
||||
return &channeldb.HTLCAttempt{
|
||||
return &paymentsdb.HTLCAttempt{
|
||||
Settle: settleInfo,
|
||||
}, nil
|
||||
}
|
||||
@@ -451,7 +451,7 @@ func (m *mockControlTowerOld) SettleAttempt(phash lntypes.Hash,
|
||||
}
|
||||
|
||||
func (m *mockControlTowerOld) FailAttempt(phash lntypes.Hash, pid uint64,
|
||||
failInfo *channeldb.HTLCFailInfo) (*channeldb.HTLCAttempt, error) {
|
||||
failInfo *paymentsdb.HTLCFailInfo) (*paymentsdb.HTLCAttempt, error) {
|
||||
|
||||
if m.failAttempt != nil {
|
||||
m.failAttempt <- failAttemptArgs{failInfo}
|
||||
@@ -480,7 +480,7 @@ func (m *mockControlTowerOld) FailAttempt(phash lntypes.Hash, pid uint64,
|
||||
}
|
||||
|
||||
p.attempts[i].Failure = failInfo
|
||||
return &channeldb.HTLCAttempt{
|
||||
return &paymentsdb.HTLCAttempt{
|
||||
Failure: failInfo,
|
||||
}, nil
|
||||
}
|
||||
@@ -518,14 +518,14 @@ func (m *mockControlTowerOld) FetchPayment(phash lntypes.Hash) (
|
||||
}
|
||||
|
||||
func (m *mockControlTowerOld) fetchPayment(phash lntypes.Hash) (
|
||||
*channeldb.MPPayment, error) {
|
||||
*paymentsdb.MPPayment, error) {
|
||||
|
||||
p, ok := m.payments[phash]
|
||||
if !ok {
|
||||
return nil, paymentsdb.ErrPaymentNotInitiated
|
||||
}
|
||||
|
||||
mp := &channeldb.MPPayment{
|
||||
mp := &paymentsdb.MPPayment{
|
||||
Info: &p.info,
|
||||
}
|
||||
|
||||
@@ -545,7 +545,7 @@ func (m *mockControlTowerOld) fetchPayment(phash lntypes.Hash) (
|
||||
}
|
||||
|
||||
func (m *mockControlTowerOld) FetchInFlightPayments() (
|
||||
[]*channeldb.MPPayment, error) {
|
||||
[]*paymentsdb.MPPayment, error) {
|
||||
|
||||
if m.fetchInFlight != nil {
|
||||
m.fetchInFlight <- struct{}{}
|
||||
@@ -555,7 +555,7 @@ func (m *mockControlTowerOld) FetchInFlightPayments() (
|
||||
defer m.Unlock()
|
||||
|
||||
// In flight are all payments not successful or failed.
|
||||
var fl []*channeldb.MPPayment
|
||||
var fl []*paymentsdb.MPPayment
|
||||
for hash := range m.payments {
|
||||
if _, ok := m.successful[hash]; ok {
|
||||
continue
|
||||
@@ -745,15 +745,15 @@ func (m *mockControlTower) DeleteFailedAttempts(phash lntypes.Hash) error {
|
||||
}
|
||||
|
||||
func (m *mockControlTower) RegisterAttempt(phash lntypes.Hash,
|
||||
a *channeldb.HTLCAttemptInfo) error {
|
||||
a *paymentsdb.HTLCAttemptInfo) error {
|
||||
|
||||
args := m.Called(phash, a)
|
||||
return args.Error(0)
|
||||
}
|
||||
|
||||
func (m *mockControlTower) SettleAttempt(phash lntypes.Hash,
|
||||
pid uint64, settleInfo *channeldb.HTLCSettleInfo) (
|
||||
*channeldb.HTLCAttempt, error) {
|
||||
pid uint64, settleInfo *paymentsdb.HTLCSettleInfo) (
|
||||
*paymentsdb.HTLCAttempt, error) {
|
||||
|
||||
args := m.Called(phash, pid, settleInfo)
|
||||
|
||||
@@ -762,11 +762,11 @@ func (m *mockControlTower) SettleAttempt(phash lntypes.Hash,
|
||||
return nil, args.Error(1)
|
||||
}
|
||||
|
||||
return attempt.(*channeldb.HTLCAttempt), args.Error(1)
|
||||
return attempt.(*paymentsdb.HTLCAttempt), args.Error(1)
|
||||
}
|
||||
|
||||
func (m *mockControlTower) FailAttempt(phash lntypes.Hash, pid uint64,
|
||||
failInfo *channeldb.HTLCFailInfo) (*channeldb.HTLCAttempt, error) {
|
||||
failInfo *paymentsdb.HTLCFailInfo) (*paymentsdb.HTLCAttempt, error) {
|
||||
|
||||
args := m.Called(phash, pid, failInfo)
|
||||
|
||||
@@ -775,7 +775,7 @@ func (m *mockControlTower) FailAttempt(phash lntypes.Hash, pid uint64,
|
||||
return nil, args.Error(1)
|
||||
}
|
||||
|
||||
return args.Get(0).(*channeldb.HTLCAttempt), args.Error(1)
|
||||
return attempt.(*paymentsdb.HTLCAttempt), args.Error(1)
|
||||
}
|
||||
|
||||
func (m *mockControlTower) FailPayment(phash lntypes.Hash,
|
||||
@@ -800,10 +800,10 @@ func (m *mockControlTower) FetchPayment(phash lntypes.Hash) (
|
||||
}
|
||||
|
||||
func (m *mockControlTower) FetchInFlightPayments() (
|
||||
[]*channeldb.MPPayment, error) {
|
||||
[]*paymentsdb.MPPayment, error) {
|
||||
|
||||
args := m.Called()
|
||||
return args.Get(0).([]*channeldb.MPPayment), args.Error(1)
|
||||
return args.Get(0).([]*paymentsdb.MPPayment), args.Error(1)
|
||||
}
|
||||
|
||||
func (m *mockControlTower) SubscribePayment(paymentHash lntypes.Hash) (
|
||||
@@ -826,14 +826,14 @@ type mockMPPayment struct {
|
||||
|
||||
var _ DBMPPayment = (*mockMPPayment)(nil)
|
||||
|
||||
func (m *mockMPPayment) GetState() *channeldb.MPPaymentState {
|
||||
func (m *mockMPPayment) GetState() *paymentsdb.MPPaymentState {
|
||||
args := m.Called()
|
||||
return args.Get(0).(*channeldb.MPPaymentState)
|
||||
return args.Get(0).(*paymentsdb.MPPaymentState)
|
||||
}
|
||||
|
||||
func (m *mockMPPayment) GetStatus() channeldb.PaymentStatus {
|
||||
func (m *mockMPPayment) GetStatus() paymentsdb.PaymentStatus {
|
||||
args := m.Called()
|
||||
return args.Get(0).(channeldb.PaymentStatus)
|
||||
return args.Get(0).(paymentsdb.PaymentStatus)
|
||||
}
|
||||
|
||||
func (m *mockMPPayment) Terminated() bool {
|
||||
@@ -847,14 +847,14 @@ func (m *mockMPPayment) NeedWaitAttempts() (bool, error) {
|
||||
return args.Bool(0), args.Error(1)
|
||||
}
|
||||
|
||||
func (m *mockMPPayment) GetHTLCs() []channeldb.HTLCAttempt {
|
||||
func (m *mockMPPayment) GetHTLCs() []paymentsdb.HTLCAttempt {
|
||||
args := m.Called()
|
||||
return args.Get(0).([]channeldb.HTLCAttempt)
|
||||
return args.Get(0).([]paymentsdb.HTLCAttempt)
|
||||
}
|
||||
|
||||
func (m *mockMPPayment) InFlightHTLCs() []channeldb.HTLCAttempt {
|
||||
func (m *mockMPPayment) InFlightHTLCs() []paymentsdb.HTLCAttempt {
|
||||
args := m.Called()
|
||||
return args.Get(0).([]channeldb.HTLCAttempt)
|
||||
return args.Get(0).([]paymentsdb.HTLCAttempt)
|
||||
}
|
||||
|
||||
func (m *mockMPPayment) AllowMoreAttempts() (bool, error) {
|
||||
@@ -862,19 +862,19 @@ func (m *mockMPPayment) AllowMoreAttempts() (bool, error) {
|
||||
return args.Bool(0), args.Error(1)
|
||||
}
|
||||
|
||||
func (m *mockMPPayment) TerminalInfo() (*channeldb.HTLCAttempt,
|
||||
func (m *mockMPPayment) TerminalInfo() (*paymentsdb.HTLCAttempt,
|
||||
*channeldb.FailureReason) {
|
||||
|
||||
args := m.Called()
|
||||
|
||||
var (
|
||||
settleInfo *channeldb.HTLCAttempt
|
||||
settleInfo *paymentsdb.HTLCAttempt
|
||||
failureInfo *channeldb.FailureReason
|
||||
)
|
||||
|
||||
settle := args.Get(0)
|
||||
if settle != nil {
|
||||
settleInfo = settle.(*channeldb.HTLCAttempt)
|
||||
settleInfo = settle.(*paymentsdb.HTLCAttempt)
|
||||
}
|
||||
|
||||
reason := args.Get(1)
|
||||
|
Reference in New Issue
Block a user