mirror of
https://github.com/aljazceru/cdk.git
synced 2025-12-20 14:14:49 +01:00
refactor: remove mint url from config
This commit is contained in:
@@ -4,7 +4,6 @@ use bitcoin::bip32::DerivationPath;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::mint_url::MintUrl;
|
||||
use crate::nuts::{MeltQuoteState, MintQuoteState};
|
||||
use crate::{Amount, CurrencyUnit, Id, KeySetInfo, PublicKey};
|
||||
|
||||
@@ -13,8 +12,6 @@ use crate::{Amount, CurrencyUnit, Id, KeySetInfo, PublicKey};
|
||||
pub struct MintQuote {
|
||||
/// Quote id
|
||||
pub id: Uuid,
|
||||
/// Mint Url
|
||||
pub mint_url: MintUrl,
|
||||
/// Amount of quote
|
||||
pub amount: Amount,
|
||||
/// Unit of quote
|
||||
@@ -34,7 +31,6 @@ pub struct MintQuote {
|
||||
impl MintQuote {
|
||||
/// Create new [`MintQuote`]
|
||||
pub fn new(
|
||||
mint_url: MintUrl,
|
||||
request: String,
|
||||
unit: CurrencyUnit,
|
||||
amount: Amount,
|
||||
@@ -45,7 +41,6 @@ impl MintQuote {
|
||||
let id = Uuid::new_v4();
|
||||
|
||||
Self {
|
||||
mint_url,
|
||||
id,
|
||||
amount,
|
||||
unit,
|
||||
|
||||
@@ -50,7 +50,6 @@ where
|
||||
|
||||
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());
|
||||
|
||||
@@ -175,7 +175,6 @@ pub async fn create_and_start_test_mint() -> anyhow::Result<Arc<Mint>> {
|
||||
|
||||
mint_builder = mint_builder
|
||||
.with_name("pure test mint".to_string())
|
||||
.with_mint_url("http://aa".to_string())
|
||||
.with_description("pure test mint".to_string())
|
||||
.with_quote_ttl(10000, 10000)
|
||||
.with_seed(mnemonic.to_seed_normalized("").to_vec());
|
||||
@@ -198,7 +197,7 @@ pub fn create_test_wallet_for_mint(mint: Arc<Mint>) -> anyhow::Result<Arc<Wallet
|
||||
let connector = DirectMintConnection::new(mint);
|
||||
|
||||
let seed = Mnemonic::generate(12)?.to_seed_normalized("");
|
||||
let mint_url = connector.mint.config.mint_url().to_string();
|
||||
let mint_url = "http://aa".to_string();
|
||||
let unit = CurrencyUnit::Sat;
|
||||
let localstore = WalletMemoryDatabase::default();
|
||||
let mut wallet = Wallet::new(&mint_url, unit, Arc::new(localstore), &seed, None)?;
|
||||
|
||||
@@ -169,7 +169,6 @@ where
|
||||
|
||||
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());
|
||||
|
||||
@@ -46,7 +46,6 @@ async fn new_mint(fee: u64) -> Mint {
|
||||
let quote_ttl = QuoteTTL::new(10000, 10000);
|
||||
|
||||
Mint::new(
|
||||
MINT_URL,
|
||||
&mnemonic.to_seed_normalized(""),
|
||||
mint_info,
|
||||
quote_ttl,
|
||||
@@ -72,7 +71,6 @@ async fn mint_proofs(
|
||||
let request_lookup = uuid::Uuid::new_v4().to_string();
|
||||
|
||||
let quote = MintQuote::new(
|
||||
mint.config.mint_url(),
|
||||
"".to_string(),
|
||||
CurrencyUnit::Sat,
|
||||
amount,
|
||||
|
||||
@@ -301,7 +301,6 @@ async fn main() -> anyhow::Result<()> {
|
||||
|
||||
mint_builder = mint_builder
|
||||
.with_name(settings.mint_info.name)
|
||||
.with_mint_url(settings.info.url)
|
||||
.with_version(mint_version)
|
||||
.with_description(settings.mint_info.description)
|
||||
.with_quote_ttl(10000, 10000)
|
||||
|
||||
@@ -202,7 +202,6 @@ impl From<V1MintQuote> for MintQuote {
|
||||
fn from(quote: V1MintQuote) -> MintQuote {
|
||||
MintQuote {
|
||||
id: quote.id,
|
||||
mint_url: quote.mint_url,
|
||||
amount: quote.amount,
|
||||
unit: quote.unit,
|
||||
request: quote.request.clone(),
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
ALTER TABLE mint_quote DROP COLUMN mint_url;
|
||||
@@ -10,7 +10,6 @@ use bitcoin::bip32::DerivationPath;
|
||||
use cdk_common::common::LnKey;
|
||||
use cdk_common::database::{self, MintDatabase};
|
||||
use cdk_common::mint::{self, MintKeySetInfo, MintQuote};
|
||||
use cdk_common::mint_url::MintUrl;
|
||||
use cdk_common::nut00::ProofsMethods;
|
||||
use cdk_common::nut05::QuoteState;
|
||||
use cdk_common::secret::Secret;
|
||||
@@ -206,12 +205,11 @@ WHERE active = 1
|
||||
let res = sqlx::query(
|
||||
r#"
|
||||
INSERT OR REPLACE INTO mint_quote
|
||||
(id, mint_url, amount, unit, request, state, expiry, request_lookup_id, pubkey)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);
|
||||
(id, amount, unit, request, state, expiry, request_lookup_id, pubkey)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?);
|
||||
"#,
|
||||
)
|
||||
.bind(quote.id.to_string())
|
||||
.bind(quote.mint_url.to_string())
|
||||
.bind(u64::from(quote.amount) as i64)
|
||||
.bind(quote.unit.to_string())
|
||||
.bind(quote.request)
|
||||
@@ -1250,7 +1248,6 @@ fn sqlite_row_to_keyset_info(row: SqliteRow) -> Result<MintKeySetInfo, Error> {
|
||||
|
||||
fn sqlite_row_to_mint_quote(row: SqliteRow) -> Result<MintQuote, Error> {
|
||||
let row_id: Hyphenated = row.try_get("id").map_err(Error::from)?;
|
||||
let row_mint_url: String = row.try_get("mint_url").map_err(Error::from)?;
|
||||
let row_amount: i64 = row.try_get("amount").map_err(Error::from)?;
|
||||
let row_unit: String = row.try_get("unit").map_err(Error::from)?;
|
||||
let row_request: String = row.try_get("request").map_err(Error::from)?;
|
||||
@@ -1274,7 +1271,6 @@ fn sqlite_row_to_mint_quote(row: SqliteRow) -> Result<MintQuote, Error> {
|
||||
|
||||
Ok(MintQuote {
|
||||
id: row_id.into_uuid(),
|
||||
mint_url: MintUrl::from_str(&row_mint_url)?,
|
||||
amount: Amount::from(row_amount as u64),
|
||||
unit: CurrencyUnit::from_str(&row_unit).map_err(Error::from)?,
|
||||
request: row_request,
|
||||
|
||||
@@ -21,8 +21,6 @@ use crate::types::{LnKey, QuoteTTL};
|
||||
/// Cashu Mint
|
||||
#[derive(Default)]
|
||||
pub struct MintBuilder {
|
||||
/// Mint Url
|
||||
mint_url: Option<String>,
|
||||
/// Mint Info
|
||||
mint_info: MintInfo,
|
||||
/// Mint Storage backend
|
||||
@@ -63,12 +61,6 @@ impl MintBuilder {
|
||||
self
|
||||
}
|
||||
|
||||
/// Set mint url
|
||||
pub fn with_mint_url(mut self, mint_url: String) -> Self {
|
||||
self.mint_url = Some(mint_url);
|
||||
self
|
||||
}
|
||||
|
||||
/// Set seed
|
||||
pub fn with_seed(mut self, seed: Vec<u8>) -> Self {
|
||||
self.seed = Some(seed);
|
||||
@@ -227,7 +219,6 @@ impl MintBuilder {
|
||||
/// Build mint
|
||||
pub async fn build(&self) -> anyhow::Result<Mint> {
|
||||
Ok(Mint::new(
|
||||
self.mint_url.as_ref().ok_or(anyhow!("Mint url not set"))?,
|
||||
self.seed.as_ref().ok_or(anyhow!("Mint seed not set"))?,
|
||||
self.mint_info.clone(),
|
||||
self.quote_ttl.ok_or(anyhow!("Quote ttl not set"))?,
|
||||
|
||||
@@ -7,7 +7,6 @@ use std::sync::Arc;
|
||||
use arc_swap::ArcSwap;
|
||||
|
||||
use super::{Id, MintInfo, MintKeySet};
|
||||
use crate::mint_url::MintUrl;
|
||||
use crate::types::QuoteTTL;
|
||||
|
||||
/// Mint Inner configuration
|
||||
@@ -16,8 +15,6 @@ pub struct Config {
|
||||
pub keysets: HashMap<Id, MintKeySet>,
|
||||
/// Mint url
|
||||
pub mint_info: MintInfo,
|
||||
/// Mint config
|
||||
pub mint_url: MintUrl,
|
||||
/// Quotes ttl
|
||||
pub quote_ttl: QuoteTTL,
|
||||
}
|
||||
@@ -36,17 +33,11 @@ pub struct SwappableConfig {
|
||||
|
||||
impl SwappableConfig {
|
||||
/// Creates a new configuration instance
|
||||
pub fn new(
|
||||
mint_url: MintUrl,
|
||||
quote_ttl: QuoteTTL,
|
||||
mint_info: MintInfo,
|
||||
keysets: HashMap<Id, MintKeySet>,
|
||||
) -> Self {
|
||||
pub fn new(quote_ttl: QuoteTTL, mint_info: MintInfo, keysets: HashMap<Id, MintKeySet>) -> Self {
|
||||
let inner = Config {
|
||||
keysets,
|
||||
quote_ttl,
|
||||
mint_info,
|
||||
mint_url,
|
||||
};
|
||||
|
||||
Self {
|
||||
@@ -59,24 +50,6 @@ impl SwappableConfig {
|
||||
self.config.load().clone()
|
||||
}
|
||||
|
||||
/// Gets a copy of the mint url
|
||||
pub fn mint_url(&self) -> MintUrl {
|
||||
self.load().mint_url.clone()
|
||||
}
|
||||
|
||||
/// Replace the current mint url with a new one
|
||||
pub fn set_mint_url(&self, mint_url: MintUrl) {
|
||||
let current_inner = self.load();
|
||||
let new_inner = Config {
|
||||
mint_url,
|
||||
quote_ttl: current_inner.quote_ttl,
|
||||
mint_info: current_inner.mint_info.clone(),
|
||||
keysets: current_inner.keysets.clone(),
|
||||
};
|
||||
|
||||
self.config.store(Arc::new(new_inner));
|
||||
}
|
||||
|
||||
/// Gets a copy of the quote ttl
|
||||
pub fn quote_ttl(&self) -> QuoteTTL {
|
||||
self.load().quote_ttl
|
||||
@@ -87,7 +60,6 @@ impl SwappableConfig {
|
||||
let current_inner = self.load();
|
||||
let new_inner = Config {
|
||||
mint_info: current_inner.mint_info.clone(),
|
||||
mint_url: current_inner.mint_url.clone(),
|
||||
quote_ttl,
|
||||
keysets: current_inner.keysets.clone(),
|
||||
};
|
||||
@@ -105,7 +77,6 @@ impl SwappableConfig {
|
||||
let current_inner = self.load();
|
||||
let new_inner = Config {
|
||||
mint_info,
|
||||
mint_url: current_inner.mint_url.clone(),
|
||||
quote_ttl: current_inner.quote_ttl,
|
||||
keysets: current_inner.keysets.clone(),
|
||||
};
|
||||
@@ -119,7 +90,6 @@ impl SwappableConfig {
|
||||
let new_inner = Config {
|
||||
mint_info: current_inner.mint_info.clone(),
|
||||
quote_ttl: current_inner.quote_ttl,
|
||||
mint_url: current_inner.mint_url.clone(),
|
||||
keysets,
|
||||
};
|
||||
|
||||
|
||||
@@ -1,21 +1,8 @@
|
||||
use tracing::instrument;
|
||||
|
||||
use super::{Mint, MintInfo};
|
||||
use crate::mint_url::MintUrl;
|
||||
|
||||
impl Mint {
|
||||
/// Set Mint Url
|
||||
#[instrument(skip_all)]
|
||||
pub fn set_mint_url(&self, mint_url: MintUrl) {
|
||||
self.config.set_mint_url(mint_url);
|
||||
}
|
||||
|
||||
/// Get Mint Url
|
||||
#[instrument(skip_all)]
|
||||
pub fn get_mint_url(&self) -> MintUrl {
|
||||
self.config.mint_url()
|
||||
}
|
||||
|
||||
/// Set Mint Info
|
||||
#[instrument(skip_all)]
|
||||
pub fn set_mint_info(&self, mint_info: MintInfo) {
|
||||
|
||||
@@ -101,7 +101,6 @@ impl Mint {
|
||||
})?;
|
||||
|
||||
let quote = MintQuote::new(
|
||||
self.config.mint_url(),
|
||||
create_invoice_response.request.to_string(),
|
||||
unit.clone(),
|
||||
amount,
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
//! Cashu Mint
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::str::FromStr;
|
||||
use std::sync::Arc;
|
||||
|
||||
use bitcoin::bip32::{ChildNumber, DerivationPath, Xpriv};
|
||||
@@ -22,7 +21,6 @@ use crate::cdk_lightning::{self, MintLightning};
|
||||
use crate::dhke::{sign_message, verify_message};
|
||||
use crate::error::Error;
|
||||
use crate::fees::calculate_fee;
|
||||
use crate::mint_url::MintUrl;
|
||||
use crate::nuts::*;
|
||||
use crate::util::unix_time;
|
||||
use crate::Amount;
|
||||
@@ -60,7 +58,6 @@ impl Mint {
|
||||
/// Create new [`Mint`]
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub async fn new(
|
||||
mint_url: &str,
|
||||
seed: &[u8],
|
||||
mint_info: MintInfo,
|
||||
quote_ttl: QuoteTTL,
|
||||
@@ -183,12 +180,7 @@ impl Mint {
|
||||
}
|
||||
|
||||
Ok(Self {
|
||||
config: SwappableConfig::new(
|
||||
MintUrl::from_str(mint_url)?,
|
||||
quote_ttl,
|
||||
mint_info,
|
||||
active_keysets,
|
||||
),
|
||||
config: SwappableConfig::new(quote_ttl, mint_info, active_keysets),
|
||||
pubsub_manager: Arc::new(localstore.clone().into()),
|
||||
secp_ctx,
|
||||
xpriv,
|
||||
@@ -564,6 +556,7 @@ fn derivation_path_from_unit(unit: CurrencyUnit, index: u32) -> Option<Derivatio
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::collections::HashSet;
|
||||
use std::str::FromStr;
|
||||
|
||||
use bitcoin::Network;
|
||||
use cdk_common::common::{LnKey, QuoteTTL};
|
||||
@@ -571,6 +564,7 @@ mod tests {
|
||||
use uuid::Uuid;
|
||||
|
||||
use super::*;
|
||||
use crate::cdk_database::mint_memory::MintMemoryDatabase;
|
||||
|
||||
#[test]
|
||||
fn mint_mod_generate_keyset_from_seed() {
|
||||
@@ -658,8 +652,6 @@ mod tests {
|
||||
assert_eq!(amounts_and_pubkeys, expected_amounts_and_pubkeys);
|
||||
}
|
||||
|
||||
use crate::cdk_database::mint_memory::MintMemoryDatabase;
|
||||
|
||||
#[derive(Default)]
|
||||
struct MintConfig<'a> {
|
||||
active_keysets: HashMap<CurrencyUnit, Id>,
|
||||
@@ -671,7 +663,6 @@ mod tests {
|
||||
blinded_signatures: HashMap<[u8; 33], BlindSignature>,
|
||||
quote_proofs: HashMap<Uuid, Vec<PublicKey>>,
|
||||
quote_signatures: HashMap<Uuid, Vec<BlindSignature>>,
|
||||
mint_url: &'a str,
|
||||
seed: &'a [u8],
|
||||
mint_info: MintInfo,
|
||||
supported_units: HashMap<CurrencyUnit, (u64, u8)>,
|
||||
@@ -697,7 +688,6 @@ mod tests {
|
||||
);
|
||||
|
||||
Mint::new(
|
||||
config.mint_url,
|
||||
config.seed,
|
||||
config.mint_info,
|
||||
config.quote_ttl,
|
||||
@@ -712,12 +702,10 @@ mod tests {
|
||||
#[tokio::test]
|
||||
async fn mint_mod_new_mint() -> Result<(), Error> {
|
||||
let config = MintConfig::<'_> {
|
||||
mint_url: "http://example.com",
|
||||
..Default::default()
|
||||
};
|
||||
let mint = create_mint(config).await?;
|
||||
|
||||
assert_eq!(mint.get_mint_url().to_string(), "http://example.com");
|
||||
let info = mint.mint_info();
|
||||
assert!(info.name.is_none());
|
||||
assert!(info.pubkey.is_none());
|
||||
@@ -751,7 +739,6 @@ mod tests {
|
||||
#[tokio::test]
|
||||
async fn mint_mod_rotate_keyset() -> Result<(), Error> {
|
||||
let config = MintConfig::<'_> {
|
||||
mint_url: "http://example.com",
|
||||
..Default::default()
|
||||
};
|
||||
let mint = create_mint(config).await?;
|
||||
@@ -796,7 +783,6 @@ mod tests {
|
||||
println!("{}", seed);
|
||||
|
||||
let config = MintConfig::<'_> {
|
||||
mint_url: "http://example.com",
|
||||
seed: &seed.to_seed_normalized(""),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user