|
|
@@ -129,6 +129,18 @@ impl Wallet {
|
|
|
/// Melt specific proofs
|
|
|
#[instrument(skip(self, proofs))]
|
|
|
pub async fn melt_proofs(&self, quote_id: &str, proofs: Proofs) -> Result<Melted, Error> {
|
|
|
+ self.melt_proofs_with_metadata(quote_id, proofs, HashMap::new())
|
|
|
+ .await
|
|
|
+ }
|
|
|
+
|
|
|
+ /// Melt specific proofs
|
|
|
+ #[instrument(skip(self, proofs))]
|
|
|
+ pub async fn melt_proofs_with_metadata(
|
|
|
+ &self,
|
|
|
+ quote_id: &str,
|
|
|
+ proofs: Proofs,
|
|
|
+ metadata: HashMap<String, String>,
|
|
|
+ ) -> Result<Melted, Error> {
|
|
|
let quote_info = self
|
|
|
.localstore
|
|
|
.get_melt_quote(quote_id)
|
|
|
@@ -284,7 +296,7 @@ impl Wallet {
|
|
|
ys: proofs.ys()?,
|
|
|
timestamp: unix_time(),
|
|
|
memo: None,
|
|
|
- metadata: HashMap::new(),
|
|
|
+ metadata,
|
|
|
quote_id: Some(quote_id.to_string()),
|
|
|
})
|
|
|
.await?;
|
|
|
@@ -320,6 +332,44 @@ impl Wallet {
|
|
|
/// }
|
|
|
#[instrument(skip(self))]
|
|
|
pub async fn melt(&self, quote_id: &str) -> Result<Melted, Error> {
|
|
|
+ self.melt_with_metadata(quote_id, HashMap::new()).await
|
|
|
+ }
|
|
|
+
|
|
|
+ /// Melt with additional metadata to be saved locally with the transaction
|
|
|
+ /// # Synopsis
|
|
|
+ /// ```rust, no_run
|
|
|
+ /// use std::sync::Arc;
|
|
|
+ ///
|
|
|
+ /// use cdk_sqlite::wallet::memory;
|
|
|
+ /// use cdk::nuts::CurrencyUnit;
|
|
|
+ /// use cdk::wallet::Wallet;
|
|
|
+ /// use rand::random;
|
|
|
+ ///
|
|
|
+ /// #[tokio::main]
|
|
|
+ /// async fn main() -> anyhow::Result<()> {
|
|
|
+ /// let seed = random::<[u8; 64]>();
|
|
|
+ /// let mint_url = "https://fake.thesimplekid.dev";
|
|
|
+ /// let unit = CurrencyUnit::Sat;
|
|
|
+ ///
|
|
|
+ /// let localstore = memory::empty().await?;
|
|
|
+ /// let wallet = Wallet::new(mint_url, unit, Arc::new(localstore), seed, None).unwrap();
|
|
|
+ /// let bolt11 = "lnbc100n1pnvpufspp5djn8hrq49r8cghwye9kqw752qjncwyfnrprhprpqk43mwcy4yfsqdq5g9kxy7fqd9h8vmmfvdjscqzzsxqyz5vqsp5uhpjt36rj75pl7jq2sshaukzfkt7uulj456s4mh7uy7l6vx7lvxs9qxpqysgqedwz08acmqwtk8g4vkwm2w78suwt2qyzz6jkkwcgrjm3r3hs6fskyhvud4fan3keru7emjm8ygqpcrwtlmhfjfmer3afs5hhwamgr4cqtactdq".to_string();
|
|
|
+ /// let quote = wallet.melt_quote(bolt11, None).await?;
|
|
|
+ /// let quote_id = quote.id;
|
|
|
+ ///
|
|
|
+ /// let mut metadata = std::collections::HashMap::new();
|
|
|
+ /// metadata.insert("my key".to_string(), "my value".to_string());
|
|
|
+ ///
|
|
|
+ /// let _ = wallet.melt_with_metadata("e_id, metadata).await?;
|
|
|
+ ///
|
|
|
+ /// Ok(())
|
|
|
+ /// }
|
|
|
+ #[instrument(skip(self))]
|
|
|
+ pub async fn melt_with_metadata(
|
|
|
+ &self,
|
|
|
+ quote_id: &str,
|
|
|
+ metadata: HashMap<String, String>,
|
|
|
+ ) -> Result<Melted, Error> {
|
|
|
let quote_info = self
|
|
|
.localstore
|
|
|
.get_melt_quote(quote_id)
|
|
|
@@ -368,6 +418,7 @@ impl Wallet {
|
|
|
input_proofs.extend_from_slice(&new_proofs);
|
|
|
}
|
|
|
|
|
|
- self.melt_proofs(quote_id, input_proofs).await
|
|
|
+ self.melt_proofs_with_metadata(quote_id, input_proofs, metadata)
|
|
|
+ .await
|
|
|
}
|
|
|
}
|