regenerate entities
This commit is contained in:
parent
63ae98e9a4
commit
dede79fde1
3
Cargo.lock
generated
3
Cargo.lock
generated
@ -1386,6 +1386,9 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "entities"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"sea-orm",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "eth-keystore"
|
||||
|
@ -59,6 +59,14 @@ $ websocat ws://127.0.0.1:8544
|
||||
|
||||
You can copy `config/example.toml` to `config/production-$CHAINNAME.toml` and then run `docker-compose up --build -d` start proxies for many chains.
|
||||
|
||||
## Database entities
|
||||
|
||||
Types for database entities are generated from a development database.
|
||||
|
||||
```
|
||||
sea-orm-cli generate entity -u mysql://root:dev_web3_proxy@127.0.0.1:3306/dev_web3_proxy -o entities/src
|
||||
```
|
||||
|
||||
## Flame Graphs
|
||||
|
||||
Flame graphs make finding slow code painless:
|
||||
|
@ -3,6 +3,11 @@ name = "entities"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[lib]
|
||||
name = "entities"
|
||||
path = "src/mod.rs"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
sea-orm = { version = "0.9.1" }
|
||||
|
@ -7,8 +7,8 @@ use sea_orm::entity::prelude::*;
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key)]
|
||||
pub id: i64,
|
||||
#[sea_orm(unique)]
|
||||
pub address: String,
|
||||
pub chain: i32,
|
||||
pub description: String,
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ pub struct Model {
|
||||
#[sea_orm(unique)]
|
||||
pub address: String,
|
||||
pub description: String,
|
||||
pub email: String,
|
||||
pub email: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
|
@ -8,6 +8,7 @@ pub struct Model {
|
||||
#[sea_orm(primary_key)]
|
||||
pub id: i64,
|
||||
pub user_id: i64,
|
||||
#[sea_orm(unique)]
|
||||
pub api_key: String,
|
||||
pub description: String,
|
||||
pub private_txs: i8,
|
||||
|
@ -25,7 +25,7 @@ impl MigrationTrait for Migration {
|
||||
.unique_key(),
|
||||
)
|
||||
.col(ColumnDef::new(User::Description).string().not_null())
|
||||
.col(ColumnDef::new(User::Email).string().not_null())
|
||||
.col(ColumnDef::new(User::Email).string())
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
@ -465,7 +465,7 @@ impl Web3ProxyApp {
|
||||
|
||||
// TODO: this only needs to be unique per connection. we don't need it globably unique
|
||||
let subscription_id = subscription_count.fetch_add(1, atomic::Ordering::SeqCst);
|
||||
let subscription_id = format!("{:#x}", subscription_id);
|
||||
let subscription_id = U64::from(subscription_id);
|
||||
|
||||
// save the id so we can use it in the response
|
||||
let id = payload.id.clone();
|
||||
@ -476,8 +476,6 @@ impl Web3ProxyApp {
|
||||
Some(x) if x == json!(["newHeads"]) => {
|
||||
let head_block_receiver = self.head_block_receiver.clone();
|
||||
|
||||
let subscription_id = subscription_id.clone();
|
||||
|
||||
trace!(?subscription_id, "new heads subscription");
|
||||
tokio::spawn(async move {
|
||||
let mut head_block_receiver = Abortable::new(
|
||||
@ -510,8 +508,6 @@ impl Web3ProxyApp {
|
||||
Some(x) if x == json!(["newPendingTransactions"]) => {
|
||||
let pending_tx_receiver = self.pending_tx_sender.subscribe();
|
||||
|
||||
let subscription_id = subscription_id.clone();
|
||||
|
||||
let mut pending_tx_receiver = Abortable::new(
|
||||
BroadcastStream::new(pending_tx_receiver),
|
||||
subscription_registration,
|
||||
@ -551,8 +547,6 @@ impl Web3ProxyApp {
|
||||
// TODO: too much copy/pasta with newPendingTransactions
|
||||
let pending_tx_receiver = self.pending_tx_sender.subscribe();
|
||||
|
||||
let subscription_id = subscription_id.clone();
|
||||
|
||||
let mut pending_tx_receiver = Abortable::new(
|
||||
BroadcastStream::new(pending_tx_receiver),
|
||||
subscription_registration,
|
||||
@ -600,8 +594,6 @@ impl Web3ProxyApp {
|
||||
subscription_registration,
|
||||
);
|
||||
|
||||
let subscription_id = subscription_id.clone();
|
||||
|
||||
trace!(?subscription_id, "pending transactions subscription");
|
||||
|
||||
// TODO: do something with this handle?
|
||||
|
@ -11,6 +11,10 @@ use axum::{http::StatusCode, response::IntoResponse, Json};
|
||||
use ethers::prelude::{Address, Bytes};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use entities::user;
|
||||
|
||||
// use entities::user::User;
|
||||
|
||||
pub async fn create_user(
|
||||
// this argument tells axum to parse the request body
|
||||
// as JSON into a `CreateUser` type
|
||||
@ -18,28 +22,26 @@ pub async fn create_user(
|
||||
) -> impl IntoResponse {
|
||||
// TODO: rate limit by ip
|
||||
// TODO: insert your application logic here
|
||||
let user = User {
|
||||
id: 1337,
|
||||
eth_address: payload.eth_address,
|
||||
let user = user::ActiveModel {
|
||||
address: sea_orm::Set(payload.address.to_string()),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
// TODO: optional email
|
||||
|
||||
todo!();
|
||||
|
||||
// this will be converted into a JSON response
|
||||
// with a status code of `201 Created`
|
||||
(StatusCode::CREATED, Json(user))
|
||||
// (StatusCode::CREATED, Json(user))
|
||||
}
|
||||
|
||||
// the input to our `create_user` handler
|
||||
#[derive(Deserialize)]
|
||||
pub struct CreateUser {
|
||||
eth_address: Address,
|
||||
// TODO: validation
|
||||
address: Address,
|
||||
// TODO: make sure the email address is valid
|
||||
email: Option<String>,
|
||||
signature: Bytes,
|
||||
}
|
||||
|
||||
// the output to our `create_user` handler
|
||||
#[derive(Serialize)]
|
||||
struct User {
|
||||
id: u64,
|
||||
eth_address: Address,
|
||||
invite_code: String,
|
||||
}
|
||||
|
@ -168,7 +168,6 @@ impl JsonRpcForwardedResponse {
|
||||
|
||||
JsonRpcForwardedResponse {
|
||||
jsonrpc: "2.0".to_string(),
|
||||
// TODO: what id can we use? how do we make sure the incoming id gets attached to this?
|
||||
id,
|
||||
result: None,
|
||||
error: Some(JsonRpcErrorData {
|
||||
|
Loading…
Reference in New Issue
Block a user