query for wallet token

This commit is contained in:
Brandon Thomas committed 2025-09-12 01:00:04 -04:00
1 parent 497dbd9b4f
commit 70bed32f51
8 files changed
+97 -3

No files matched your search

@@ -35,3 +35,4 @@ pub mod voice_clone_requests;
pub mod voice_conversion;
pub mod voice_designer;
pub mod w2l;
pub mod wallets;
@@ -0,0 +1,67 @@
use sqlx;
use sqlx::pool::PoolConnection;
use sqlx::MySql;
use tokens::tokens::users::UserToken;
use tokens::tokens::wallets::WalletToken;
pub async fn find_wallet_token_for_owner_user_using_connection(
user_token: &UserToken,
connection: &mut PoolConnection<MySql>,
) -> anyhow::Result<Option<WalletToken>> {
// TODO(bt,2025-08-07): DO NOT COPY THIS. For some reason the query macro can't
// decide which impl to use to deserialize typed tokens.
let result = sqlx::query_as!(
RecordRaw,
r#"
SELECT
token as `token: tokens::tokens::wallets::WalletToken`
FROM wallets
WHERE owner_user_token = ?
LIMIT 1
"#,
user_token.as_str()
)
.fetch_optional(&mut **connection)
.await;
match result {
Ok(Some(record)) => Ok(Some(record.token)),
Ok(None) => Ok(None),
Err(e) => Err(anyhow::anyhow!("Database query error: {}", e)),
}
}
pub async fn find_wallet_token_for_owner_user_using_transaction(
user_token: &UserToken,
transaction: &mut sqlx::Transaction<'_, MySql>,
) -> anyhow::Result<Option<WalletToken>> {
// TODO(bt,2025-08-07): DO NOT COPY THIS. For some reason the query macro can't
// decide which impl to use to deserialize typed tokens.
let result = sqlx::query_as!(
RecordRaw,
r#"
SELECT
token as `token: tokens::tokens::wallets::WalletToken`
FROM wallets
WHERE owner_user_token = ?
LIMIT 1
"#,
user_token.as_str()
)
.fetch_optional(&mut **transaction)
.await;
match result {
Ok(Some(record)) => Ok(Some(record.token)),
Ok(None) => Ok(None),
Err(e) => Err(anyhow::anyhow!("Database query error: {}", e)),
}
}
#[derive(sqlx::FromRow)]
struct RecordRaw {
token: WalletToken,
}
@@ -0,0 +1,4 @@
pub (crate) async fn select_wallet_for_update(wallet_token: &str) -> anyhow::Result<()> {
Ok(())
}
@@ -0,0 +1,2 @@
pub (crate) mod internal_select_wallet_balance_for_update;
pub mod find_wallet_token_for_owner_user;
@@ -45,6 +45,7 @@ pub(crate) enum TokenPrefix {
UserSession,
VoiceConversionModel,
VoiceConversionResult,
Wallet,
ZsVoice,
ZsVoiceDataset,
ZsVoiceDatasetSample,
@@ -124,6 +125,7 @@ impl PrefixGenerator for TokenPrefix {
Self::UserSession => "session_",
Self::VoiceConversionModel => "vcm_",
Self::VoiceConversionResult => "vcr_",
Self::Wallet => "wallet_",
Self::ZsVoice => "zsv_",
Self::ZsVoiceDataset => "zsd_",
Self::ZsVoiceDatasetSample => "zss_",
@@ -38,6 +38,7 @@ pub mod w2l_inference_jobs;
pub mod w2l_results;
pub mod w2l_template_upload_jobs;
pub mod w2l_templates;
pub mod wallets;
pub mod zs_voice_dataset_samples;
pub mod zs_voice_datasets;
pub mod zs_voices;
@@ -0,0 +1,17 @@
use std::fmt::Debug;
use serde::Deserialize;
use serde::Serialize;
use utoipa::ToSchema;
use crate::prefixes::TokenPrefix;
/// The primary key for Media Files
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Serialize, Deserialize, ToSchema)]
#[cfg_attr(feature = "database", derive(sqlx::Type))]
#[cfg_attr(feature = "database", sqlx(transparent))]
pub struct WalletToken(pub String);
impl_string_token!(WalletToken);
impl_mysql_token_from_row!(WalletToken);
impl_crockford_generator!(WalletToken, 32usize, TokenPrefix::Wallet, CrockfordLower);
@@ -72,11 +72,11 @@ pub async fn payment_intent_succeeded_handler(
info!("Fulfilling one-time payment...");
complete_credits_pack_purchase(credits_pack, purchase.quantity)
.await?;
should_ignore_retry = true;
action_was_taken = true;
}
}
should_ignore_retry = true;
action_was_taken = true;
}
}