mirror of
https://github.com/aljazceru/cdk.git
synced 2025-12-22 23:25:22 +01:00
feat: lnd mint
This commit is contained in:
@@ -3,10 +3,10 @@ use std::env;
|
||||
use anyhow::Result;
|
||||
use cdk::cdk_database::mint_memory::MintMemoryDatabase;
|
||||
use cdk_integration_tests::init_regtest::{
|
||||
create_cln_backend, create_mint, fund_ln, generate_block, get_bitcoin_dir, get_cln_dir,
|
||||
get_lnd_cert_file_path, get_lnd_dir, get_lnd_macaroon_path, get_temp_dir, init_bitcoin_client,
|
||||
init_bitcoind, init_lnd, open_channel, BITCOIN_RPC_PASS, BITCOIN_RPC_USER, LND_ADDR,
|
||||
LND_RPC_ADDR, LND_TWO_ADDR, LND_TWO_RPC_ADDR,
|
||||
create_cln_backend, create_lnd_backend, create_mint, fund_ln, generate_block, get_bitcoin_dir,
|
||||
get_cln_dir, get_lnd_cert_file_path, get_lnd_dir, get_lnd_macaroon_path, get_temp_dir,
|
||||
init_bitcoin_client, init_bitcoind, init_lnd, open_channel, BITCOIN_RPC_PASS, BITCOIN_RPC_USER,
|
||||
LND_ADDR, LND_RPC_ADDR, LND_TWO_ADDR, LND_TWO_RPC_ADDR,
|
||||
};
|
||||
use cdk_redb::MintRedbDatabase;
|
||||
use cdk_sqlite::MintSqliteDatabase;
|
||||
@@ -24,10 +24,11 @@ async fn main() -> Result<()> {
|
||||
let sqlx_filter = "sqlx=warn";
|
||||
let hyper_filter = "hyper=warn";
|
||||
let h2_filter = "h2=warn";
|
||||
let rustls_filter = "rustls=warn";
|
||||
|
||||
let env_filter = EnvFilter::new(format!(
|
||||
"{},{},{},{}",
|
||||
default_filter, sqlx_filter, hyper_filter, h2_filter
|
||||
"{},{},{},{},{}",
|
||||
default_filter, sqlx_filter, hyper_filter, h2_filter, rustls_filter
|
||||
));
|
||||
|
||||
tracing_subscriber::fmt().with_env_filter(env_filter).init();
|
||||
@@ -141,27 +142,66 @@ async fn main() -> Result<()> {
|
||||
lnd_two_client.wait_channels_active().await?;
|
||||
}
|
||||
|
||||
let addr = "127.0.0.1";
|
||||
let port = 8085;
|
||||
let mint_addr = "127.0.0.1";
|
||||
let cln_mint_port = 8085;
|
||||
|
||||
let mint_db_kind = env::var("MINT_DATABASE")?;
|
||||
|
||||
let db_path = get_temp_dir().join("mint");
|
||||
let lnd_mint_db_path = get_temp_dir().join("lnd_mint");
|
||||
let cln_mint_db_path = get_temp_dir().join("cln_mint");
|
||||
|
||||
let cln_backend = create_cln_backend(&cln_client).await?;
|
||||
let lnd_mint_port = 8087;
|
||||
|
||||
let lnd_backend = create_lnd_backend(&lnd_two_client).await?;
|
||||
|
||||
match mint_db_kind.as_str() {
|
||||
"MEMORY" => {
|
||||
create_mint(addr, port, MintMemoryDatabase::default(), cln_backend).await?;
|
||||
tokio::spawn(async move {
|
||||
create_mint(
|
||||
mint_addr,
|
||||
cln_mint_port,
|
||||
MintMemoryDatabase::default(),
|
||||
cln_backend,
|
||||
)
|
||||
.await
|
||||
.expect("Could not start cln mint");
|
||||
});
|
||||
|
||||
create_mint(
|
||||
mint_addr,
|
||||
lnd_mint_port,
|
||||
MintMemoryDatabase::default(),
|
||||
lnd_backend,
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
"SQLITE" => {
|
||||
let sqlite_db = MintSqliteDatabase::new(&db_path).await?;
|
||||
tokio::spawn(async move {
|
||||
let sqlite_db = MintSqliteDatabase::new(&cln_mint_db_path)
|
||||
.await
|
||||
.expect("Could not create mint db");
|
||||
sqlite_db.migrate().await;
|
||||
create_mint(mint_addr, cln_mint_port, sqlite_db, cln_backend)
|
||||
.await
|
||||
.expect("Could not start cln mint");
|
||||
});
|
||||
|
||||
let sqlite_db = MintSqliteDatabase::new(&lnd_mint_db_path).await?;
|
||||
sqlite_db.migrate().await;
|
||||
create_mint(addr, port, sqlite_db, cln_backend).await?;
|
||||
create_mint(mint_addr, lnd_mint_port, sqlite_db, lnd_backend).await?;
|
||||
}
|
||||
"REDB" => {
|
||||
let redb_db = MintRedbDatabase::new(&db_path).unwrap();
|
||||
create_mint(addr, port, redb_db, cln_backend).await?;
|
||||
tokio::spawn(async move {
|
||||
let redb_db = MintRedbDatabase::new(&cln_mint_db_path).unwrap();
|
||||
create_mint(mint_addr, cln_mint_port, redb_db, cln_backend)
|
||||
.await
|
||||
.expect("Could not start cln mint");
|
||||
});
|
||||
|
||||
let redb_db = MintRedbDatabase::new(&lnd_mint_db_path).unwrap();
|
||||
|
||||
create_mint(mint_addr, lnd_mint_port, redb_db, lnd_backend).await?;
|
||||
}
|
||||
_ => panic!("Unknown mint db type: {}", mint_db_kind),
|
||||
};
|
||||
|
||||
@@ -281,8 +281,8 @@ async fn test_pay_invoice_twice() -> Result<()> {
|
||||
match melt_two {
|
||||
Err(err) => match err {
|
||||
cdk::Error::RequestAlreadyPaid => (),
|
||||
_ => {
|
||||
bail!("Wrong invoice already paid");
|
||||
err => {
|
||||
bail!("Wrong invoice already paid: {}", err.to_string());
|
||||
}
|
||||
},
|
||||
Ok(_) => {
|
||||
|
||||
@@ -29,6 +29,7 @@ use fedimint_tonic_lnd::Client;
|
||||
use futures::{Stream, StreamExt};
|
||||
use tokio::sync::Mutex;
|
||||
use tokio_util::sync::CancellationToken;
|
||||
use tracing::instrument;
|
||||
|
||||
pub mod error;
|
||||
|
||||
@@ -189,6 +190,7 @@ impl MintLightning for Lnd {
|
||||
})
|
||||
}
|
||||
|
||||
#[instrument(skip_all)]
|
||||
async fn pay_invoice(
|
||||
&self,
|
||||
melt_quote: mint::MeltQuote,
|
||||
@@ -225,7 +227,10 @@ impl MintLightning for Lnd {
|
||||
.lightning()
|
||||
.send_payment_sync(fedimint_tonic_lnd::tonic::Request::new(pay_req))
|
||||
.await
|
||||
.map_err(|_| Error::PaymentFailed)?
|
||||
.map_err(|err| {
|
||||
tracing::warn!("Lightning payment failed: {}", err);
|
||||
Error::PaymentFailed
|
||||
})?
|
||||
.into_inner();
|
||||
|
||||
let total_amount = payment_response
|
||||
|
||||
@@ -28,7 +28,7 @@ cleanup() {
|
||||
}
|
||||
|
||||
# Set up trap to call cleanup on script exit
|
||||
trap cleanup EXIT
|
||||
# trap cleanup EXIT
|
||||
|
||||
# Create a temporary directory
|
||||
export cdk_itests=$(mktemp -d)
|
||||
@@ -82,10 +82,14 @@ done
|
||||
|
||||
|
||||
# Run cargo test
|
||||
cargo test -p cdk-integration-tests --test regtest
|
||||
# cargo test -p cdk-integration-tests --test regtest
|
||||
|
||||
# Run cargo test with the http_subscription feature
|
||||
cargo test -p cdk-integration-tests --test regtest --features http_subscription
|
||||
# # Run cargo test with the http_subscription feature
|
||||
# cargo test -p cdk-integration-tests --test regtest --features http_subscription
|
||||
|
||||
# Run tests with lnd mint
|
||||
export cdk_itests_mint_port=8087;
|
||||
cargo test -p cdk-integration-tests --test regtest
|
||||
|
||||
# Capture the exit status of cargo test
|
||||
test_status=$?
|
||||
|
||||
Reference in New Issue
Block a user