routing+channeldb: add more failure reasons

This commit is contained in:
Joost Jager
2019-06-04 11:22:23 +02:00
parent d6d87e12fe
commit ae46fb00cb
7 changed files with 241 additions and 167 deletions

View File

@@ -539,17 +539,13 @@ func (s *Server) trackPayment(paymentHash lntypes.Hash,
result.Route,
)
} else {
switch result.FailureReason {
case channeldb.FailureReasonTimeout:
status.State = PaymentState_FAILED_TIMEOUT
case channeldb.FailureReasonNoRoute:
status.State = PaymentState_FAILED_NO_ROUTE
default:
return errors.New("unknown failure reason")
state, err := marshallFailureReason(
result.FailureReason,
)
if err != nil {
return err
}
status.State = state
}
// Send event to the client.
@@ -565,3 +561,26 @@ func (s *Server) trackPayment(paymentHash lntypes.Hash,
return nil
}
// marshallFailureReason marshalls the failure reason to the corresponding rpc
// type.
func marshallFailureReason(reason channeldb.FailureReason) (
PaymentState, error) {
switch reason {
case channeldb.FailureReasonTimeout:
return PaymentState_FAILED_TIMEOUT, nil
case channeldb.FailureReasonNoRoute:
return PaymentState_FAILED_NO_ROUTE, nil
case channeldb.FailureReasonError:
return PaymentState_FAILED_ERROR, nil
case channeldb.FailureReasonIncorrectPaymentDetails:
return PaymentState_FAILED_INCORRECT_PAYMENT_DETAILS, nil
}
return 0, errors.New("unknown failure reason")
}