Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions crates/cdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ bitcoin = { version = "0.32.2", features = [
"rand",
"rand-std",
] }
bitcoin_hashes = { version = "0.16", features = ["serde"] }
ciborium = { version = "0.2.2", default-features = false, features = ["std"] }
lightning-invoice = { version = "0.32.0", features = ["serde", "std"] }
regex = "1"
Expand Down Expand Up @@ -101,6 +102,7 @@ rand = "0.8.5"
bip39 = "2.0"
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
criterion = "0.5.1"
cdk-integration-tests = { path = "../cdk-integration-tests" }

[[bench]]
name = "dhke_benchmarks"
Expand Down
66 changes: 63 additions & 3 deletions crates/cdk/src/mint/mint_nut04.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use cdk_common::nut04::{MintMiningShareRequest, MintQuoteMiningShareRequest, MintQuoteMiningShareResponse};
use cdk_common::BlindedMessage;
use tracing::instrument;
use tracing::{instrument, debug};
use uuid::Uuid;

use super::verification::Verification;
Expand Down Expand Up @@ -183,8 +183,11 @@ impl Mint {
};

self.process_mining_mint_request(mint_mining_share_request).await?;

let quote: MintQuoteMiningShareResponse<Uuid> = quote.into();
debug!("Successfully processed mining mint request for quote {}", quote.id);

// Update the local quote state to Issued since was updated in process_mining_mint_request
let mut quote: MintQuoteMiningShareResponse<Uuid> = quote.into();
quote.state = MintQuoteState::Issued;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of assuming that process_mining_mint_request updated the state to Issued we should update that function to return the state of the quote and use it here to update our quote.


self.pubsub_manager
.broadcast(NotificationPayload::MintQuoteMiningShareResponse(quote.clone()));
Expand Down Expand Up @@ -534,3 +537,60 @@ impl Mint {
})
}
}

#[cfg(test)]
mod tests {
use crate::amount::Amount;
use crate::nuts::{CurrencyUnit, MintQuoteState};
use cdk_common::nut04::MintQuoteMiningShareRequest;
use cdk_integration_tests::init_pure_tests::create_and_start_test_mint;
use bitcoin_hashes::sha256::Hash;
use cdk_common::nut00::BlindedMessage;
use std::collections::HashMap;
use anyhow::Result;

#[tokio::test]
async fn test_mint_mining_share_quote_is_issued() -> Result<()> {
let mint = create_and_start_test_mint().await?;

// Rotate keyset to make it active for CurrencyUnit::Sat
mint.rotate_keyset(CurrencyUnit::Sat, 0, 32, 0, &HashMap::new()).await?;

// Create a header hash for the mining share request
let header_hash = Hash::hash(b"test_header");

// Get active keyset ID, keyset info to get a valid public key
let active_keyset_id = mint.localstore.get_active_keyset_id(&CurrencyUnit::Sat).await?.unwrap();
let keyset_info = mint.localstore.get_keyset_info(&active_keyset_id).await?.unwrap();
let keyset = mint.generate_keyset(keyset_info);

// Get the public key for amount 512 (2^9)
let amount = Amount::from(512);
let valid_public_key = keyset.keys.get(&amount).unwrap().public_key;

let request = MintQuoteMiningShareRequest {
amount: Amount::from(512),
unit: CurrencyUnit::Sat,
header_hash,
description: None,
pubkey: None,
};

// Create a minimal blinded message with the same unit
let blinded_message = BlindedMessage {
amount: Amount::from(512),
keyset_id: active_keyset_id,
blinded_secret: valid_public_key,
witness: None,
};

// Create the quote with the blinded message
let quote = mint.create_paid_mint_mining_share_quote(request, vec![blinded_message]).await.unwrap();

// Verify quote state is Issued
assert_eq!(quote.state, MintQuoteState::Issued);

Ok(())
}
}