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:
26 files changed
+1075
-948
No files matched your search
@@ -22,6 +22,7 @@ import (
|
||||
"github.com/lightningnetwork/lnd/lnrpc"
|
||||
"github.com/lightningnetwork/lnd/lntypes"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
paymentsdb "github.com/lightningnetwork/lnd/payments/db"
|
||||
"github.com/lightningnetwork/lnd/record"
|
||||
"github.com/lightningnetwork/lnd/routing"
|
||||
"github.com/lightningnetwork/lnd/routing/route"
|
||||
@@ -1488,7 +1489,7 @@ func UnmarshalAMP(reqAMP *lnrpc.AMPRecord) (*record.AMP, error) {
|
||||
|
||||
// MarshalHTLCAttempt constructs an RPC HTLCAttempt from the db representation.
|
||||
func (r *RouterBackend) MarshalHTLCAttempt(
|
||||
htlc channeldb.HTLCAttempt) (*lnrpc.HTLCAttempt, error) {
|
||||
htlc paymentsdb.HTLCAttempt) (*lnrpc.HTLCAttempt, error) {
|
||||
|
||||
route, err := r.MarshallRoute(&htlc.Route)
|
||||
if err != nil {
|
||||
@@ -1529,7 +1530,7 @@ func (r *RouterBackend) MarshalHTLCAttempt(
|
||||
|
||||
// marshallHtlcFailure marshalls htlc fail info from the database to its rpc
|
||||
// representation.
|
||||
func marshallHtlcFailure(failure *channeldb.HTLCFailInfo) (*lnrpc.Failure,
|
||||
func marshallHtlcFailure(failure *paymentsdb.HTLCFailInfo) (*lnrpc.Failure,
|
||||
error) {
|
||||
|
||||
rpcFailure := &lnrpc.Failure{
|
||||
@@ -1537,16 +1538,16 @@ func marshallHtlcFailure(failure *channeldb.HTLCFailInfo) (*lnrpc.Failure,
|
||||
}
|
||||
|
||||
switch failure.Reason {
|
||||
case channeldb.HTLCFailUnknown:
|
||||
case paymentsdb.HTLCFailUnknown:
|
||||
rpcFailure.Code = lnrpc.Failure_UNKNOWN_FAILURE
|
||||
|
||||
case channeldb.HTLCFailUnreadable:
|
||||
case paymentsdb.HTLCFailUnreadable:
|
||||
rpcFailure.Code = lnrpc.Failure_UNREADABLE_FAILURE
|
||||
|
||||
case channeldb.HTLCFailInternal:
|
||||
case paymentsdb.HTLCFailInternal:
|
||||
rpcFailure.Code = lnrpc.Failure_INTERNAL_FAILURE
|
||||
|
||||
case channeldb.HTLCFailMessage:
|
||||
case paymentsdb.HTLCFailMessage:
|
||||
err := marshallWireError(failure.Message, rpcFailure)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -1743,7 +1744,7 @@ func marshallChannelUpdate(update *lnwire.ChannelUpdate1) *lnrpc.ChannelUpdate {
|
||||
}
|
||||
|
||||
// MarshallPayment marshall a payment to its rpc representation.
|
||||
func (r *RouterBackend) MarshallPayment(payment *channeldb.MPPayment) (
|
||||
func (r *RouterBackend) MarshallPayment(payment *paymentsdb.MPPayment) (
|
||||
*lnrpc.Payment, error) {
|
||||
|
||||
// Fetch the payment's preimage and the total paid in fees.
|
||||
@@ -1813,11 +1814,11 @@ func (r *RouterBackend) MarshallPayment(payment *channeldb.MPPayment) (
|
||||
|
||||
// convertPaymentStatus converts a channeldb.PaymentStatus to the type expected
|
||||
// by the RPC.
|
||||
func convertPaymentStatus(dbStatus channeldb.PaymentStatus, useInit bool) (
|
||||
func convertPaymentStatus(dbStatus paymentsdb.PaymentStatus, useInit bool) (
|
||||
lnrpc.Payment_PaymentStatus, error) {
|
||||
|
||||
switch dbStatus {
|
||||
case channeldb.StatusInitiated:
|
||||
case paymentsdb.StatusInitiated:
|
||||
// If the client understands the new status, return it.
|
||||
if useInit {
|
||||
return lnrpc.Payment_INITIATED, nil
|
||||
@@ -1826,13 +1827,13 @@ func convertPaymentStatus(dbStatus channeldb.PaymentStatus, useInit bool) (
|
||||
// Otherwise remain the old behavior.
|
||||
return lnrpc.Payment_IN_FLIGHT, nil
|
||||
|
||||
case channeldb.StatusInFlight:
|
||||
case paymentsdb.StatusInFlight:
|
||||
return lnrpc.Payment_IN_FLIGHT, nil
|
||||
|
||||
case channeldb.StatusSucceeded:
|
||||
case paymentsdb.StatusSucceeded:
|
||||
return lnrpc.Payment_SUCCEEDED, nil
|
||||
|
||||
case channeldb.StatusFailed:
|
||||
case paymentsdb.StatusFailed:
|
||||
return lnrpc.Payment_FAILED, nil
|
||||
|
||||
default:
|
||||
|
||||
Reference in new issue
Block a user