diff --git a/Cargo.lock b/Cargo.lock index cb991d45..1f358090 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1498,7 +1498,7 @@ dependencies = [ [[package]] name = "entities" -version = "0.1.0" +version = "0.2.0" dependencies = [ "sea-orm", "serde", diff --git a/README.md b/README.md index 9513ee5d..93c8cda0 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ This command only needs to be run during development. Production should use the When developing new database migrations, **after you migrate**, run this command to generate updated entity files. It's best to keep the migration and entity changes in the same commit. ``` -sea-orm-cli generate entity -u mysql://root:dev_web3_proxy@127.0.0.1:13306/dev_web3_proxy -o entities/src +sea-orm-cli generate entity -u mysql://root:dev_web3_proxy@127.0.0.1:13306/dev_web3_proxy -o entities/src --with-serde both ``` After running the above, you will need to manually fix some columns: `Vec` -> `sea_orm::prelude::Uuid` and `i8` -> `bool`. Related: diff --git a/entities/Cargo.toml b/entities/Cargo.toml index 1ab870cf..17ec4d19 100644 --- a/entities/Cargo.toml +++ b/entities/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "entities" -version = "0.1.0" +version = "0.2.0" edition = "2021" [lib] diff --git a/entities/src/mod.rs b/entities/src/mod.rs index 81b20ad1..4f2429b0 100644 --- a/entities/src/mod.rs +++ b/entities/src/mod.rs @@ -2,6 +2,7 @@ pub mod prelude; +pub mod revert_logs; pub mod sea_orm_active_enums; pub mod secondary_user; pub mod user; diff --git a/entities/src/prelude.rs b/entities/src/prelude.rs index c66f9b73..dfc16135 100644 --- a/entities/src/prelude.rs +++ b/entities/src/prelude.rs @@ -1,5 +1,6 @@ //! SeaORM Entity. Generated by sea-orm-codegen 0.9.1 +pub use super::revert_logs::Entity as RevertLogs; pub use super::secondary_user::Entity as SecondaryUser; pub use super::user::Entity as User; pub use super::user_keys::Entity as UserKeys; diff --git a/entities/src/revert_logs.rs b/entities/src/revert_logs.rs new file mode 100644 index 00000000..9d466590 --- /dev/null +++ b/entities/src/revert_logs.rs @@ -0,0 +1,38 @@ +//! SeaORM Entity. Generated by sea-orm-codegen 0.9.1 + +use super::sea_orm_active_enums::Method; +use sea_orm::entity::prelude::*; +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel, Serialize, Deserialize)] +#[sea_orm(table_name = "revert_logs")] +pub struct Model { + #[sea_orm(primary_key)] + pub id: u64, + pub user_key_id: u64, + pub timestamp: DateTimeUtc, + pub method: Method, + pub to: Vec, + #[sea_orm(column_type = "Text")] + pub call_data: String, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation { + #[sea_orm( + belongs_to = "super::user_keys::Entity", + from = "Column::UserKeyId", + to = "super::user_keys::Column::Id", + on_update = "NoAction", + on_delete = "NoAction" + )] + UserKeys, +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::UserKeys.def() + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/entities/src/sea_orm_active_enums.rs b/entities/src/sea_orm_active_enums.rs index 8af4137b..7726cdb3 100644 --- a/entities/src/sea_orm_active_enums.rs +++ b/entities/src/sea_orm_active_enums.rs @@ -13,3 +13,13 @@ pub enum Role { #[sea_orm(string_value = "collaborator")] Collaborator, } +#[derive(Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum, Serialize, Deserialize)] +#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "method")] +pub enum Method { + #[sea_orm(string_value = "eth_call")] + EthCall, + #[sea_orm(string_value = "eth_estimateGas")] + EthEstimateGas, + #[sea_orm(string_value = "eth_sendRawTransaction")] + EthSendRawTransaction, +} diff --git a/entities/src/secondary_user.rs b/entities/src/secondary_user.rs index abbbb0f1..88319e87 100644 --- a/entities/src/secondary_user.rs +++ b/entities/src/secondary_user.rs @@ -4,7 +4,7 @@ use super::sea_orm_active_enums::Role; use sea_orm::entity::prelude::*; use serde::{Deserialize, Serialize}; -#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)] +#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel, Serialize, Deserialize)] #[sea_orm(table_name = "secondary_user")] pub struct Model { #[sea_orm(primary_key)] diff --git a/entities/src/user_keys.rs b/entities/src/user_keys.rs index f93e98e2..19f57650 100644 --- a/entities/src/user_keys.rs +++ b/entities/src/user_keys.rs @@ -16,9 +16,15 @@ pub struct Model { pub private_txs: bool, pub active: bool, pub requests_per_minute: Option, + #[sea_orm(column_type = "Decimal(Some((5, 4)))")] + pub log_reverts: Decimal, + #[sea_orm(column_type = "Text", nullable)] pub allowed_ips: Option, + #[sea_orm(column_type = "Text", nullable)] pub allowed_origins: Option, + #[sea_orm(column_type = "Text", nullable)] pub allowed_referers: Option, + #[sea_orm(column_type = "Text", nullable)] pub allowed_user_agents: Option, } @@ -32,6 +38,8 @@ pub enum Relation { on_delete = "NoAction" )] User, + #[sea_orm(has_many = "super::revert_logs::Entity")] + RevertLogs, } impl Related for Entity { @@ -40,4 +48,10 @@ impl Related for Entity { } } +impl Related for Entity { + fn to() -> RelationDef { + Relation::RevertLogs.def() + } +} + impl ActiveModelBehavior for ActiveModel {}