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