mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-01-19 05:45:21 +01:00
channeldb/payments: extract common info fetch into fetchCreationInfo
This commit is contained in:
parent
36a80b4d51
commit
9a1ec950bd
@ -548,14 +548,7 @@ func (p *PaymentControl) FetchInFlightPayments() ([]*InFlightPayment, error) {
|
|||||||
inFlight := &InFlightPayment{}
|
inFlight := &InFlightPayment{}
|
||||||
|
|
||||||
// Get the CreationInfo.
|
// Get the CreationInfo.
|
||||||
b := bucket.Get(paymentCreationInfoKey)
|
inFlight.Info, err = fetchCreationInfo(bucket)
|
||||||
if b == nil {
|
|
||||||
return fmt.Errorf("unable to find creation " +
|
|
||||||
"info for inflight payment")
|
|
||||||
}
|
|
||||||
|
|
||||||
r := bytes.NewReader(b)
|
|
||||||
inFlight.Info, err = deserializePaymentCreationInfo(r)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -252,6 +252,16 @@ func (db *DB) FetchPayments() ([]*MPPayment, error) {
|
|||||||
return payments, nil
|
return payments, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func fetchCreationInfo(bucket kvdb.ReadBucket) (*PaymentCreationInfo, error) {
|
||||||
|
b := bucket.Get(paymentCreationInfoKey)
|
||||||
|
if b == nil {
|
||||||
|
return nil, fmt.Errorf("creation info not found")
|
||||||
|
}
|
||||||
|
|
||||||
|
r := bytes.NewReader(b)
|
||||||
|
return deserializePaymentCreationInfo(r)
|
||||||
|
}
|
||||||
|
|
||||||
func fetchPayment(bucket kvdb.ReadBucket) (*MPPayment, error) {
|
func fetchPayment(bucket kvdb.ReadBucket) (*MPPayment, error) {
|
||||||
seqBytes := bucket.Get(paymentSequenceKey)
|
seqBytes := bucket.Get(paymentSequenceKey)
|
||||||
if seqBytes == nil {
|
if seqBytes == nil {
|
||||||
@ -261,13 +271,7 @@ func fetchPayment(bucket kvdb.ReadBucket) (*MPPayment, error) {
|
|||||||
sequenceNum := binary.BigEndian.Uint64(seqBytes)
|
sequenceNum := binary.BigEndian.Uint64(seqBytes)
|
||||||
|
|
||||||
// Get the PaymentCreationInfo.
|
// Get the PaymentCreationInfo.
|
||||||
b := bucket.Get(paymentCreationInfoKey)
|
creationInfo, err := fetchCreationInfo(bucket)
|
||||||
if b == nil {
|
|
||||||
return nil, fmt.Errorf("creation info not found")
|
|
||||||
}
|
|
||||||
|
|
||||||
r := bytes.NewReader(b)
|
|
||||||
creationInfo, err := deserializePaymentCreationInfo(r)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
||||||
@ -285,7 +289,7 @@ func fetchPayment(bucket kvdb.ReadBucket) (*MPPayment, error) {
|
|||||||
|
|
||||||
// Get failure reason if available.
|
// Get failure reason if available.
|
||||||
var failureReason *FailureReason
|
var failureReason *FailureReason
|
||||||
b = bucket.Get(paymentFailInfoKey)
|
b := bucket.Get(paymentFailInfoKey)
|
||||||
if b != nil {
|
if b != nil {
|
||||||
reason := FailureReason(b[0])
|
reason := FailureReason(b[0])
|
||||||
failureReason = &reason
|
failureReason = &reason
|
||||||
|
Loading…
Reference in New Issue
Block a user