Skip to content
This repository was archived by the owner on Jan 6, 2025. It is now read-only.

Commit 177ff80

Browse files
committed
Deprecate CANCELLED state
.. as per spec.
1 parent 8092662 commit 177ff80

File tree

1 file changed

+16
-20
lines changed

1 file changed

+16
-20
lines changed

src/lsps1/msgs.rs

+16-20
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ pub struct PaymentInfo {
159159
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
160160
pub struct Bolt11PaymentInfo {
161161
/// Indicates the current state of the payment.
162-
pub state: Bolt11PaymentState,
162+
pub state: PaymentState,
163163
/// The datetime when the payment option expires.
164164
pub expires_at: chrono::DateTime<Utc>,
165165
/// The total fee the LSP will charge to open this channel in satoshi.
@@ -176,7 +176,7 @@ pub struct Bolt11PaymentInfo {
176176
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
177177
pub struct OnchainPaymentInfo {
178178
/// Indicates the current state of the payment.
179-
pub state: OnchainPaymentState,
179+
pub state: PaymentState,
180180
/// The datetime when the payment option expires.
181181
pub expires_at: chrono::DateTime<Utc>,
182182
/// The total fee the LSP will charge to open this channel in satoshi.
@@ -203,31 +203,19 @@ pub struct OnchainPaymentInfo {
203203
pub refund_onchain_address: Option<Address>,
204204
}
205205

206-
/// The state of a BOLT 11 payment.
207-
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
208-
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
209-
pub enum Bolt11PaymentState {
210-
/// A payment is expected.
211-
ExpectPayment,
212-
/// A Lighting payment has arrived, but the preimage has not been released yet.
213-
Hold,
214-
/// A sufficient payment has been received.
215-
Paid,
216-
/// The payment has been refunded.
217-
Refunded,
218-
/// The payment has been cancelled.
219-
Cancelled,
220-
}
221-
222-
/// The state of an onchain payment.
206+
/// The state of a payment.
207+
///
208+
/// *Note*: Previously, the spec also knew a `CANCELLED` state for BOLT11 payments, which has since
209+
/// been deprecated and `REFUNDED` should be used instead.
223210
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
224211
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
225-
pub enum OnchainPaymentState {
212+
pub enum PaymentState {
226213
/// A payment is expected.
227214
ExpectPayment,
228215
/// A sufficient payment has been received.
229216
Paid,
230217
/// The payment has been refunded.
218+
#[serde(alias = "CANCELLED")]
231219
Refunded,
232220
}
233221

@@ -473,5 +461,13 @@ mod tests {
473461
"expires_at": "2012-04-23T18:25:43.511Z"
474462
}"#;
475463
let _channel: ChannelInfo = serde_json::from_str(json_str).unwrap();
464+
465+
let json_str = r#""CANCELLED""#;
466+
let payment_state: PaymentState = serde_json::from_str(json_str).unwrap();
467+
assert_eq!(payment_state, PaymentState::Refunded);
468+
469+
let json_str = r#""REFUNDED""#;
470+
let payment_state: PaymentState = serde_json::from_str(json_str).unwrap();
471+
assert_eq!(payment_state, PaymentState::Refunded);
476472
}
477473
}

0 commit comments

Comments
 (0)