Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
tnull committed Jan 5, 2024
1 parent 42592ff commit 767d755
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions src/liquidity.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::logger::log_error;
use crate::types::{ChannelManager, LiquidityManager, PeerManager};
use crate::Error;
use crate::{Error, UserChannelId};

use lightning::ln::features::{InitFeatures, NodeFeatures};
use lightning::ln::msgs::SocketAddress;
Expand All @@ -13,11 +13,14 @@ use lightning_liquidity::events::Event;
use lightning_liquidity::lsps0::msgs::RawLSPSMessage;
use lightning_liquidity::lsps2::event::LSPS2ClientEvent;
use lightning_liquidity::lsps2::msgs::OpeningFeeParams;
use lightning_liquidity::lsps2::utils::compute_opening_fee;

use bitcoin::secp256k1::PublicKey;

use tokio::sync::oneshot;

use rand::Rng;

use std::collections::HashMap;
use std::ops::Deref;
use std::sync::{Arc, Mutex};
Expand Down Expand Up @@ -177,17 +180,37 @@ where
}
}

pub(crate) fn lsps2_receive_to_inbound_channel(&self) -> Result<Bolt11Invoice, Error> {
pub(crate) fn lsps2_receive_to_inbound_channel(
&self,
) -> Result<(Bolt11Invoice, UserChannelId), Error> {
match self {
Self::None => Err(Error::LiquiditySourceUnavailable),
Self::LSPS2 { liquidity_manager, pending_fee_requests, pending_buy_requests } => {
Self::LSPS2 {
liquidity_manager,
pending_fee_requests,
pending_buy_requests,
logger,
..
} => {
let user_channel_id: u128 = rand::thread_rng().gen::<u128>();
// First, get the current opening fee from the LSP and check whether we want to
// proceed.
//
{
let (fee_request_sender, fee_request_receiver) = oneshot::channel();
self.pending
pending_fee_requests
.lock()
.unwrap()
.insert(user_channel_id, fee_request_sender);

let fee_response = fee_request_receiver.blocking_recv().map_err(|e| {
log_error!(
logger,
"Failed to handle response from liquidity service: {:?}",
e
);
});
}
Err(Error::LiquiditySourceUnavailable)
}
}
}
Expand Down

0 comments on commit 767d755

Please sign in to comment.