resolution_result.go
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 // ExternalValidationFailed is returned when the external validation 125 // failed. 126 ExternalValidationFailed 127 ) 128 129 // String returns a string representation of the result. 130 func (f FailResolutionResult) String() string { 131 return f.FailureString() 132 } 133 134 // FailureString returns a string representation of the result. 135 // 136 // Note: it is part of the FailureDetail interface. 137 func (f FailResolutionResult) FailureString() string { 138 switch f { 139 case resultInvalidFailure: 140 return "invalid failure result" 141 142 case ResultReplayToCanceled: 143 return "replayed htlc to canceled invoice" 144 145 case ResultInvoiceAlreadyCanceled: 146 return "invoice already canceled" 147 148 case ResultInvoiceAlreadySettled: 149 return "invoice already settled" 150 151 case ResultAmountTooLow: 152 return "amount too low" 153 154 case ResultExpiryTooSoon: 155 return "expiry too soon" 156 157 case ResultCanceled: 158 return "canceled" 159 160 case ResultInvoiceNotOpen: 161 return "invoice no longer open" 162 163 case ResultMppTimeout: 164 return "mpp timeout" 165 166 case ResultAddressMismatch: 167 return "payment address mismatch" 168 169 case ResultHtlcSetTotalMismatch: 170 return "htlc total amt doesn't match set total" 171 172 case ResultHtlcSetTotalTooLow: 173 return "set total too low for invoice" 174 175 case ResultHtlcSetOverpayment: 176 return "mpp is overpaying set total" 177 178 case ResultInvoiceNotFound: 179 return "invoice not found" 180 181 case ResultKeySendError: 182 return "invalid keysend parameters" 183 184 case ResultMppInProgress: 185 return "mpp reception in progress" 186 187 case ResultHtlcInvoiceTypeMismatch: 188 return "htlc invoice type mismatch" 189 190 case ResultAmpError: 191 return "invalid amp parameters" 192 193 case ResultAmpReconstruction: 194 return "amp reconstruction failed" 195 196 case ExternalValidationFailed: 197 return "external validation failed" 198 199 default: 200 return "unknown failure resolution result" 201 } 202 } 203 204 // IsSetFailure returns true if this failure should result in the entire HTLC 205 // set being failed with the same result. 206 func (f FailResolutionResult) IsSetFailure() bool { 207 switch f { 208 case 209 ResultAmpReconstruction, 210 ResultHtlcSetTotalTooLow, 211 ResultHtlcSetTotalMismatch, 212 ResultHtlcSetOverpayment, 213 ExternalValidationFailed: 214 215 return true 216 217 default: 218 return false 219 } 220 } 221 222 // SettleResolutionResult provides metadata which about a htlc that was failed 223 // by the registry. It can be used to take custom actions on resolution of the 224 // htlc. 225 type SettleResolutionResult uint8 226 227 const ( 228 resultInvalidSettle SettleResolutionResult = iota 229 230 // ResultSettled is returned when we settle an invoice. 231 ResultSettled 232 233 // ResultReplayToSettled is returned when we replay a settled invoice. 234 ResultReplayToSettled 235 236 // ResultDuplicateToSettled is returned when we settle an invoice which 237 // has already been settled at least once. 238 ResultDuplicateToSettled 239 ) 240 241 // String returns a string representation of the result. 242 func (s SettleResolutionResult) String() string { 243 switch s { 244 case resultInvalidSettle: 245 return "invalid settle result" 246 247 case ResultSettled: 248 return "settled" 249 250 case ResultReplayToSettled: 251 return "replayed htlc to settled invoice" 252 253 case ResultDuplicateToSettled: 254 return "accepting duplicate payment to settled invoice" 255 256 default: 257 return "unknown settle resolution result" 258 } 259 }