Parcourir la source

feat: rename refresh to check mint quote (#1629)

tsk il y a 3 semaines
Parent
commit
c5213bfd3f

+ 7 - 4
crates/cdk-ffi/src/wallet.rs

@@ -223,14 +223,17 @@ impl Wallet {
         Ok(quote.into())
     }
 
-    /// Refresh a specific mint quote status from the mint.
+    /// Check a mint quote status from the mint.
+    ///
+    /// Calls `GET /v1/mint/quote/{method}/{quote_id}` per NUT-04.
     /// Updates local store with current state from mint.
-    /// Does NOT mint tokens - use mint() to mint a specific quote.
-    pub async fn refresh_mint_quote(
+    /// If there was a crashed mid-mint (pending saga), attempts to complete it.
+    /// Does NOT mint tokens directly - use mint() for that.
+    pub async fn check_mint_quote(
         &self,
         quote_id: String,
     ) -> Result<MintQuoteBolt11Response, FfiError> {
-        let quote = self.inner.refresh_mint_quote_status(&quote_id).await?;
+        let quote = self.inner.check_mint_quote_status(&quote_id).await?;
         Ok(quote.into())
     }
 

+ 6 - 6
crates/cdk-integration-tests/tests/bolt12.rs

@@ -354,7 +354,7 @@ async fn test_regtest_bolt12_mint_extra() -> Result<()> {
         .mint_quote(PaymentMethod::BOLT12, None, None, None)
         .await?;
 
-    let state = wallet.refresh_mint_quote_status(&mint_quote.id).await?;
+    let state = wallet.check_mint_quote_status(&mint_quote.id).await?;
 
     assert_eq!(state.amount_paid, Amount::ZERO);
     assert_eq!(state.amount_issued, Amount::ZERO);
@@ -375,7 +375,7 @@ async fn test_regtest_bolt12_mint_extra() -> Result<()> {
         .await?
         .unwrap();
 
-    let state = wallet.refresh_mint_quote_status(&mint_quote.id).await?;
+    let state = wallet.check_mint_quote_status(&mint_quote.id).await?;
 
     assert_eq!(payment, state.amount_paid);
     assert_eq!(state.amount_paid, (pay_amount_msats / 1_000).into());
@@ -487,7 +487,7 @@ async fn test_attempt_to_mint_unpaid() {
         .unwrap();
 
     let state = wallet
-        .refresh_mint_quote_status(&mint_quote.id)
+        .check_mint_quote_status(&mint_quote.id)
         .await
         .unwrap();
 
@@ -617,7 +617,7 @@ async fn test_bolt12_quote_amount_issued_tracking() -> Result<()> {
         .await?;
 
     // Verify initial state
-    let state_before = wallet.refresh_mint_quote_status(&mint_quote.id).await?;
+    let state_before = wallet.check_mint_quote_status(&mint_quote.id).await?;
     assert_eq!(state_before.amount_paid, Amount::ZERO);
     assert_eq!(state_before.amount_issued, Amount::ZERO);
 
@@ -637,7 +637,7 @@ async fn test_bolt12_quote_amount_issued_tracking() -> Result<()> {
         .expect("Should receive payment notification");
 
     // Check state after payment but before minting
-    let state_after_payment = wallet.refresh_mint_quote_status(&mint_quote.id).await?;
+    let state_after_payment = wallet.check_mint_quote_status(&mint_quote.id).await?;
     assert_eq!(
         state_after_payment.amount_paid,
         Amount::from(pay_amount_msats / 1000)
@@ -657,7 +657,7 @@ async fn test_bolt12_quote_amount_issued_tracking() -> Result<()> {
     assert_eq!(minted_amount, payment);
 
     // Check state after minting
-    let state_after_mint = wallet.refresh_mint_quote_status(&mint_quote.id).await?;
+    let state_after_mint = wallet.check_mint_quote_status(&mint_quote.id).await?;
     assert_eq!(
         state_after_mint.amount_issued, minted_amount,
         "amount_issued should be updated after minting"

+ 1 - 1
crates/cdk-integration-tests/tests/fake_wallet.rs

@@ -2255,7 +2255,7 @@ async fn test_get_unissued_mint_quotes_wallet() {
 /// 2. Quote state is updated correctly
 /// 3. The quote is stored properly in the localstore
 #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
-async fn test_refresh_mint_quote_status_updates_after_minting() {
+async fn test_check_mint_quote_status_updates_after_minting() {
     let wallet = Wallet::new(
         MINT_URL,
         CurrencyUnit::Sat,

+ 2 - 2
crates/cdk-integration-tests/tests/ffi_minting_integration.rs

@@ -107,9 +107,9 @@ async fn test_ffi_full_minting_flow() {
     );
     assert!(!quote.id.is_empty(), "Quote should have an ID");
 
-    // Refresh mint quote status
+    // Check mint quote status
     let quote_status = wallet
-        .refresh_mint_quote(quote.id.clone())
+        .check_mint_quote(quote.id.clone())
         .await
         .expect("failed to get mint status");
     assert_eq!(

+ 1 - 1
crates/cdk-integration-tests/tests/regtest.rs

@@ -507,7 +507,7 @@ async fn test_attempt_to_mint_unpaid() {
         .unwrap();
 
     let state = wallet
-        .refresh_mint_quote_status(&mint_quote.id)
+        .check_mint_quote_status(&mint_quote.id)
         .await
         .unwrap();
 

+ 6 - 6
crates/cdk-integration-tests/tests/wallet_repository.rs

@@ -125,7 +125,7 @@ async fn test_wallet_repository_mint() {
 
     // Poll for quote to be paid (like a real wallet would)
     let mut quote_status = wallet
-        .refresh_mint_quote_status(&mint_quote.id)
+        .check_mint_quote_status(&mint_quote.id)
         .await
         .unwrap();
 
@@ -141,13 +141,13 @@ async fn test_wallet_repository_mint() {
         }
         tokio::time::sleep(tokio::time::Duration::from_millis(500)).await;
         quote_status = wallet
-            .refresh_mint_quote_status(&mint_quote.id)
+            .check_mint_quote_status(&mint_quote.id)
             .await
             .unwrap();
     }
     tokio::time::sleep(tokio::time::Duration::from_millis(500)).await;
     let _ = wallet
-        .refresh_mint_quote_status(&mint_quote.id)
+        .check_mint_quote_status(&mint_quote.id)
         .await
         .unwrap();
 
@@ -614,7 +614,7 @@ async fn test_wallet_repository_check_all_mint_quotes() {
 
     // Poll for quote to be paid (like a real wallet would)
     let mut quote_status = wallet
-        .refresh_mint_quote_status(&mint_quote.id)
+        .check_mint_quote_status(&mint_quote.id)
         .await
         .unwrap();
 
@@ -630,13 +630,13 @@ async fn test_wallet_repository_check_all_mint_quotes() {
         }
         tokio::time::sleep(tokio::time::Duration::from_millis(500)).await;
         quote_status = wallet
-            .refresh_mint_quote_status(&mint_quote.id)
+            .check_mint_quote_status(&mint_quote.id)
             .await
             .unwrap();
     }
     tokio::time::sleep(tokio::time::Duration::from_millis(500)).await;
     let _ = wallet
-        .refresh_mint_quote_status(&mint_quote.id)
+        .check_mint_quote_status(&mint_quote.id)
         .await
         .unwrap();
 

+ 1 - 1
crates/cdk/README.md

@@ -86,7 +86,7 @@ async fn main() {
         println!("Pay request: {}", quote.request);
 
         loop {
-            let status = wallet.refresh_mint_quote_status(&quote.id).await.unwrap();
+            let status = wallet.check_mint_quote_status(&quote.id).await.unwrap();
 
             if status.state == MintQuoteState::Paid {
                 break;

+ 1 - 1
crates/cdk/examples/bip353.rs

@@ -77,7 +77,7 @@ async fn main() -> anyhow::Result<()> {
     let start = std::time::Instant::now();
 
     while start.elapsed() < timeout {
-        let status = wallet.refresh_mint_quote_status(&mint_quote.id).await?;
+        let status = wallet.check_mint_quote_status(&mint_quote.id).await?;
 
         if status.amount_paid >= initial_amount {
             break;

+ 12 - 6
crates/cdk/src/wallet/issue/mod.rs

@@ -232,11 +232,14 @@ impl Wallet {
         Ok(mint_quote)
     }
 
-    /// Refresh the status of a single mint quote from the mint.
+    /// Check the status of a single mint quote from the mint.
+    ///
+    /// Calls `GET /v1/mint/quote/{method}/{quote_id}` per NUT-04.
     /// Updates local store with current state from mint.
-    /// Does NOT mint tokens - use mint() to mint a specific quote.
+    /// If there was a crashed mid-mint (pending saga), attempts to complete it.
+    /// Does NOT mint tokens directly - use mint() for that.
     #[instrument(skip(self, quote_id))]
-    pub async fn refresh_mint_quote_status(&self, quote_id: &str) -> Result<MintQuote, Error> {
+    pub async fn check_mint_quote_status(&self, quote_id: &str) -> Result<MintQuote, Error> {
         let mint_quote = self
             .localstore
             .get_mint_quote(quote_id)
@@ -248,11 +251,14 @@ impl Wallet {
         Ok(mint_quote)
     }
 
-    /// Refresh all unissued mint quote states from the mint.
+    /// Check all unissued mint quote states from the mint.
+    ///
+    /// Calls `GET /v1/mint/quote/{method}/{quote_id}` per NUT-04 for each quote.
     /// Updates local store with current state from mint for each quote.
-    /// Does NOT mint tokens - use mint() or mint_unissued_quotes() for that.
+    /// If there was a crashed mid-mint (pending saga), attempts to complete it.
+    /// Does NOT mint tokens directly - use mint() or mint_unissued_quotes() for that.
     #[instrument(skip(self))]
-    pub async fn refresh_all_mint_quotes(&self) -> Result<Vec<MintQuote>, Error> {
+    pub async fn check_all_mint_quotes(&self) -> Result<Vec<MintQuote>, Error> {
         let mint_quotes = self.localstore.get_unissued_mint_quotes().await?;
         let mut updated_quotes = Vec::new();