mirror of
https://github.com/aljazceru/cdk.git
synced 2026-02-05 05:06:14 +01:00
feat: create new ClnRpc for each request
This removes the mutex from the ClnRpc client avoiding blocking the mint. cln-grpc handles this in the same way. https://search.nixos.org/packages?channel=unstable&from=0&size=50&sort=relevance&type=packages&query=c-lightning
This commit is contained in:
@@ -32,7 +32,6 @@ use cln_rpc::primitives::{Amount as CLN_Amount, AmountOrAny};
|
||||
use error::Error;
|
||||
use futures::{Stream, StreamExt};
|
||||
use serde_json::Value;
|
||||
use tokio::sync::Mutex;
|
||||
use tokio_util::sync::CancellationToken;
|
||||
use uuid::Uuid;
|
||||
|
||||
@@ -42,7 +41,6 @@ pub mod error;
|
||||
#[derive(Clone)]
|
||||
pub struct Cln {
|
||||
rpc_socket: PathBuf,
|
||||
cln_client: Arc<Mutex<cln_rpc::ClnRpc>>,
|
||||
fee_reserve: FeeReserve,
|
||||
wait_invoice_cancel_token: CancellationToken,
|
||||
wait_invoice_is_active: Arc<AtomicBool>,
|
||||
@@ -51,11 +49,8 @@ pub struct Cln {
|
||||
impl Cln {
|
||||
/// Create new [`Cln`]
|
||||
pub async fn new(rpc_socket: PathBuf, fee_reserve: FeeReserve) -> Result<Self, Error> {
|
||||
let cln_client = cln_rpc::ClnRpc::new(&rpc_socket).await?;
|
||||
|
||||
Ok(Self {
|
||||
rpc_socket,
|
||||
cln_client: Arc::new(Mutex::new(cln_client)),
|
||||
fee_reserve,
|
||||
wait_invoice_cancel_token: CancellationToken::new(),
|
||||
wait_invoice_is_active: Arc::new(AtomicBool::new(false)),
|
||||
@@ -243,7 +238,7 @@ impl MintPayment for Cln {
|
||||
})
|
||||
.flatten();
|
||||
|
||||
let mut cln_client = self.cln_client.lock().await;
|
||||
let mut cln_client = cln_rpc::ClnRpc::new(&self.rpc_socket).await?;
|
||||
let cln_response = cln_client
|
||||
.call_typed(&PayRequest {
|
||||
bolt11: melt_quote.request.to_string(),
|
||||
@@ -313,7 +308,7 @@ impl MintPayment for Cln {
|
||||
) -> Result<CreateIncomingPaymentResponse, Self::Err> {
|
||||
let time_now = unix_time();
|
||||
|
||||
let mut cln_client = self.cln_client.lock().await;
|
||||
let mut cln_client = cln_rpc::ClnRpc::new(&self.rpc_socket).await?;
|
||||
|
||||
let label = Uuid::new_v4().to_string();
|
||||
|
||||
@@ -350,7 +345,7 @@ impl MintPayment for Cln {
|
||||
&self,
|
||||
payment_hash: &str,
|
||||
) -> Result<MintQuoteState, Self::Err> {
|
||||
let mut cln_client = self.cln_client.lock().await;
|
||||
let mut cln_client = cln_rpc::ClnRpc::new(&self.rpc_socket).await?;
|
||||
|
||||
let listinvoices_response = cln_client
|
||||
.call_typed(&ListinvoicesRequest {
|
||||
@@ -383,7 +378,7 @@ impl MintPayment for Cln {
|
||||
&self,
|
||||
payment_hash: &str,
|
||||
) -> Result<MakePaymentResponse, Self::Err> {
|
||||
let mut cln_client = self.cln_client.lock().await;
|
||||
let mut cln_client = cln_rpc::ClnRpc::new(&self.rpc_socket).await?;
|
||||
|
||||
let listpays_response = cln_client
|
||||
.call_typed(&ListpaysRequest {
|
||||
@@ -425,7 +420,7 @@ impl MintPayment for Cln {
|
||||
impl Cln {
|
||||
/// Get last pay index for cln
|
||||
async fn get_last_pay_index(&self) -> Result<Option<u64>, Error> {
|
||||
let mut cln_client = self.cln_client.lock().await;
|
||||
let mut cln_client = cln_rpc::ClnRpc::new(&self.rpc_socket).await?;
|
||||
let listinvoices_response = cln_client
|
||||
.call_typed(&ListinvoicesRequest {
|
||||
index: None,
|
||||
|
||||
Reference in New Issue
Block a user