Skip to content

Commit

Permalink
add event to lnurl::Response::Ok
Browse files Browse the repository at this point in the history
  • Loading branch information
edouardparis committed Aug 9, 2020
1 parent ba2797e commit 5a8566a
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
_Readings about **lnurl**_


* [The spec](https://github.com/btcontract/lnurl-rfc/blob/master/spec.md) – **lnurl** spec, by [Anton Kumaigorodski](https://twitter.com/akumaigorodski).
* [The spec](https://github.com/btcontract/lnurl-rfc) – **lnurl** spec, by [Anton Kumaigorodski](https://twitter.com/akumaigorodski).
* [An introduction to lnurl](https://telegra.ph/lnurl-a-protocol-for-seamless-interaction-between-services-and-Lightning-wallets-08-19) – An article introducing the various types of **lnurl**'s, by [fiatjaf](https://twitter.com/fiatjaf).

## Progress
Expand Down
69 changes: 53 additions & 16 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug, PartialEq, Serialize, Deserialize)]
pub enum Event {
#[serde(rename = "REGISTERED")]
Registered,
#[serde(rename = "LOGGEDIN")]
LoggedIn,
#[serde(rename = "LINKED")]
Linked,
#[serde(rename = "AUTHED")]
Authed,
}

#[derive(Debug, PartialEq, Serialize, Deserialize)]
pub enum Tag {
#[serde(rename = "withdrawRequest")]
WithdrawRequest,
Expand Down Expand Up @@ -36,30 +48,55 @@ pub enum Response {
#[serde(rename = "ERROR")]
Error { reason: String },
#[serde(rename = "OK")]
Ok,
Ok { event: Option<Event> },
}

#[cfg(test)]
mod tests {
use crate::lnurl::Response;
use super::*;

#[test]
fn response_from_str() {
let json = r#"{"status":"ERROR","reason":"error detail..."}"#;
let resp: Response = serde_json::from_str(json).unwrap();
assert_eq!(
resp,
Response::Error {
reason: "error detail...".to_string()
}
);
let tests = vec![
(
r#"{"status":"ERROR","reason":"error detail..."}"#,
Response::Error {
reason: "error detail...".to_string(),
},
),
(
r#"{"status":"OK","event":"LOGGEDIN"}"#,
Response::Ok {
event: Some(Event::LoggedIn),
},
),
];

for test in tests {
let resp: Response = serde_json::from_str(test.0).unwrap();
assert_eq!(resp, test.1);
}
}
#[test]
fn response_to_str() {
let resp = Response::Error {
reason: "error detail...".to_string(),
};
let json = serde_json::to_string(&resp).unwrap();
assert_eq!(json, r#"{"status":"ERROR","reason":"error detail..."}"#);
let tests = vec![
(
r#"{"status":"ERROR","reason":"error detail..."}"#,
Response::Error {
reason: "error detail...".to_string(),
},
),
(
r#"{"status":"OK","event":"LOGGEDIN"}"#,
Response::Ok {
event: Some(Event::LoggedIn),
},
),
];

for test in tests {
let json = serde_json::to_string(&test.1).unwrap();
assert_eq!(json, test.0);
}
}
}

0 comments on commit 5a8566a

Please sign in to comment.