channeldb: add error return value to fetchPaymentStatus
Preparation for when we need to return errors in a next commit.
This commit is contained in:
parent
e6e9e44e6f
commit
fa3a762a2c
@ -76,7 +76,10 @@ func (p *PaymentControl) InitPayment(paymentHash lntypes.Hash,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get the existing status of this payment, if any.
|
// Get the existing status of this payment, if any.
|
||||||
paymentStatus := fetchPaymentStatus(bucket)
|
paymentStatus, err := fetchPaymentStatus(bucket)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
switch paymentStatus {
|
switch paymentStatus {
|
||||||
|
|
||||||
@ -358,27 +361,30 @@ func nextPaymentSequence(tx *bbolt.Tx) ([]byte, error) {
|
|||||||
|
|
||||||
// fetchPaymentStatus fetches the payment status of the payment. If the payment
|
// fetchPaymentStatus fetches the payment status of the payment. If the payment
|
||||||
// isn't found, it will default to "StatusUnknown".
|
// isn't found, it will default to "StatusUnknown".
|
||||||
func fetchPaymentStatus(bucket *bbolt.Bucket) PaymentStatus {
|
func fetchPaymentStatus(bucket *bbolt.Bucket) (PaymentStatus, error) {
|
||||||
if bucket.Get(paymentSettleInfoKey) != nil {
|
if bucket.Get(paymentSettleInfoKey) != nil {
|
||||||
return StatusSucceeded
|
return StatusSucceeded, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if bucket.Get(paymentFailInfoKey) != nil {
|
if bucket.Get(paymentFailInfoKey) != nil {
|
||||||
return StatusFailed
|
return StatusFailed, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if bucket.Get(paymentCreationInfoKey) != nil {
|
if bucket.Get(paymentCreationInfoKey) != nil {
|
||||||
return StatusInFlight
|
return StatusInFlight, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return StatusUnknown
|
return StatusUnknown, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ensureInFlight checks whether the payment found in the given bucket has
|
// ensureInFlight checks whether the payment found in the given bucket has
|
||||||
// status InFlight, and returns an error otherwise. This should be used to
|
// status InFlight, and returns an error otherwise. This should be used to
|
||||||
// ensure we only mark in-flight payments as succeeded or failed.
|
// ensure we only mark in-flight payments as succeeded or failed.
|
||||||
func ensureInFlight(bucket *bbolt.Bucket) error {
|
func ensureInFlight(bucket *bbolt.Bucket) error {
|
||||||
paymentStatus := fetchPaymentStatus(bucket)
|
paymentStatus, err := fetchPaymentStatus(bucket)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
|
|
||||||
@ -443,15 +449,16 @@ func (p *PaymentControl) FetchInFlightPayments() ([]*InFlightPayment, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If the status is not InFlight, we can return early.
|
// If the status is not InFlight, we can return early.
|
||||||
paymentStatus := fetchPaymentStatus(bucket)
|
paymentStatus, err := fetchPaymentStatus(bucket)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
if paymentStatus != StatusInFlight {
|
if paymentStatus != StatusInFlight {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
inFlight := &InFlightPayment{}
|
||||||
inFlight = &InFlightPayment{}
|
|
||||||
err error
|
|
||||||
)
|
|
||||||
|
|
||||||
// Get the CreationInfo.
|
// Get the CreationInfo.
|
||||||
b := bucket.Get(paymentCreationInfoKey)
|
b := bucket.Get(paymentCreationInfoKey)
|
||||||
|
@ -337,7 +337,10 @@ func fetchPayment(bucket *bbolt.Bucket) (*MPPayment, error) {
|
|||||||
p.sequenceNum = binary.BigEndian.Uint64(seqBytes)
|
p.sequenceNum = binary.BigEndian.Uint64(seqBytes)
|
||||||
|
|
||||||
// Get the payment status.
|
// Get the payment status.
|
||||||
p.Status = fetchPaymentStatus(bucket)
|
p.Status, err = fetchPaymentStatus(bucket)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
// Get the PaymentCreationInfo.
|
// Get the PaymentCreationInfo.
|
||||||
b := bucket.Get(paymentCreationInfoKey)
|
b := bucket.Get(paymentCreationInfoKey)
|
||||||
@ -401,7 +404,11 @@ func (db *DB) DeletePayments() error {
|
|||||||
|
|
||||||
// If the status is InFlight, we cannot safely delete
|
// If the status is InFlight, we cannot safely delete
|
||||||
// the payment information, so we return early.
|
// the payment information, so we return early.
|
||||||
paymentStatus := fetchPaymentStatus(bucket)
|
paymentStatus, err := fetchPaymentStatus(bucket)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
if paymentStatus == StatusInFlight {
|
if paymentStatus == StatusInFlight {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user