feat: refresh keysets (#974)

* feat: refresh keysets

* feat: rename get_mint_info to fetch_mint_info
This commit is contained in:
thesimplekid
2025-08-19 19:19:08 +01:00
committed by GitHub
parent 86d51ed54d
commit 5c5075af71
15 changed files with 33 additions and 55 deletions

View File

@@ -49,7 +49,7 @@ pub async fn cat_device_login(
}; };
let mint_info = wallet let mint_info = wallet
.get_mint_info() .fetch_mint_info()
.await? .await?
.ok_or(anyhow!("Mint info not found"))?; .ok_or(anyhow!("Mint info not found"))?;

View File

@@ -51,7 +51,7 @@ pub async fn cat_login(
}; };
let mint_info = wallet let mint_info = wallet
.get_mint_info() .fetch_mint_info()
.await? .await?
.ok_or(anyhow!("Mint info not found"))?; .ok_or(anyhow!("Mint info not found"))?;

View File

@@ -47,7 +47,7 @@ pub async fn mint_blind_auth(
} }
}; };
wallet.get_mint_info().await?; wallet.fetch_mint_info().await?;
// Try to get the token from the provided argument or from the stored file // Try to get the token from the provided argument or from the stored file
let cat = match &sub_command_args.cat { let cat = match &sub_command_args.cat {
@@ -83,7 +83,7 @@ pub async fn mint_blind_auth(
println!("Attempting to refresh the access token..."); println!("Attempting to refresh the access token...");
// Get the mint info to access OIDC configuration // Get the mint info to access OIDC configuration
if let Some(mint_info) = wallet.get_mint_info().await? { if let Some(mint_info) = wallet.fetch_mint_info().await? {
match refresh_access_token(&mint_info, &token_data.refresh_token).await { match refresh_access_token(&mint_info, &token_data.refresh_token).await {
Ok((new_access_token, new_refresh_token)) => { Ok((new_access_token, new_refresh_token)) => {
println!("Successfully refreshed access token"); println!("Successfully refreshed access token");
@@ -137,7 +137,7 @@ pub async fn mint_blind_auth(
Some(amount) => amount, Some(amount) => amount,
None => { None => {
let mint_info = wallet let mint_info = wallet
.get_mint_info() .fetch_mint_info()
.await? .await?
.ok_or(anyhow!("Unknown mint info"))?; .ok_or(anyhow!("Unknown mint info"))?;
mint_info mint_info

View File

@@ -266,8 +266,6 @@ async fn test_regtest_bolt12_melt() -> Result<()> {
None, None,
)?; )?;
wallet.get_mint_info().await?;
let mint_amount = Amount::from(20_000); let mint_amount = Amount::from(20_000);
// Create a single-use BOLT12 quote // Create a single-use BOLT12 quote
@@ -323,8 +321,6 @@ async fn test_regtest_bolt12_mint_extra() -> Result<()> {
None, None,
)?; )?;
wallet.get_mint_info().await?;
// Create a single-use BOLT12 quote // Create a single-use BOLT12 quote
let mint_quote = wallet.mint_bolt12_quote(None, None).await?; let mint_quote = wallet.mint_bolt12_quote(None, None).await?;

View File

@@ -42,7 +42,7 @@ async fn test_invalid_credentials() {
.expect("Wallet"); .expect("Wallet");
let mint_info = wallet let mint_info = wallet
.get_mint_info() .fetch_mint_info()
.await .await
.expect("mint info") .expect("mint info")
.expect("could not get mint info"); .expect("could not get mint info");
@@ -278,7 +278,7 @@ async fn test_mint_blind_auth() {
.seed(Mnemonic::generate(12).unwrap().to_seed_normalized("")) .seed(Mnemonic::generate(12).unwrap().to_seed_normalized(""))
.build() .build()
.expect("Wallet"); .expect("Wallet");
let mint_info = wallet.get_mint_info().await.unwrap().unwrap(); let mint_info = wallet.fetch_mint_info().await.unwrap().unwrap();
let (access_token, _) = get_access_token(&mint_info).await; let (access_token, _) = get_access_token(&mint_info).await;
@@ -310,7 +310,7 @@ async fn test_mint_with_auth() {
.expect("Wallet"); .expect("Wallet");
let mint_info = wallet let mint_info = wallet
.get_mint_info() .fetch_mint_info()
.await .await
.expect("mint info") .expect("mint info")
.expect("could not get mint info"); .expect("could not get mint info");
@@ -355,7 +355,7 @@ async fn test_swap_with_auth() {
.seed(Mnemonic::generate(12).unwrap().to_seed_normalized("")) .seed(Mnemonic::generate(12).unwrap().to_seed_normalized(""))
.build() .build()
.expect("Wallet"); .expect("Wallet");
let mint_info = wallet.get_mint_info().await.unwrap().unwrap(); let mint_info = wallet.fetch_mint_info().await.unwrap().unwrap();
let (access_token, _) = get_access_token(&mint_info).await; let (access_token, _) = get_access_token(&mint_info).await;
wallet.set_cat(access_token).await.unwrap(); wallet.set_cat(access_token).await.unwrap();
@@ -410,7 +410,7 @@ async fn test_melt_with_auth() {
.expect("Wallet"); .expect("Wallet");
let mint_info = wallet let mint_info = wallet
.get_mint_info() .fetch_mint_info()
.await .await
.expect("Mint info not found") .expect("Mint info not found")
.expect("Mint info not found"); .expect("Mint info not found");
@@ -452,7 +452,7 @@ async fn test_mint_auth_over_max() {
let wallet = Arc::new(wallet); let wallet = Arc::new(wallet);
let mint_info = wallet let mint_info = wallet
.get_mint_info() .fetch_mint_info()
.await .await
.expect("Mint info not found") .expect("Mint info not found")
.expect("Mint info not found"); .expect("Mint info not found");
@@ -490,7 +490,7 @@ async fn test_reuse_auth_proof() {
.seed(Mnemonic::generate(12).unwrap().to_seed_normalized("")) .seed(Mnemonic::generate(12).unwrap().to_seed_normalized(""))
.build() .build()
.expect("Wallet"); .expect("Wallet");
let mint_info = wallet.get_mint_info().await.unwrap().unwrap(); let mint_info = wallet.fetch_mint_info().await.unwrap().unwrap();
let (access_token, _) = get_access_token(&mint_info).await; let (access_token, _) = get_access_token(&mint_info).await;
@@ -542,7 +542,7 @@ async fn test_melt_with_invalid_auth() {
.seed(Mnemonic::generate(12).unwrap().to_seed_normalized("")) .seed(Mnemonic::generate(12).unwrap().to_seed_normalized(""))
.build() .build()
.expect("Wallet"); .expect("Wallet");
let mint_info = wallet.get_mint_info().await.unwrap().unwrap(); let mint_info = wallet.fetch_mint_info().await.unwrap().unwrap();
let (access_token, _) = get_access_token(&mint_info).await; let (access_token, _) = get_access_token(&mint_info).await;
@@ -607,7 +607,7 @@ async fn test_refresh_access_token() {
.expect("Wallet"); .expect("Wallet");
let mint_info = wallet let mint_info = wallet
.get_mint_info() .fetch_mint_info()
.await .await
.expect("mint info") .expect("mint info")
.expect("could not get mint info"); .expect("could not get mint info");
@@ -663,7 +663,7 @@ async fn test_invalid_refresh_token() {
.expect("Wallet"); .expect("Wallet");
let mint_info = wallet let mint_info = wallet
.get_mint_info() .fetch_mint_info()
.await .await
.expect("mint info") .expect("mint info")
.expect("could not get mint info"); .expect("could not get mint info");
@@ -699,7 +699,7 @@ async fn test_auth_token_spending_order() {
.expect("Wallet"); .expect("Wallet");
let mint_info = wallet let mint_info = wallet
.get_mint_info() .fetch_mint_info()
.await .await
.expect("mint info") .expect("mint info")
.expect("could not get mint info"); .expect("could not get mint info");

View File

@@ -196,7 +196,7 @@ async fn test_mint_nut06() {
let initial_mint_url = wallet_alice.mint_url.clone(); let initial_mint_url = wallet_alice.mint_url.clone();
let mint_info_before = wallet_alice let mint_info_before = wallet_alice
.get_mint_info() .fetch_mint_info()
.await .await
.expect("Failed to get mint info") .expect("Failed to get mint info")
.unwrap(); .unwrap();

View File

@@ -37,7 +37,7 @@ async fn main() -> Result<(), Error> {
let wallet = Wallet::new(mint_url, unit, Arc::new(localstore), seed, None)?; let wallet = Wallet::new(mint_url, unit, Arc::new(localstore), seed, None)?;
let mint_info = wallet let mint_info = wallet
.get_mint_info() .fetch_mint_info()
.await .await
.expect("mint info") .expect("mint info")
.expect("could not get mint info"); .expect("could not get mint info");

View File

@@ -52,6 +52,8 @@ impl Wallet {
let mint_url = self.mint_url.clone(); let mint_url = self.mint_url.clone();
let unit = self.unit.clone(); let unit = self.unit.clone();
self.refresh_keysets().await?;
// If we have a description, we check that the mint supports it. // If we have a description, we check that the mint supports it.
if description.is_some() { if description.is_some() {
let settings = self let settings = self
@@ -194,15 +196,7 @@ impl Wallet {
amount_split_target: SplitTarget, amount_split_target: SplitTarget,
spending_conditions: Option<SpendingConditions>, spending_conditions: Option<SpendingConditions>,
) -> Result<Proofs, Error> { ) -> Result<Proofs, Error> {
// Check that mint is in store of mints self.refresh_keysets().await?;
if self
.localstore
.get_mint(self.mint_url.clone())
.await?
.is_none()
{
self.get_mint_info().await?;
}
let quote_info = self let quote_info = self
.localstore .localstore

View File

@@ -29,6 +29,8 @@ impl Wallet {
let mint_url = self.mint_url.clone(); let mint_url = self.mint_url.clone();
let unit = &self.unit; let unit = &self.unit;
self.refresh_keysets().await?;
// If we have a description, we check that the mint supports it. // If we have a description, we check that the mint supports it.
if description.is_some() { if description.is_some() {
let mint_method_settings = self let mint_method_settings = self
@@ -83,15 +85,7 @@ impl Wallet {
amount_split_target: SplitTarget, amount_split_target: SplitTarget,
spending_conditions: Option<SpendingConditions>, spending_conditions: Option<SpendingConditions>,
) -> Result<Proofs, Error> { ) -> Result<Proofs, Error> {
// Check that mint is in store of mints self.refresh_keysets().await?;
if self
.localstore
.get_mint(self.mint_url.clone())
.await?
.is_none()
{
self.get_mint_info().await?;
}
let quote_info = self.localstore.get_mint_quote(quote_id).await?; let quote_info = self.localstore.get_mint_quote(quote_id).await?;

View File

@@ -82,7 +82,7 @@ impl Wallet {
#[instrument(skip(self))] #[instrument(skip(self))]
pub async fn refresh_keysets(&self) -> Result<KeySetInfos, Error> { pub async fn refresh_keysets(&self) -> Result<KeySetInfos, Error> {
tracing::debug!("Refreshing keysets and ensuring we have keys"); tracing::debug!("Refreshing keysets and ensuring we have keys");
let _ = self.get_mint_info().await?; let _ = self.fetch_mint_info().await?;
// Fetch all current keysets from mint // Fetch all current keysets from mint
let keysets_response = self.client.get_mint_keysets().await?; let keysets_response = self.client.get_mint_keysets().await?;

View File

@@ -48,6 +48,8 @@ impl Wallet {
request: String, request: String,
options: Option<MeltOptions>, options: Option<MeltOptions>,
) -> Result<MeltQuote, Error> { ) -> Result<MeltQuote, Error> {
self.refresh_keysets().await?;
let invoice = Bolt11Invoice::from_str(&request)?; let invoice = Bolt11Invoice::from_str(&request)?;
let quote_request = MeltQuoteBolt11Request { let quote_request = MeltQuoteBolt11Request {

View File

@@ -249,7 +249,7 @@ impl Wallet {
/// Query mint for current mint information /// Query mint for current mint information
#[instrument(skip(self))] #[instrument(skip(self))]
pub async fn get_mint_info(&self) -> Result<Option<MintInfo>, Error> { pub async fn fetch_mint_info(&self) -> Result<Option<MintInfo>, Error> {
match self.client.get_mint_info().await { match self.client.get_mint_info().await {
Ok(mint_info) => { Ok(mint_info) => {
// If mint provides time make sure it is accurate // If mint provides time make sure it is accurate
@@ -382,7 +382,7 @@ impl Wallet {
.await? .await?
.is_none() .is_none()
{ {
self.get_mint_info().await?; self.fetch_mint_info().await?;
} }
let keysets = self.load_mint_keysets().await?; let keysets = self.load_mint_keysets().await?;

View File

@@ -78,7 +78,7 @@ impl MultiMintWallet {
target_proof_count, target_proof_count,
)?; )?;
wallet.get_mint_info().await?; wallet.fetch_mint_info().await?;
self.add_wallet(wallet.clone()).await; self.add_wallet(wallet.clone()).await;

View File

@@ -27,18 +27,8 @@ impl Wallet {
memo: Option<String>, memo: Option<String>,
) -> Result<Amount, Error> { ) -> Result<Amount, Error> {
let mint_url = &self.mint_url; let mint_url = &self.mint_url;
// Add mint if it does not exist in the store
if self
.localstore
.get_mint(self.mint_url.clone())
.await?
.is_none()
{
tracing::debug!("Mint not in localstore fetching info for: {mint_url}");
self.get_mint_info().await?;
}
let _ = self.fetch_active_keyset().await?; self.refresh_keysets().await?;
let active_keyset_id = self.fetch_active_keyset().await?.id; let active_keyset_id = self.fetch_active_keyset().await?.id;

View File

@@ -21,6 +21,8 @@ impl Wallet {
spending_conditions: Option<SpendingConditions>, spending_conditions: Option<SpendingConditions>,
include_fees: bool, include_fees: bool,
) -> Result<Option<Proofs>, Error> { ) -> Result<Option<Proofs>, Error> {
self.refresh_keysets().await?;
tracing::info!("Swapping"); tracing::info!("Swapping");
let mint_url = &self.mint_url; let mint_url = &self.mint_url;
let unit = &self.unit; let unit = &self.unit;