github.com/decred/dcrlnd@v0.7.6/invoices/resolution_result.go (about)

     1  package invoices
     2  
     3  // acceptResolutionResult provides metadata which about a htlc that was
     4  // accepted by the registry.
     5  type acceptResolutionResult uint8
     6  
     7  const (
     8  	resultInvalidAccept acceptResolutionResult = iota
     9  
    10  	// resultReplayToAccepted is returned when we replay an accepted
    11  	// invoice.
    12  	resultReplayToAccepted
    13  
    14  	// resultDuplicateToAccepted is returned when we accept a duplicate
    15  	// htlc.
    16  	resultDuplicateToAccepted
    17  
    18  	// resultAccepted is returned when we accept a hodl invoice.
    19  	resultAccepted
    20  
    21  	// resultPartialAccepted is returned when we have partially received
    22  	// payment.
    23  	resultPartialAccepted
    24  )
    25  
    26  // String returns a string representation of the result.
    27  func (a acceptResolutionResult) String() string {
    28  	switch a {
    29  	case resultInvalidAccept:
    30  		return "invalid accept result"
    31  
    32  	case resultReplayToAccepted:
    33  		return "replayed htlc to accepted invoice"
    34  
    35  	case resultDuplicateToAccepted:
    36  		return "accepting duplicate payment to accepted invoice"
    37  
    38  	case resultAccepted:
    39  		return "accepted"
    40  
    41  	case resultPartialAccepted:
    42  		return "partial payment accepted"
    43  
    44  	default:
    45  		return "unknown accept resolution result"
    46  	}
    47  }
    48  
    49  // FailResolutionResult provides metadata about a htlc that was failed by
    50  // the registry. It can be used to take custom actions on resolution of the
    51  // htlc.
    52  type FailResolutionResult uint8
    53  
    54  const (
    55  	resultInvalidFailure FailResolutionResult = iota
    56  
    57  	// ResultReplayToCanceled is returned when we replay a canceled invoice.
    58  	ResultReplayToCanceled
    59  
    60  	// ResultInvoiceAlreadyCanceled is returned when trying to pay an
    61  	// invoice that is already canceled.
    62  	ResultInvoiceAlreadyCanceled
    63  
    64  	// ResultInvoiceAlreadySettled is returned when trying to pay an invoice
    65  	// that is already settled.
    66  	ResultInvoiceAlreadySettled
    67  
    68  	// ResultAmountTooLow is returned when an invoice is underpaid.
    69  	ResultAmountTooLow
    70  
    71  	// ResultExpiryTooSoon is returned when we do not accept an invoice
    72  	// payment because it expires too soon.
    73  	ResultExpiryTooSoon
    74  
    75  	// ResultCanceled is returned when we cancel an invoice and its
    76  	// associated htlcs.
    77  	ResultCanceled
    78  
    79  	// ResultInvoiceNotOpen is returned when a mpp invoice is not open.
    80  	ResultInvoiceNotOpen
    81  
    82  	// ResultMppTimeout is returned when an invoice paid with multiple
    83  	// partial payments times out before it is fully paid.
    84  	ResultMppTimeout
    85  
    86  	// ResultAddressMismatch is returned when the payment address for a mpp
    87  	// invoice does not match.
    88  	ResultAddressMismatch
    89  
    90  	// ResultHtlcSetTotalMismatch is returned when the amount paid by a
    91  	// htlc does not match its set total.
    92  	ResultHtlcSetTotalMismatch
    93  
    94  	// ResultHtlcSetTotalTooLow is returned when a mpp set total is too low
    95  	// for an invoice.
    96  	ResultHtlcSetTotalTooLow
    97  
    98  	// ResultHtlcSetOverpayment is returned when a mpp set is overpaid.
    99  	ResultHtlcSetOverpayment
   100  
   101  	// ResultInvoiceNotFound is returned when an attempt is made to pay an
   102  	// invoice that is unknown to us.
   103  	ResultInvoiceNotFound
   104  
   105  	// ResultKeySendError is returned when we receive invalid keysend
   106  	// parameters.
   107  	ResultKeySendError
   108  
   109  	// ResultMppInProgress is returned when we are busy receiving a mpp
   110  	// payment.
   111  	ResultMppInProgress
   112  
   113  	// ResultHtlcInvoiceTypeMismatch is returned when an AMP HTLC targets a
   114  	// non-AMP invoice and vice versa.
   115  	ResultHtlcInvoiceTypeMismatch
   116  
   117  	// ResultAmpError is returned when we receive invalid AMP parameters.
   118  	ResultAmpError
   119  
   120  	// ResultAmpReconstruction is returned when the derived child
   121  	// hash/preimage pairs were invalid for at least one HTLC in the set.
   122  	ResultAmpReconstruction
   123  )
   124  
   125  // String returns a string representation of the result.
   126  func (f FailResolutionResult) String() string {
   127  	return f.FailureString()
   128  }
   129  
   130  // FailureString returns a string representation of the result.
   131  //
   132  // Note: it is part of the FailureDetail interface.
   133  func (f FailResolutionResult) FailureString() string {
   134  	switch f {
   135  	case resultInvalidFailure:
   136  		return "invalid failure result"
   137  
   138  	case ResultReplayToCanceled:
   139  		return "replayed htlc to canceled invoice"
   140  
   141  	case ResultInvoiceAlreadyCanceled:
   142  		return "invoice already canceled"
   143  
   144  	case ResultInvoiceAlreadySettled:
   145  		return "invoice alread settled"
   146  
   147  	case ResultAmountTooLow:
   148  		return "amount too low"
   149  
   150  	case ResultExpiryTooSoon:
   151  		return "expiry too soon"
   152  
   153  	case ResultCanceled:
   154  		return "canceled"
   155  
   156  	case ResultInvoiceNotOpen:
   157  		return "invoice no longer open"
   158  
   159  	case ResultMppTimeout:
   160  		return "mpp timeout"
   161  
   162  	case ResultAddressMismatch:
   163  		return "payment address mismatch"
   164  
   165  	case ResultHtlcSetTotalMismatch:
   166  		return "htlc total amt doesn't match set total"
   167  
   168  	case ResultHtlcSetTotalTooLow:
   169  		return "set total too low for invoice"
   170  
   171  	case ResultHtlcSetOverpayment:
   172  		return "mpp is overpaying set total"
   173  
   174  	case ResultInvoiceNotFound:
   175  		return "invoice not found"
   176  
   177  	case ResultKeySendError:
   178  		return "invalid keysend parameters"
   179  
   180  	case ResultMppInProgress:
   181  		return "mpp reception in progress"
   182  
   183  	case ResultHtlcInvoiceTypeMismatch:
   184  		return "htlc invoice type mismatch"
   185  
   186  	case ResultAmpError:
   187  		return "invalid amp parameters"
   188  
   189  	case ResultAmpReconstruction:
   190  		return "amp reconstruction failed"
   191  
   192  	default:
   193  		return "unknown failure resolution result"
   194  	}
   195  }
   196  
   197  // IsSetFailure returns true if this failure should result in the entire HTLC
   198  // set being failed with the same result.
   199  func (f FailResolutionResult) IsSetFailure() bool {
   200  	switch f {
   201  	case
   202  		ResultAmpReconstruction,
   203  		ResultHtlcSetTotalTooLow,
   204  		ResultHtlcSetTotalMismatch,
   205  		ResultHtlcSetOverpayment:
   206  
   207  		return true
   208  
   209  	default:
   210  		return false
   211  	}
   212  }
   213  
   214  // SettleResolutionResult provides metadata which about a htlc that was failed
   215  // by the registry. It can be used to take custom actions on resolution of the
   216  // htlc.
   217  type SettleResolutionResult uint8
   218  
   219  const (
   220  	resultInvalidSettle SettleResolutionResult = iota
   221  
   222  	// ResultSettled is returned when we settle an invoice.
   223  	ResultSettled
   224  
   225  	// ResultReplayToSettled is returned when we replay a settled invoice.
   226  	ResultReplayToSettled
   227  
   228  	// ResultDuplicateToSettled is returned when we settle an invoice which
   229  	// has already been settled at least once.
   230  	ResultDuplicateToSettled
   231  )
   232  
   233  // String returns a string representation of the result.
   234  func (s SettleResolutionResult) String() string {
   235  	switch s {
   236  	case resultInvalidSettle:
   237  		return "invalid settle result"
   238  
   239  	case ResultSettled:
   240  		return "settled"
   241  
   242  	case ResultReplayToSettled:
   243  		return "replayed htlc to settled invoice"
   244  
   245  	case ResultDuplicateToSettled:
   246  		return "accepting duplicate payment to settled invoice"
   247  
   248  	default:
   249  		return "unknown settle resolution result"
   250  	}
   251  }