2019-05-16 16:27:29 +03:00
|
|
|
package htlcswitch
|
|
|
|
|
2019-05-16 16:27:29 +03:00
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
|
|
|
|
"github.com/lightningnetwork/lnd/lnwire"
|
|
|
|
)
|
2019-05-16 16:27:29 +03:00
|
|
|
|
|
|
|
var (
|
|
|
|
// ErrPaymentIDNotFound is an error returned if the given paymentID is
|
|
|
|
// not found.
|
|
|
|
ErrPaymentIDNotFound = errors.New("paymentID not found")
|
|
|
|
|
|
|
|
// ErrPaymentIDAlreadyExists is returned if we try to write a pending
|
|
|
|
// payment whose paymentID already exists.
|
|
|
|
ErrPaymentIDAlreadyExists = errors.New("paymentID already exists")
|
|
|
|
)
|
|
|
|
|
2019-05-16 16:27:29 +03:00
|
|
|
// PaymentResult wraps a decoded result received from the network after a
|
|
|
|
// payment attempt was made. This is what is eventually handed to the router
|
|
|
|
// for processing.
|
2019-05-16 16:27:29 +03:00
|
|
|
type PaymentResult struct {
|
|
|
|
// Preimage is set by the switch in case a sent HTLC was settled.
|
|
|
|
Preimage [32]byte
|
|
|
|
|
|
|
|
// Error is non-nil in case a HTLC send failed, and the HTLC is now
|
|
|
|
// irrevocably cancelled. If the payment failed during forwarding, this
|
|
|
|
// error will be a *ForwardingError.
|
|
|
|
Error error
|
|
|
|
}
|
2019-05-16 16:27:29 +03:00
|
|
|
|
|
|
|
// networkResult is the raw result received from the network after a payment
|
|
|
|
// attempt has been made. Since the switch doesn't always have the necessary
|
|
|
|
// data to decode the raw message, we store it together with some meta data,
|
|
|
|
// and decode it when the router query for the final result.
|
|
|
|
type networkResult struct {
|
|
|
|
// msg is the received result. This should be of type UpdateFulfillHTLC
|
|
|
|
// or UpdateFailHTLC.
|
|
|
|
msg lnwire.Message
|
|
|
|
|
|
|
|
// unencrypted indicates whether the failure encoded in the message is
|
|
|
|
// unencrypted, and hence doesn't need to be decrypted.
|
|
|
|
unencrypted bool
|
|
|
|
|
|
|
|
// isResolution indicates whether this is a resolution message, in
|
|
|
|
// which the failure reason might not be included.
|
|
|
|
isResolution bool
|
|
|
|
}
|