Skip to content

Minor tweaks to lightning-liquidity to get it building in bindings #3701

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
4 changes: 3 additions & 1 deletion lightning-liquidity/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@
use crate::lsps0;
use crate::lsps1;
use crate::lsps2;
use crate::prelude::{Vec, VecDeque};
use crate::sync::{Arc, Mutex};

use alloc::collections::VecDeque;
use alloc::vec::Vec;

use core::future::Future;
use core::task::{Poll, Waker};

Expand Down
6 changes: 0 additions & 6 deletions lightning-liquidity/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,6 @@
extern crate alloc;

mod prelude {
#![allow(unused_imports)]
pub use alloc::{boxed::Box, collections::VecDeque, string::String, vec, vec::Vec};

pub use alloc::borrow::ToOwned;
pub use alloc::string::ToString;

pub(crate) use lightning::util::hash_tables::*;
}

Expand Down
3 changes: 2 additions & 1 deletion lightning-liquidity/src/lsps0/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

//! Contains bLIP-50 / LSPS0 event types.

use crate::prelude::Vec;
use alloc::vec::Vec;

use bitcoin::secp256k1::PublicKey;

/// An event which an bLIP-50 / LSPS0 client may want to take some action in response to.
Expand Down
9 changes: 5 additions & 4 deletions lightning-liquidity/src/lsps0/msgs.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//! Message, request, and other primitive types used to implement LSPS0.

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

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

use serde::{Deserialize, Serialize};

use core::convert::TryFrom;

pub(crate) const LSPS0_LISTPROTOCOLS_METHOD_NAME: &str = "lsps0.list_protocols";

