mirror of
https://github.com/aljazceru/cdk.git
synced 2025-12-24 08:05:02 +01:00
Merge pull request #531 from thesimplekid/itest_mint_builder
refactor: mint builder in itest
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
//! CDK common types and traits
|
||||
//!
|
||||
pub mod amount;
|
||||
pub mod dhke;
|
||||
#[cfg(feature = "mint")]
|
||||
|
||||
@@ -3,18 +3,15 @@ use std::sync::Arc;
|
||||
|
||||
use anyhow::Result;
|
||||
use axum::Router;
|
||||
use bip39::Mnemonic;
|
||||
use cdk::cdk_database::{self, MintDatabase};
|
||||
use cdk::cdk_lightning::MintLightning;
|
||||
use cdk::mint::FeeReserve;
|
||||
use cdk::nuts::CurrencyUnit;
|
||||
use cdk::types::LnKey;
|
||||
use cdk::mint::{FeeReserve, MintBuilder, MintMeltLimits};
|
||||
use cdk::nuts::{CurrencyUnit, PaymentMethod};
|
||||
use cdk_fake_wallet::FakeWallet;
|
||||
use tokio::sync::Notify;
|
||||
use tower_http::cors::CorsLayer;
|
||||
use tracing_subscriber::EnvFilter;
|
||||
|
||||
use crate::init_regtest::create_mint;
|
||||
|
||||
pub async fn start_fake_mint<D>(addr: &str, port: u16, database: D) -> Result<()>
|
||||
where
|
||||
D: MintDatabase<Err = cdk_database::Error> + Send + Sync + 'static,
|
||||
@@ -32,11 +29,6 @@ where
|
||||
// Parse input
|
||||
tracing_subscriber::fmt().with_env_filter(env_filter).init();
|
||||
|
||||
let mut ln_backends: HashMap<
|
||||
LnKey,
|
||||
Arc<dyn MintLightning<Err = cdk::cdk_lightning::Error> + Sync + Send>,
|
||||
> = HashMap::new();
|
||||
|
||||
let fee_reserve = FeeReserve {
|
||||
min_fee_reserve: 1.into(),
|
||||
percent_fee_reserve: 1.0,
|
||||
@@ -44,12 +36,28 @@ where
|
||||
|
||||
let fake_wallet = FakeWallet::new(fee_reserve, HashMap::default(), HashSet::default(), 0);
|
||||
|
||||
ln_backends.insert(
|
||||
LnKey::new(CurrencyUnit::Sat, cdk::nuts::PaymentMethod::Bolt11),
|
||||
let mut mint_builder = MintBuilder::new();
|
||||
|
||||
mint_builder = mint_builder.with_localstore(Arc::new(database));
|
||||
|
||||
mint_builder = mint_builder.add_ln_backend(
|
||||
CurrencyUnit::Sat,
|
||||
PaymentMethod::Bolt11,
|
||||
MintMeltLimits::default(),
|
||||
Arc::new(fake_wallet),
|
||||
);
|
||||
|
||||
let mint = create_mint(database, ln_backends.clone()).await?;
|
||||
let mnemonic = Mnemonic::generate(12)?;
|
||||
|
||||
mint_builder = mint_builder
|
||||
.with_name("fake test mint".to_string())
|
||||
.with_mint_url(format!("http://{addr}:{port}"))
|
||||
.with_description("fake test mint".to_string())
|
||||
.with_quote_ttl(10000, 10000)
|
||||
.with_seed(mnemonic.to_seed_normalized("").to_vec());
|
||||
|
||||
let mint = mint_builder.build().await?;
|
||||
|
||||
let mint_arc = Arc::new(mint);
|
||||
|
||||
let v1_service = cdk_axum::create_mint_router(Arc::clone(&mint_arc))
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use std::collections::HashMap;
|
||||
use std::env;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
@@ -7,10 +6,8 @@ use anyhow::Result;
|
||||
use axum::Router;
|
||||
use bip39::Mnemonic;
|
||||
use cdk::cdk_database::{self, MintDatabase};
|
||||
use cdk::cdk_lightning::MintLightning;
|
||||
use cdk::mint::{FeeReserve, Mint};
|
||||
use cdk::nuts::{CurrencyUnit, MintInfo};
|
||||
use cdk::types::{LnKey, QuoteTTL};
|
||||
use cdk::mint::{FeeReserve, MintBuilder, MintMeltLimits};
|
||||
use cdk::nuts::{CurrencyUnit, PaymentMethod};
|
||||
use cdk_cln::Cln as CdkCln;
|
||||
use ln_regtest_rs::bitcoin_client::BitcoinClient;
|
||||
use ln_regtest_rs::bitcoind::Bitcoind;
|
||||
@@ -145,49 +142,6 @@ pub async fn create_cln_backend(cln_client: &ClnClient) -> Result<CdkCln> {
|
||||
Ok(CdkCln::new(rpc_path, fee_reserve).await?)
|
||||
}
|
||||
|
||||
pub async fn create_mint<D>(
|
||||
database: D,
|
||||
ln_backends: HashMap<
|
||||
LnKey,
|
||||
Arc<dyn MintLightning<Err = cdk::cdk_lightning::Error> + Sync + Send>,
|
||||
>,
|
||||
) -> Result<Mint>
|
||||
where
|
||||
D: MintDatabase<Err = cdk_database::Error> + Send + Sync + 'static,
|
||||
{
|
||||
let nuts = cdk::nuts::Nuts::new()
|
||||
.nut07(true)
|
||||
.nut08(true)
|
||||
.nut09(true)
|
||||
.nut10(true)
|
||||
.nut11(true)
|
||||
.nut12(true)
|
||||
.nut14(true);
|
||||
|
||||
let mint_info = MintInfo::new().nuts(nuts);
|
||||
|
||||
let mnemonic = Mnemonic::generate(12)?;
|
||||
|
||||
let mut supported_units: HashMap<CurrencyUnit, (u64, u8)> = HashMap::new();
|
||||
supported_units.insert(CurrencyUnit::Sat, (0, 32));
|
||||
|
||||
let quote_ttl = QuoteTTL::new(10000, 10000);
|
||||
|
||||
let mint = Mint::new(
|
||||
&get_mint_url(),
|
||||
&mnemonic.to_seed_normalized(""),
|
||||
mint_info,
|
||||
quote_ttl,
|
||||
Arc::new(database),
|
||||
ln_backends,
|
||||
supported_units,
|
||||
HashMap::new(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(mint)
|
||||
}
|
||||
|
||||
pub async fn start_cln_mint<D>(addr: &str, port: u16, database: D) -> Result<()>
|
||||
where
|
||||
D: MintDatabase<Err = cdk_database::Error> + Send + Sync + 'static,
|
||||
@@ -196,17 +150,28 @@ where
|
||||
|
||||
let cln_backend = create_cln_backend(&cln_client).await?;
|
||||
|
||||
let mut ln_backends: HashMap<
|
||||
LnKey,
|
||||
Arc<dyn MintLightning<Err = cdk::cdk_lightning::Error> + Sync + Send>,
|
||||
> = HashMap::new();
|
||||
let mut mint_builder = MintBuilder::new();
|
||||
|
||||
ln_backends.insert(
|
||||
LnKey::new(CurrencyUnit::Sat, cdk::nuts::PaymentMethod::Bolt11),
|
||||
mint_builder = mint_builder.with_localstore(Arc::new(database));
|
||||
|
||||
mint_builder = mint_builder.add_ln_backend(
|
||||
CurrencyUnit::Sat,
|
||||
PaymentMethod::Bolt11,
|
||||
MintMeltLimits::default(),
|
||||
Arc::new(cln_backend),
|
||||
);
|
||||
|
||||
let mint = create_mint(database, ln_backends.clone()).await?;
|
||||
let mnemonic = Mnemonic::generate(12)?;
|
||||
|
||||
mint_builder = mint_builder
|
||||
.with_name("regtest mint".to_string())
|
||||
.with_mint_url(format!("http://{addr}:{port}"))
|
||||
.with_description("regtest mint".to_string())
|
||||
.with_quote_ttl(10000, 10000)
|
||||
.with_seed(mnemonic.to_seed_normalized("").to_vec());
|
||||
|
||||
let mint = mint_builder.build().await?;
|
||||
|
||||
let mint_arc = Arc::new(mint);
|
||||
|
||||
let v1_service = cdk_axum::create_mint_router(Arc::clone(&mint_arc))
|
||||
|
||||
@@ -145,8 +145,8 @@ impl Wallet {
|
||||
/// use anyhow::Result;
|
||||
/// use cdk::amount::{Amount, SplitTarget};
|
||||
/// use cdk::cdk_database::WalletMemoryDatabase;
|
||||
/// use cdk::nuts::CurrencyUnit;
|
||||
/// use cdk::nuts::nut00::ProofsMethods;
|
||||
/// use cdk::nuts::CurrencyUnit;
|
||||
/// use cdk::wallet::Wallet;
|
||||
/// use rand::Rng;
|
||||
///
|
||||
|
||||
Reference in New Issue
Block a user