init_fake_wallet.rs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. use std::collections::{HashMap, HashSet};
  2. use std::sync::Arc;
  3. use anyhow::Result;
  4. use bip39::Mnemonic;
  5. use cdk::cdk_database::{self, MintDatabase};
  6. use cdk::mint::{FeeReserve, MintBuilder, MintMeltLimits};
  7. use cdk::nuts::{CurrencyUnit, PaymentMethod};
  8. use cdk_fake_wallet::FakeWallet;
  9. use tracing_subscriber::EnvFilter;
  10. use crate::init_mint::start_mint;
  11. pub async fn start_fake_mint<D>(addr: &str, port: u16, database: D) -> Result<()>
  12. where
  13. D: MintDatabase<Err = cdk_database::Error> + Send + Sync + 'static,
  14. {
  15. let default_filter = "debug";
  16. let sqlx_filter = "sqlx=warn";
  17. let hyper_filter = "hyper=warn";
  18. let env_filter = EnvFilter::new(format!(
  19. "{},{},{}",
  20. default_filter, sqlx_filter, hyper_filter
  21. ));
  22. // Parse input
  23. tracing_subscriber::fmt().with_env_filter(env_filter).init();
  24. let fee_reserve = FeeReserve {
  25. min_fee_reserve: 1.into(),
  26. percent_fee_reserve: 1.0,
  27. };
  28. let fake_wallet = FakeWallet::new(fee_reserve, HashMap::default(), HashSet::default(), 0);
  29. let mut mint_builder = MintBuilder::new();
  30. mint_builder = mint_builder.with_localstore(Arc::new(database));
  31. mint_builder = mint_builder.add_ln_backend(
  32. CurrencyUnit::Sat,
  33. PaymentMethod::Bolt11,
  34. MintMeltLimits::new(1, 5_000),
  35. Arc::new(fake_wallet),
  36. );
  37. let mnemonic = Mnemonic::generate(12)?;
  38. mint_builder = mint_builder
  39. .with_name("fake test mint".to_string())
  40. .with_description("fake test mint".to_string())
  41. .with_quote_ttl(10000, 10000)
  42. .with_seed(mnemonic.to_seed_normalized("").to_vec());
  43. let mint = mint_builder.build().await?;
  44. start_mint(addr, port, mint).await?;
  45. Ok(())
  46. }