web3-proxy/migration/src/m20230214_134254_increase_balance_transactions.rs
David 3f76b08364
Test balance and referral accounting (#111)
* removed bloom filter temporarily, added some fixes with decimals in payment.rs

* balance accounting for a single user (paid and free tier) seems to be ok

* fixed some balance accounting

* compute_cost reduced back to 0
2023-06-08 10:08:29 -07:00

96 lines
3.1 KiB
Rust

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> {
// Adds a table which keeps track of which transactions were already added (basically to prevent double spending)
manager
.create_table(
Table::create()
.table(IncreaseOnChainBalanceReceipt::Table)
.if_not_exists()
.col(
ColumnDef::new(IncreaseOnChainBalanceReceipt::Id)
.integer()
.not_null()
.auto_increment()
.primary_key(),
)
.col(
ColumnDef::new(IncreaseOnChainBalanceReceipt::TxHash)
.string()
.not_null(),
)
.col(
ColumnDef::new(IncreaseOnChainBalanceReceipt::ChainId)
.big_unsigned()
.not_null(),
)
.col(
ColumnDef::new(IncreaseOnChainBalanceReceipt::Amount)
.decimal_len(20, 10)
.not_null(),
)
.col(
ColumnDef::new(IncreaseOnChainBalanceReceipt::DepositToUserId)
.big_unsigned()
.not_null(),
)
.foreign_key(
ForeignKey::create()
.name("fk-deposit_to_user_id")
.from(
IncreaseOnChainBalanceReceipt::Table,
IncreaseOnChainBalanceReceipt::DepositToUserId,
)
.to(User::Table, User::Id),
)
.to_owned(),
)
.await?;
// Add a unique-constraint on chain-id and tx-hash
manager
.create_index(
Index::create()
.name("idx-increase_on_chain_balance_receipt-unique-chain_id-tx_hash")
.table(IncreaseOnChainBalanceReceipt::Table)
.col(IncreaseOnChainBalanceReceipt::ChainId)
.col(IncreaseOnChainBalanceReceipt::TxHash)
.unique()
.to_owned(),
)
.await
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_table(
Table::drop()
.table(IncreaseOnChainBalanceReceipt::Table)
.to_owned(),
)
.await
}
}
/// Learn more at https://docs.rs/sea-query#iden
#[derive(Iden)]
enum IncreaseOnChainBalanceReceipt {
Table,
Id,
TxHash,
ChainId,
Amount,
DepositToUserId,
}
#[derive(Iden)]
enum User {
Table,
Id,
}