diff --git a/Cargo.lock b/Cargo.lock index 51435518..be56b64c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1678,7 +1678,7 @@ dependencies = [ [[package]] name = "entities" -version = "0.35.0" +version = "0.36.0" dependencies = [ "ethers", "sea-orm", @@ -3329,7 +3329,7 @@ dependencies = [ [[package]] name = "migration" -version = "0.35.0" +version = "0.36.0" dependencies = [ "chrono", "sea-orm-migration", @@ -7033,7 +7033,7 @@ dependencies = [ [[package]] name = "web3_proxy" -version = "0.35.0" +version = "0.36.0" dependencies = [ "anyhow", "arc-swap", diff --git a/entities/Cargo.toml b/entities/Cargo.toml index e7ed35c3..966baa23 100644 --- a/entities/Cargo.toml +++ b/entities/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "entities" -version = "0.35.0" +version = "0.36.0" edition = "2021" [lib] diff --git a/entities/src/admin_increase_balance_receipt.rs b/entities/src/admin_increase_balance_receipt.rs index 999c9076..1723c52b 100644 --- a/entities/src/admin_increase_balance_receipt.rs +++ b/entities/src/admin_increase_balance_receipt.rs @@ -13,6 +13,7 @@ pub struct Model { pub admin_id: u64, pub deposit_to_user_id: u64, pub note: String, + pub date_created: DateTimeUtc, } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] diff --git a/entities/src/increase_on_chain_balance_receipt.rs b/entities/src/increase_on_chain_balance_receipt.rs index 29e76d05..31633cac 100644 --- a/entities/src/increase_on_chain_balance_receipt.rs +++ b/entities/src/increase_on_chain_balance_receipt.rs @@ -16,6 +16,7 @@ pub struct Model { pub block_hash: String, pub log_index: u64, pub token_address: String, + pub date_created: DateTimeUtc, } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] diff --git a/migration/Cargo.toml b/migration/Cargo.toml index 583aff39..00f780a8 100644 --- a/migration/Cargo.toml +++ b/migration/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "migration" -version = "0.35.0" +version = "0.36.0" edition = "2021" publish = false diff --git a/migration/src/lib.rs b/migration/src/lib.rs index 28b5de40..80c4fdff 100644 --- a/migration/src/lib.rs +++ b/migration/src/lib.rs @@ -38,6 +38,7 @@ mod m20230707_211936_premium_tier_changes; mod m20230708_151756_rpc_accounting_free_usage_credits; mod m20230708_152131_referral_track_one_time_bonus_bonus; mod m20230713_144446_stripe_default_date_created; +mod m20230713_210511_deposit_add_date_created; pub struct Migrator; @@ -83,6 +84,7 @@ impl MigratorTrait for Migrator { Box::new(m20230708_151756_rpc_accounting_free_usage_credits::Migration), Box::new(m20230708_152131_referral_track_one_time_bonus_bonus::Migration), Box::new(m20230713_144446_stripe_default_date_created::Migration), + Box::new(m20230713_210511_deposit_add_date_created::Migration), ] } } diff --git a/migration/src/m20230713_210511_deposit_add_date_created.rs b/migration/src/m20230713_210511_deposit_add_date_created.rs new file mode 100644 index 00000000..9ed7deeb --- /dev/null +++ b/migration/src/m20230713_210511_deposit_add_date_created.rs @@ -0,0 +1,96 @@ +use sea_orm_migration::prelude::*; + +#[derive(DeriveMigrationName)] +pub struct Migration; + +#[async_trait::async_trait] +impl MigrationTrait for Migration { + async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { + // Add column to both tables + manager + .alter_table( + Table::alter() + .table(AdminIncreaseBalanceReceipt::Table) + .add_column( + ColumnDef::new(AdminIncreaseBalanceReceipt::DateCreated) + .timestamp() + .extra("DEFAULT CURRENT_TIMESTAMP".to_string()) + .not_null(), + ) + .to_owned(), + ) + .await?; + // Add column to both tables + manager + .alter_table( + Table::alter() + .table(IncreaseOnChainBalanceReceipt::Table) + .add_column( + ColumnDef::new(IncreaseOnChainBalanceReceipt::DateCreated) + .timestamp() + .extra("DEFAULT CURRENT_TIMESTAMP".to_string()) + .not_null(), + ) + .to_owned(), + ) + .await?; + + let now = chrono::offset::Utc::now(); + // Then change all columns to "now" + let update_to_current_timestamp = Query::update() + .table(AdminIncreaseBalanceReceipt::Table) + .values([(AdminIncreaseBalanceReceipt::DateCreated, Some(now).into())]) + .to_owned(); + manager.exec_stmt(update_to_current_timestamp).await?; + // Then change all columns to "now" + let update_to_current_timestamp = Query::update() + .table(IncreaseOnChainBalanceReceipt::Table) + .values([(IncreaseOnChainBalanceReceipt::DateCreated, Some(now).into())]) + .to_owned(); + manager.exec_stmt(update_to_current_timestamp).await + } + + async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { + // Replace the sample below with your own migration scripts + manager + .alter_table( + Table::alter() + .table(AdminIncreaseBalanceReceipt::Table) + .drop_column(AdminIncreaseBalanceReceipt::DateCreated) + .to_owned(), + ) + .await?; + // Add column to both tables + manager + .alter_table( + Table::alter() + .table(IncreaseOnChainBalanceReceipt::Table) + .drop_column(IncreaseOnChainBalanceReceipt::DateCreated) + .to_owned(), + ) + .await + } +} + +/// Learn more at https://docs.rs/sea-query#iden +#[derive(Iden)] +enum AdminIncreaseBalanceReceipt { + Table, + Id, + Amount, + AdminId, + DepositToUserId, + Note, + DateCreated, +} + +#[derive(Iden)] +enum IncreaseOnChainBalanceReceipt { + Table, + Id, + TxHash, + ChainId, + Amount, + DepositToUserId, + DateCreated, +} diff --git a/web3_proxy/Cargo.toml b/web3_proxy/Cargo.toml index 950326fa..345224b8 100644 --- a/web3_proxy/Cargo.toml +++ b/web3_proxy/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "web3_proxy" -version = "0.35.0" +version = "0.36.0" edition = "2021" default-run = "web3_proxy_cli" diff --git a/web3_proxy/src/frontend/users/payment.rs b/web3_proxy/src/frontend/users/payment.rs index 8303d61c..2a2f7e1b 100644 --- a/web3_proxy/src/frontend/users/payment.rs +++ b/web3_proxy/src/frontend/users/payment.rs @@ -81,6 +81,7 @@ pub async fn user_chain_deposits_get( "amount": x.amount, "chain_id": x.chain_id, "tx_hash": x.tx_hash, + "date_created": x.date_created }) }) .collect::>(); @@ -163,6 +164,7 @@ pub async fn user_admin_deposits_get( "amount": x.amount, "deposit_to_user_id": x.deposit_to_user_id, "note": x.note, + "date_created": x.date_created }) }) .collect::>(); @@ -383,6 +385,7 @@ pub async fn user_balance_post( log_index: sea_orm::ActiveValue::Set(log_index), token_address: sea_orm::ActiveValue::Set(payment_token_address.encode_hex()), tx_hash: sea_orm::ActiveValue::Set(tx_hash.encode_hex()), + date_created: sea_orm::ActiveValue::NotSet, }; trace!("Trying to insert receipt {:?}", receipt);