Browse Source

feat: abstract create mint

thesimplekid 2 months ago
parent
commit
ed23853d5d

+ 10 - 5
crates/cdk-integration-tests/src/bin/regtest_mint.rs

@@ -3,8 +3,9 @@ use std::env;
 use anyhow::Result;
 use cdk::cdk_database::mint_memory::MintMemoryDatabase;
 use cdk_integration_tests::init_regtest::{
-    fund_ln, get_bitcoin_dir, get_cln_dir, get_temp_dir, init_bitcoin_client, init_bitcoind,
-    init_lnd, init_lnd_client, open_channel, start_cln_mint, BITCOIN_RPC_PASS, BITCOIN_RPC_USER,
+    create_cln_backend, create_mint, fund_ln, get_bitcoin_dir, get_cln_dir, get_temp_dir,
+    init_bitcoin_client, init_bitcoind, init_lnd, init_lnd_client, open_channel, BITCOIN_RPC_PASS,
+    BITCOIN_RPC_USER,
 };
 use cdk_redb::MintRedbDatabase;
 use cdk_sqlite::MintSqliteDatabase;
@@ -96,18 +97,22 @@ async fn main() -> Result<()> {
     let db_path = get_temp_dir().join("mint");
     let cln_path = temp_dir_path.join("one");
 
+    let cln_client = ClnClient::new(cln_path, None).await?;
+
+    let cln_backend = create_cln_backend(&cln_client).await?;
+
     match mint_db_kind.as_str() {
         "MEMORY" => {
-            start_cln_mint(addr, port, MintMemoryDatabase::default(), cln_path).await?;
+            create_mint(addr, port, MintMemoryDatabase::default(), cln_backend).await?;
         }
         "SQLITE" => {
             let sqlite_db = MintSqliteDatabase::new(&db_path).await?;
             sqlite_db.migrate().await;
-            start_cln_mint(addr, port, sqlite_db, cln_path).await?;
+            create_mint(addr, port, sqlite_db, cln_backend).await?;
         }
         "REDB" => {
             let redb_db = MintRedbDatabase::new(&db_path).unwrap();
-            start_cln_mint(addr, port, redb_db, cln_path).await?;
+            create_mint(addr, port, redb_db, cln_backend).await?;
         }
         _ => panic!("Unknown mint db type: {}", mint_db_kind),
     };

+ 4 - 6
crates/cdk-integration-tests/src/init_regtest.rs

@@ -5,6 +5,7 @@ use std::sync::Arc;
 use anyhow::Result;
 use bip39::Mnemonic;
 use cdk::cdk_database::{self, MintDatabase};
+use cdk::cdk_lightning::{self, MintLightning};
 use cdk::mint::{FeeReserve, MintBuilder, MintMeltLimits};
 use cdk::nuts::{CurrencyUnit, PaymentMethod};
 use cdk_cln::Cln as CdkCln;
@@ -124,14 +125,11 @@ pub async fn create_cln_backend(cln_client: &ClnClient) -> Result<CdkCln> {
     Ok(CdkCln::new(rpc_path, fee_reserve).await?)
 }
 
-pub async fn start_cln_mint<D>(addr: &str, port: u16, database: D, dir: PathBuf) -> Result<()>
+pub async fn create_mint<D, L>(addr: &str, port: u16, database: D, lighting: L) -> Result<()>
 where
     D: MintDatabase<Err = cdk_database::Error> + Send + Sync + 'static,
+    L: MintLightning<Err = cdk_lightning::Error> + Send + Sync + 'static,
 {
-    let cln_client = ClnClient::new(dir.clone(), None).await?;
-
-    let cln_backend = create_cln_backend(&cln_client).await?;
-
     let mut mint_builder = MintBuilder::new();
 
     mint_builder = mint_builder.with_localstore(Arc::new(database));
@@ -140,7 +138,7 @@ where
         CurrencyUnit::Sat,
         PaymentMethod::Bolt11,
         MintMeltLimits::new(1, 5_000),
-        Arc::new(cln_backend),
+        Arc::new(lighting),
     );
 
     let mnemonic = Mnemonic::generate(12)?;