Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lightning-liquidity/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ backtrace = ["dep:backtrace"]
lightning = { version = "0.2.0", path = "../lightning", default-features = false }
lightning-types = { version = "0.3.0", path = "../lightning-types", default-features = false }
lightning-invoice = { version = "0.34.0", path = "../lightning-invoice", default-features = false, features = ["serde"] }
lightning-macros = { version = "0.2", path = "../lightning-macros" }

bitcoin = { version = "0.32.2", default-features = false, features = ["serde"] }

Expand Down
1 change: 1 addition & 0 deletions lightning-liquidity/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ extern crate alloc;

mod prelude {
pub(crate) use lightning::util::hash_tables::*;
pub(crate) use lightning_macros::DeserializeWithUnknowns;
}

pub mod events;
Expand Down
45 changes: 39 additions & 6 deletions lightning-liquidity/src/lsps0/msgs.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
//! Message, request, and other primitive types used to implement LSPS0.

use crate::prelude::*;

use alloc::string::String;
use alloc::vec::Vec;
use core::convert::TryFrom;

use crate::lsps0::ser::{LSPSMessage, LSPSRequestId, LSPSResponseError};
use crate::lsps0::ser::{DeserializeWithUnknowns, LSPSMessage, LSPSRequestId, LSPSResponseError};

use serde::{Deserialize, Serialize};

Expand All @@ -14,15 +17,15 @@ pub(crate) const LSPS0_LISTPROTOCOLS_METHOD_NAME: &str = "lsps0.list_protocols";
/// Please refer to the [bLIP-50 / LSPS0
/// specification](https://github.com/lightning/blips/blob/master/blip-0050.md#lsps-specification-support-query)
/// for more information.
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize, Default)]
#[derive(DeserializeWithUnknowns, Clone, Debug, PartialEq, Eq, Deserialize, Serialize, Default)]
pub struct LSPS0ListProtocolsRequest {}

/// A response to a `list_protocols` request.
///
/// Please refer to the [bLIP-50 / LSPS0
/// specification](https://github.com/lightning/blips/blob/master/blip-0050.md#lsps-specification-support-query)
/// for more information.
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
#[derive(DeserializeWithUnknowns, Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
pub struct LSPS0ListProtocolsResponse {
/// A list of supported protocols.
pub protocols: Vec<u16>,
Expand Down Expand Up @@ -96,10 +99,13 @@ impl From<LSPS0Message> for LSPSMessage {

#[cfg(test)]
mod tests {
use lightning::util::hash_tables::new_hash_map;

use super::*;
use crate::lsps0::ser::LSPSMethod;

use crate::lsps0::ser::{
InvalidParams, LSPSMethod, LSPSResponseErrorData, JSONRPC_INVALID_PARAMS_ERROR_CODE,
};

use lightning::util::hash_tables::new_hash_map;

use alloc::string::ToString;

Expand Down Expand Up @@ -224,4 +230,31 @@ mod tests {
r#"{"jsonrpc":"2.0","id":"request:id:xyz123","result":{"protocols":[1,2,3]}}"#
);
}

#[test]
fn deserializes_request_with_unknown_params() {
let json = r#"{
"jsonrpc": "2.0",
"id": "request:id:abc",
"method": "lsps0.list_protocols",
"params": { "foo": "bar", "nested": { "x": 1 } }
}"#;

let mut request_id_method_map = new_hash_map();
let msg = LSPSMessage::from_str_with_id_map(json, &mut request_id_method_map).unwrap();

assert_eq!(
msg,
LSPSMessage::LSPS0(LSPS0Message::Response(
LSPSRequestId("request:id:abc".to_string()),
LSPS0Response::ListProtocolsError(LSPSResponseError {
code: JSONRPC_INVALID_PARAMS_ERROR_CODE,
message: "Invalid params".to_string(),
data: Some(LSPSResponseErrorData::InvalidParams(InvalidParams {
unrecognized: vec!["foo".to_string(), "nested".to_string()]
})),
})
))
);
}
}
Loading
Loading