add check_balance command

This commit is contained in:
Bryan Stitt 2023-08-08 16:18:07 -07:00
parent 3f932b9d57
commit cee4603b55
6 changed files with 54 additions and 4 deletions

4
Cargo.lock generated

@ -7243,7 +7243,7 @@ dependencies = [
[[package]]
name = "web3_proxy"
version = "1.42.4"
version = "1.42.5"
dependencies = [
"anyhow",
"arc-swap",
@ -7324,7 +7324,7 @@ dependencies = [
[[package]]
name = "web3_proxy_cli"
version = "1.42.4"
version = "1.42.5"
dependencies = [
"env_logger",
"parking_lot",

@ -1,6 +1,6 @@
[package]
name = "web3_proxy"
version = "1.42.4"
version = "1.42.5"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

@ -1,6 +1,6 @@
[package]
name = "web3_proxy_cli"
version = "1.42.4"
version = "1.42.5"
edition = "2021"
default-run = "web3_proxy_cli"

@ -65,6 +65,7 @@ enum SubCommand {
ChangeUserTier(sub_commands::ChangeUserTierSubCommand),
ChangeUserTierByAddress(sub_commands::ChangeUserTierByAddressSubCommand),
ChangeUserTierByKey(sub_commands::ChangeUserTierByKeySubCommand),
CheckBalance(sub_commands::CheckBalanceSubCommand),
CheckConfig(sub_commands::CheckConfigSubCommand),
CountUsers(sub_commands::CountUsersSubCommand),
CreateKey(sub_commands::CreateKeySubCommand),
@ -349,6 +350,15 @@ fn main() -> anyhow::Result<()> {
x.main(&db_conn).await
}
SubCommand::CheckBalance(x) => {
let db_url = cli_config
.db_url
.expect("'--config' (with a db) or '--db-url' is required to run change_user_addres");
let db_conn = connect_db(db_url, 1, 1).await?;
x.main(&db_conn).await
}
SubCommand::CheckConfig(x) => x.main().await,
SubCommand::CreateKey(x) => {
let db_url = cli_config

@ -0,0 +1,38 @@
use web3_proxy::balance::Balance;
use web3_proxy::prelude::anyhow::{self, Context};
use web3_proxy::prelude::argh::{self, FromArgs};
use web3_proxy::prelude::entities::user;
use web3_proxy::prelude::ethers::types::Address;
use web3_proxy::prelude::migration::sea_orm::{
ColumnTrait, DatabaseConnection, EntityTrait, QueryFilter,
};
use web3_proxy::prelude::serde_json::json;
use web3_proxy::prelude::tracing::debug;
/// change a user's tier.
#[derive(FromArgs, PartialEq, Eq, Debug)]
#[argh(subcommand, name = "check_balance")]
pub struct CheckBalanceSubCommand {
#[argh(positional)]
/// the address of the user you want to check.
user_address: Address,
}
impl CheckBalanceSubCommand {
pub async fn main(self, db_conn: &DatabaseConnection) -> anyhow::Result<()> {
// use the address to get the user
let user = user::Entity::find()
.filter(user::Column::Address.eq(self.user_address.as_bytes()))
.one(db_conn)
.await?
.context("No user found with that key")?;
// TODO: don't serialize the rpc key
debug!("user: {:#}", json!(&user));
let balance = Balance::try_from_db(db_conn, user.id).await?;
debug!("balance: {:#}", json!(&balance));
Ok(())
}
}

@ -3,6 +3,7 @@ mod change_user_address;
mod change_user_tier;
mod change_user_tier_by_address;
mod change_user_tier_by_key;
mod check_balance;
mod check_config;
mod count_users;
mod create_key;
@ -26,6 +27,7 @@ pub use self::change_user_address::ChangeUserAddressSubCommand;
pub use self::change_user_tier::ChangeUserTierSubCommand;
pub use self::change_user_tier_by_address::ChangeUserTierByAddressSubCommand;
pub use self::change_user_tier_by_key::ChangeUserTierByKeySubCommand;
pub use self::check_balance::CheckBalanceSubCommand;
pub use self::check_config::CheckConfigSubCommand;
pub use self::count_users::CountUsersSubCommand;
pub use self::create_key::CreateKeySubCommand;