Ln use common (#751)

* chore: cdk-cln use common

* feat: lnd use common

* feat: lnbits use common
This commit is contained in:
thesimplekid
2025-05-14 17:29:58 +01:00
committed by GitHub
parent 65e785561c
commit 9ac387ae3d
9 changed files with 31 additions and 31 deletions

View File

@@ -13,7 +13,7 @@ readme = "README.md"
[dependencies] [dependencies]
async-trait.workspace = true async-trait.workspace = true
bitcoin.workspace = true bitcoin.workspace = true
cdk = { workspace = true, features = ["mint"] } cdk-common = { workspace = true, features = ["mint"] }
cln-rpc = "0.3.0" cln-rpc = "0.3.0"
futures.workspace = true futures.workspace = true
tokio.workspace = true tokio.workspace = true

View File

@@ -25,10 +25,10 @@ pub enum Error {
ClnRpc(#[from] cln_rpc::RpcError), ClnRpc(#[from] cln_rpc::RpcError),
/// Amount Error /// Amount Error
#[error(transparent)] #[error(transparent)]
Amount(#[from] cdk::amount::Error), Amount(#[from] cdk_common::amount::Error),
} }
impl From<Error> for cdk::cdk_payment::Error { impl From<Error> for cdk_common::payment::Error {
fn from(e: Error) -> Self { fn from(e: Error) -> Self {
Self::Lightning(Box::new(e)) Self::Lightning(Box::new(e))
} }

View File

@@ -12,15 +12,15 @@ use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc; use std::sync::Arc;
use async_trait::async_trait; use async_trait::async_trait;
use cdk::amount::{to_unit, Amount}; use cdk_common::amount::{to_unit, Amount};
use cdk::cdk_payment::{ use cdk_common::common::FeeReserve;
use cdk_common::nuts::{CurrencyUnit, MeltOptions, MeltQuoteState, MintQuoteState};
use cdk_common::payment::{
self, Bolt11Settings, CreateIncomingPaymentResponse, MakePaymentResponse, MintPayment, self, Bolt11Settings, CreateIncomingPaymentResponse, MakePaymentResponse, MintPayment,
PaymentQuoteResponse, PaymentQuoteResponse,
}; };
use cdk::nuts::{CurrencyUnit, MeltOptions, MeltQuoteState, MintQuoteState}; use cdk_common::util::{hex, unix_time};
use cdk::types::FeeReserve; use cdk_common::{mint, Bolt11Invoice};
use cdk::util::{hex, unix_time};
use cdk::{mint, Bolt11Invoice};
use cln_rpc::model::requests::{ use cln_rpc::model::requests::{
InvoiceRequest, ListinvoicesRequest, ListpaysRequest, PayRequest, WaitanyinvoiceRequest, InvoiceRequest, ListinvoicesRequest, ListpaysRequest, PayRequest, WaitanyinvoiceRequest,
}; };
@@ -65,7 +65,7 @@ impl Cln {
#[async_trait] #[async_trait]
impl MintPayment for Cln { impl MintPayment for Cln {
type Err = cdk_payment::Error; type Err = payment::Error;
async fn get_settings(&self) -> Result<Value, Self::Err> { async fn get_settings(&self) -> Result<Value, Self::Err> {
Ok(serde_json::to_value(Bolt11Settings { Ok(serde_json::to_value(Bolt11Settings {

View File

@@ -15,7 +15,7 @@ async-trait.workspace = true
anyhow.workspace = true anyhow.workspace = true
axum.workspace = true axum.workspace = true
bitcoin.workspace = true bitcoin.workspace = true
cdk = { workspace = true, features = ["mint"] } cdk-common = { workspace = true, features = ["mint"] }
futures.workspace = true futures.workspace = true
tokio.workspace = true tokio.workspace = true
tokio-util.workspace = true tokio-util.workspace = true

View File

@@ -19,7 +19,7 @@ pub enum Error {
Anyhow(#[from] anyhow::Error), Anyhow(#[from] anyhow::Error),
} }
impl From<Error> for cdk::cdk_payment::Error { impl From<Error> for cdk_common::payment::Error {
fn from(e: Error) -> Self { fn from(e: Error) -> Self {
Self::Lightning(Box::new(e)) Self::Lightning(Box::new(e))
} }

View File

@@ -13,15 +13,15 @@ use std::sync::Arc;
use anyhow::anyhow; use anyhow::anyhow;
use async_trait::async_trait; use async_trait::async_trait;
use axum::Router; use axum::Router;
use cdk::amount::{to_unit, Amount, MSAT_IN_SAT}; use cdk_common::amount::{to_unit, Amount, MSAT_IN_SAT};
use cdk::cdk_payment::{ use cdk_common::common::FeeReserve;
use cdk_common::nuts::{CurrencyUnit, MeltOptions, MeltQuoteState, MintQuoteState};
use cdk_common::payment::{
self, Bolt11Settings, CreateIncomingPaymentResponse, MakePaymentResponse, MintPayment, self, Bolt11Settings, CreateIncomingPaymentResponse, MakePaymentResponse, MintPayment,
PaymentQuoteResponse, PaymentQuoteResponse,
}; };
use cdk::nuts::{CurrencyUnit, MeltOptions, MeltQuoteState, MintQuoteState}; use cdk_common::util::unix_time;
use cdk::types::FeeReserve; use cdk_common::{mint, Bolt11Invoice};
use cdk::util::unix_time;
use cdk::{mint, Bolt11Invoice};
use error::Error; use error::Error;
use futures::stream::StreamExt; use futures::stream::StreamExt;
use futures::Stream; use futures::Stream;
@@ -77,7 +77,7 @@ impl LNbits {
#[async_trait] #[async_trait]
impl MintPayment for LNbits { impl MintPayment for LNbits {
type Err = cdk_payment::Error; type Err = payment::Error;
async fn get_settings(&self) -> Result<Value, Self::Err> { async fn get_settings(&self) -> Result<Value, Self::Err> {
Ok(serde_json::to_value(&self.settings)?) Ok(serde_json::to_value(&self.settings)?)
@@ -166,7 +166,7 @@ impl MintPayment for LNbits {
let amount_msat = match options { let amount_msat = match options {
Some(amount) => { Some(amount) => {
if matches!(amount, MeltOptions::Mpp { mpp: _ }) { if matches!(amount, MeltOptions::Mpp { mpp: _ }) {
return Err(cdk_payment::Error::UnsupportedPaymentOption); return Err(payment::Error::UnsupportedPaymentOption);
} }
amount.amount_msat() amount.amount_msat()
} }

View File

@@ -13,7 +13,7 @@ readme = "README.md"
[dependencies] [dependencies]
async-trait.workspace = true async-trait.workspace = true
anyhow.workspace = true anyhow.workspace = true
cdk = { workspace = true, features = ["mint"] } cdk-common = { workspace = true, features = ["mint"] }
fedimint-tonic-lnd = "0.2.0" fedimint-tonic-lnd = "0.2.0"
futures.workspace = true futures.workspace = true
tokio.workspace = true tokio.workspace = true

View File

@@ -38,7 +38,7 @@ pub enum Error {
InvalidConfig(String), InvalidConfig(String),
} }
impl From<Error> for cdk::cdk_payment::Error { impl From<Error> for cdk_common::payment::Error {
fn from(e: Error) -> Self { fn from(e: Error) -> Self {
Self::Lightning(Box::new(e)) Self::Lightning(Box::new(e))
} }

View File

@@ -15,16 +15,16 @@ use std::sync::Arc;
use anyhow::anyhow; use anyhow::anyhow;
use async_trait::async_trait; use async_trait::async_trait;
use cdk::amount::{to_unit, Amount, MSAT_IN_SAT}; use cdk_common::amount::{to_unit, Amount, MSAT_IN_SAT};
use cdk::cdk_payment::{ use cdk_common::bitcoin::hashes::Hash;
use cdk_common::common::FeeReserve;
use cdk_common::nuts::{CurrencyUnit, MeltOptions, MeltQuoteState, MintQuoteState};
use cdk_common::payment::{
self, Bolt11Settings, CreateIncomingPaymentResponse, MakePaymentResponse, MintPayment, self, Bolt11Settings, CreateIncomingPaymentResponse, MakePaymentResponse, MintPayment,
PaymentQuoteResponse, PaymentQuoteResponse,
}; };
use cdk::nuts::{CurrencyUnit, MeltOptions, MeltQuoteState, MintQuoteState}; use cdk_common::util::hex;
use cdk::secp256k1::hashes::Hash; use cdk_common::{mint, Bolt11Invoice};
use cdk::types::FeeReserve;
use cdk::util::hex;
use cdk::{mint, Bolt11Invoice};
use error::Error; use error::Error;
use fedimint_tonic_lnd::lnrpc::fee_limit::Limit; use fedimint_tonic_lnd::lnrpc::fee_limit::Limit;
use fedimint_tonic_lnd::lnrpc::payment::PaymentStatus; use fedimint_tonic_lnd::lnrpc::payment::PaymentStatus;
@@ -113,7 +113,7 @@ impl Lnd {
#[async_trait] #[async_trait]
impl MintPayment for Lnd { impl MintPayment for Lnd {
type Err = cdk_payment::Error; type Err = payment::Error;
#[instrument(skip_all)] #[instrument(skip_all)]
async fn get_settings(&self) -> Result<serde_json::Value, Self::Err> { async fn get_settings(&self) -> Result<serde_json::Value, Self::Err> {
@@ -522,7 +522,7 @@ impl MintPayment for Lnd {
unit: self.settings.unit.clone(), unit: self.settings.unit.clone(),
}); });
} else { } else {
return Err(cdk_payment::Error::UnknownPaymentState); return Err(payment::Error::UnknownPaymentState);
} }
} }
}; };