credits helpers

This commit is contained in:
Bryan Stitt 2023-08-07 15:25:10 -07:00
parent 4601852c0c
commit 7454c1a256
2 changed files with 15 additions and 1 deletions

@ -0,0 +1,7 @@
SELECT SUM(`sum_credits_used`) as sum, rpc_accounting_v2.rpc_key_id, rpc_key.user_id, user.email
FROM `rpc_accounting_v2`
JOIN rpc_key ON rpc_accounting_v2.rpc_key_id=rpc_key.id
JOIN user on rpc_key.user_id=user.id
GROUP BY `rpc_key_id`
ORDER BY sum DESC
LIMIT 100

@ -26,6 +26,10 @@ pub struct GrantCreditsToAddress {
#[argh(positional)]
/// how many credits to give. "0" to just see their balance
credits: Decimal,
#[argh(option)]
/// description of the transaction.
note: Option<String>,
}
impl GrantCreditsToAddress {
@ -52,7 +56,10 @@ impl GrantCreditsToAddress {
// TODO: allow customizing the admin id
admin_id: sea_orm::Set(1),
deposit_to_user_id: sea_orm::Set(user_id),
note: sea_orm::Set("grant credits to address".into()),
note: sea_orm::Set(
self.note
.unwrap_or_else(|| "grant credits to address".to_string()),
),
..Default::default()
};
increase_balance_receipt.save(&txn).await?;