/// A `list_protocols` request.
Expand Down Expand Up @@ -99,7 +99,8 @@ mod tests {

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

use alloc::string::ToString;

#[test]
fn deserializes_request() {
Expand Down
20 changes: 11 additions & 9 deletions lightning-liquidity/src/lsps0/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
//! specification](https://github.com/lightning/blips/blob/master/blip-0050.md) for more
//! information.

use alloc::string::String;

use core::fmt::{self, Display};
use core::str::FromStr;

use crate::lsps0::msgs::{
LSPS0ListProtocolsRequest, LSPS0Message, LSPS0Request, LSPS0Response,
LSPS0_LISTPROTOCOLS_METHOD_NAME,
Expand All @@ -16,17 +21,14 @@ use crate::lsps1::msgs::{
use crate::lsps2::msgs::{
LSPS2Message, LSPS2Request, LSPS2Response, LSPS2_BUY_METHOD_NAME, LSPS2_GET_INFO_METHOD_NAME,
};
use crate::prelude::{HashMap, String};
use crate::prelude::HashMap;

use lightning::ln::msgs::{DecodeError, LightningError};
use lightning::ln::wire;
use lightning::util::ser::{LengthLimitedRead, LengthReadable, WithoutLength};

use bitcoin::secp256k1::PublicKey;

use core::fmt::{self, Display};
use core::str::FromStr;

#[cfg(feature = "std")]
use std::time::{SystemTime, UNIX_EPOCH};

Expand Down Expand Up @@ -625,7 +627,7 @@ impl<'de, 'a> Visitor<'de> for LSPSMessageVisitor<'a> {
}

pub(crate) mod string_amount {
use crate::prelude::{String, ToString};
use alloc::string::{String, ToString};
use core::str::FromStr;
use serde::de::Unexpected;
use serde::{Deserialize, Deserializer, Serializer};
Expand All @@ -650,7 +652,7 @@ pub(crate) mod string_amount {
}

pub(crate) mod string_amount_option {
use crate::prelude::{String, ToString};
use alloc::string::{String, ToString};
use core::str::FromStr;
use serde::de::Unexpected;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
Expand Down Expand Up @@ -679,7 +681,7 @@ pub(crate) mod string_amount_option {
}

pub(crate) mod string_offer {
use crate::prelude::{String, ToString};
use alloc::string::{String, ToString};
use core::str::FromStr;
use lightning::offers::offer::Offer;
use serde::de::Unexpected;
Expand All @@ -705,7 +707,7 @@ pub(crate) mod string_offer {
}

pub(crate) mod unchecked_address {
use crate::prelude::{String, ToString};
use alloc::string::{String, ToString};
use bitcoin::Address;
use core::str::FromStr;
use serde::de::Unexpected;
Expand All @@ -732,7 +734,7 @@ pub(crate) mod unchecked_address {
}

pub(crate) mod unchecked_address_option {
use crate::prelude::{String, ToString};
use alloc::string::{String, ToString};
use bitcoin::Address;
use core::str::FromStr;
use serde::de::Unexpected;
Expand Down
3 changes: 2 additions & 1 deletion lightning-liquidity/src/lsps0/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
//! specifcation](https://github.com/lightning/blips/blob/master/blip-0050.md) for more
//! information.

use alloc::vec::Vec;

use crate::lsps0::msgs::{LSPS0ListProtocolsResponse, LSPS0Message, LSPS0Request, LSPS0Response};
use crate::lsps0::ser::{LSPSProtocolMessageHandler, LSPSRequestId};
use crate::message_queue::MessageQueue;
use crate::prelude::Vec;
use crate::sync::Arc;

use lightning::ln::msgs::{ErrorAction, LightningError};
Expand Down
8 changes: 4 additions & 4 deletions lightning-liquidity/src/lsps1/msgs.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
//! Message, request, and other primitive types used to implement bLIP-51 / LSPS1.

use alloc::string::String;

use core::convert::TryFrom;

use crate::lsps0::ser::{
string_amount, string_offer, u32_fee_rate, unchecked_address, unchecked_address_option,
LSPSDateTime, LSPSMessage, LSPSRequestId, LSPSResponseError,
};

use crate::prelude::String;

use bitcoin::{Address, FeeRate, OutPoint};

use lightning::offers::offer::Offer;
use lightning_invoice::Bolt11Invoice;

use serde::{Deserialize, Serialize};

use core::convert::TryFrom;

pub(crate) const LSPS1_GET_INFO_METHOD_NAME: &str = "lsps1.get_info";
pub(crate) const LSPS1_CREATE_ORDER_METHOD_NAME: &str = "lsps1.create_order";
pub(crate) const LSPS1_GET_ORDER_METHOD_NAME: &str = "lsps1.get_order";
Expand Down
7 changes: 5 additions & 2 deletions lightning-liquidity/src/lsps1/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@

//! Contains the main bLIP-51 / LSPS1 server object, [`LSPS1ServiceHandler`].

use alloc::string::String;

use core::ops::Deref;

use super::event::LSPS1ServiceEvent;
use super::msgs::{
LSPS1ChannelInfo, LSPS1CreateOrderRequest, LSPS1CreateOrderResponse, LSPS1GetInfoResponse,
Expand All @@ -22,7 +26,7 @@ use crate::events::EventQueue;
use crate::lsps0::ser::{
LSPSDateTime, LSPSProtocolMessageHandler, LSPSRequestId, LSPSResponseError,
};
use crate::prelude::{new_hash_map, HashMap, String};
use crate::prelude::{new_hash_map, HashMap};
use crate::sync::{Arc, Mutex, RwLock};
use crate::utils;

Expand All @@ -36,7 +40,6 @@ use lightning::util::logger::Level;
use bitcoin::secp256k1::PublicKey;

use chrono::Utc;
use core::ops::Deref;

/// Server-side configuration options for bLIP-51 / LSPS1 channel requests.
#[derive(Clone, Debug)]
Expand Down
10 changes: 6 additions & 4 deletions lightning-liquidity/src/lsps2/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@

//! Contains the main bLIP-52 / LSPS2 client object, [`LSPS2ClientHandler`].

use alloc::string::{String, ToString};

use core::default::Default;
use core::ops::Deref;

use crate::events::EventQueue;
use crate::lsps0::ser::{LSPSProtocolMessageHandler, LSPSRequestId, LSPSResponseError};
use crate::lsps2::event::LSPS2ClientEvent;
use crate::message_queue::MessageQueue;
use crate::prelude::{new_hash_map, new_hash_set, HashMap, HashSet, String, ToString};
use crate::prelude::{new_hash_map, new_hash_set, HashMap, HashSet};
use crate::sync::{Arc, Mutex, RwLock};

use lightning::ln::msgs::{ErrorAction, LightningError};
Expand All @@ -22,9 +27,6 @@ use lightning::util::logger::Level;

use bitcoin::secp256k1::PublicKey;

use core::default::Default;
use core::ops::Deref;

use crate::lsps2::msgs::{
LSPS2BuyRequest, LSPS2BuyResponse, LSPS2GetInfoRequest, LSPS2GetInfoResponse, LSPS2Message,
LSPS2OpeningFeeParams, LSPS2Request, LSPS2Response,
Expand Down
3 changes: 2 additions & 1 deletion lightning-liquidity/src/lsps2/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

use super::msgs::LSPS2OpeningFeeParams;
use crate::lsps0::ser::LSPSRequestId;
use crate::prelude::{String, Vec};
use alloc::string::String;
use alloc::vec::Vec;

use bitcoin::secp256k1::PublicKey;

Expand Down
4 changes: 3 additions & 1 deletion lightning-liquidity/src/lsps2/msgs.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
//! Message, request, and other primitive types used to implement bLIP-52 / LSPS2.

use alloc::string::String;
use alloc::vec::Vec;

use core::convert::TryFrom;

use bitcoin::hashes::hmac::{Hmac, HmacEngine};
Expand All @@ -13,7 +16,6 @@ use crate::lsps0::ser::{
string_amount, string_amount_option, LSPSDateTime, LSPSMessage, LSPSRequestId,
LSPSResponseError,
};
use crate::prelude::{String, Vec};
use crate::utils;

pub(crate) const LSPS2_GET_INFO_METHOD_NAME: &str = "lsps2.get_info";
Expand Down
3 changes: 2 additions & 1 deletion lightning-liquidity/src/lsps2/payment_queue.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::prelude::Vec;
use alloc::vec::Vec;

use lightning::ln::channelmanager::InterceptId;
use lightning_types::payment::PaymentHash;

Expand Down
17 changes: 10 additions & 7 deletions lightning-liquidity/src/lsps2/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@

//! Contains the main bLIP-52 / LSPS2 server-side object, [`LSPS2ServiceHandler`].

use alloc::string::{String, ToString};
use alloc::vec::Vec;

use core::ops::Deref;
use core::sync::atomic::{AtomicUsize, Ordering};

use crate::events::EventQueue;
use crate::lsps0::ser::{
LSPSMessage, LSPSProtocolMessageHandler, LSPSRequestId, LSPSResponseError,
Expand All @@ -22,7 +28,7 @@ use crate::lsps2::utils::{
};
use crate::message_queue::MessageQueue;
use crate::prelude::hash_map::Entry;
use crate::prelude::{new_hash_map, HashMap, String, ToString, Vec};
use crate::prelude::{new_hash_map, HashMap};
use crate::sync::{Arc, Mutex, MutexGuard, RwLock};

use lightning::events::HTLCDestination;
Expand All @@ -36,9 +42,6 @@ use lightning_types::payment::PaymentHash;

use bitcoin::secp256k1::PublicKey;

use core::ops::Deref;
use core::sync::atomic::{AtomicUsize, Ordering};

use crate::lsps2::msgs::{
LSPS2BuyRequest, LSPS2BuyResponse, LSPS2GetInfoRequest, LSPS2GetInfoResponse, LSPS2Message,
LSPS2OpeningFeeParams, LSPS2RawOpeningFeeParams, LSPS2Request, LSPS2Response,
Expand Down Expand Up @@ -551,7 +554,7 @@ macro_rules! get_or_insert_peer_state_entry {
}

/// The main object allowing to send and receive bLIP-52 / LSPS2 messages.
pub struct LSPS2ServiceHandler<CM: Deref + Clone>
pub struct LSPS2ServiceHandler<CM: Deref>
where
CM::Target: AChannelManager,
{
Expand All @@ -565,7 +568,7 @@ where
config: LSPS2ServiceConfig,
}

impl<CM: Deref + Clone> LSPS2ServiceHandler<CM>
impl<CM: Deref> LSPS2ServiceHandler<CM>
where
CM::Target: AChannelManager,
{
Expand Down Expand Up @@ -1352,7 +1355,7 @@ where
}
}

impl<CM: Deref + Clone> LSPSProtocolMessageHandler for LSPS2ServiceHandler<CM>
impl<CM: Deref> LSPSProtocolMessageHandler for LSPS2ServiceHandler<CM>
where
CM::Target: AChannelManager,
{
Expand Down
6 changes: 5 additions & 1 deletion lightning-liquidity/src/manager.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
use alloc::boxed::Box;
use alloc::string::ToString;
use alloc::vec::Vec;

use crate::events::{EventQueue, LiquidityEvent};
use crate::lsps0::client::LSPS0ClientHandler;
use crate::lsps0::msgs::LSPS0Message;
Expand All @@ -17,7 +21,7 @@ use crate::lsps1::service::{LSPS1ServiceConfig, LSPS1ServiceHandler};
use crate::lsps2::client::{LSPS2ClientConfig, LSPS2ClientHandler};
use crate::lsps2::msgs::LSPS2Message;
use crate::lsps2::service::{LSPS2ServiceConfig, LSPS2ServiceHandler};
use crate::prelude::{new_hash_map, new_hash_set, Box, HashMap, HashSet, ToString, Vec};
use crate::prelude::{new_hash_map, new_hash_set, HashMap, HashSet};
use crate::sync::{Arc, Mutex, RwLock};

use lightning::chain::{self, BestBlock, Confirm, Filter, Listen};
Expand Down
5 changes: 4 additions & 1 deletion lightning-liquidity/src/message_queue.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
//! Holds types and traits used to implement message queues for [`LSPSMessage`]s.

use alloc::boxed::Box;
use alloc::collections::VecDeque;
use alloc::vec::Vec;

use crate::lsps0::ser::LSPSMessage;
use crate::prelude::{Box, Vec, VecDeque};
use crate::sync::{Mutex, RwLock};

use bitcoin::secp256k1::PublicKey;
Expand Down
3 changes: 2 additions & 1 deletion lightning-liquidity/src/tests/utils.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::prelude::Vec;
use alloc::vec::Vec;

use bitcoin::secp256k1::PublicKey;
use lightning::io;
use lightning::sign::EntropySource;
Expand Down
3 changes: 2 additions & 1 deletion lightning-liquidity/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use alloc::string::String;
use core::{fmt::Write, ops::Deref};

use lightning::sign::EntropySource;

use crate::lsps0::ser::LSPSRequestId;
use crate::prelude::String;

pub fn scid_from_human_readable_string(human_readable_scid: &str) -> Result<u64, ()> {
let mut parts = human_readable_scid.split('x');
Expand Down
Loading