2023-01-26 08:24:09 +03:00
|
|
|
//! `frontend` contains HTTP and websocket endpoints for use by a website or web3 wallet.
|
2023-02-06 20:55:27 +03:00
|
|
|
//!
|
2023-04-11 01:06:40 +03:00
|
|
|
//! Important reading about axum extractors: <https://docs.rs/axum/latest/axum/extract/index.html#the-order-of-extractors>
|
2022-10-18 00:47:58 +03:00
|
|
|
|
2023-01-17 22:12:40 +03:00
|
|
|
pub mod admin;
|
2022-09-22 23:27:14 +03:00
|
|
|
pub mod authorization;
|
2022-11-04 07:32:09 +03:00
|
|
|
pub mod errors;
|
2022-10-18 00:47:58 +03:00
|
|
|
// TODO: these are only public so docs are generated. What's a better way to do this?
|
|
|
|
pub mod rpc_proxy_http;
|
|
|
|
pub mod rpc_proxy_ws;
|
|
|
|
pub mod status;
|
|
|
|
pub mod users;
|
2022-07-07 06:22:09 +03:00
|
|
|
|
2022-08-16 22:29:00 +03:00
|
|
|
use crate::app::Web3ProxyApp;
|
2022-06-05 22:58:47 +03:00
|
|
|
use axum::{
|
2022-10-31 23:51:06 +03:00
|
|
|
routing::{get, post, put},
|
2022-06-05 22:58:47 +03:00
|
|
|
Extension, Router,
|
|
|
|
};
|
2023-05-13 21:13:02 +03:00
|
|
|
use http::{header::AUTHORIZATION, StatusCode};
|
2023-05-13 01:15:32 +03:00
|
|
|
use listenfd::ListenFd;
|
2022-11-12 11:24:32 +03:00
|
|
|
use log::info;
|
2023-05-15 20:48:59 +03:00
|
|
|
use quick_cache_ttl::UnitWeighter;
|
2022-08-07 23:44:56 +03:00
|
|
|
use std::net::SocketAddr;
|
2022-06-05 22:58:47 +03:00
|
|
|
use std::sync::Arc;
|
2023-05-15 20:48:59 +03:00
|
|
|
use std::{iter::once, time::Duration};
|
2023-05-13 21:13:02 +03:00
|
|
|
use strum::{EnumCount, EnumIter};
|
2023-05-15 20:48:59 +03:00
|
|
|
use tokio::sync::broadcast;
|
2022-09-25 07:26:13 +03:00
|
|
|
use tower_http::cors::CorsLayer;
|
2022-09-25 19:35:01 +03:00
|
|
|
use tower_http::sensitive_headers::SetSensitiveRequestHeadersLayer;
|
2022-06-15 04:02:26 +03:00
|
|
|
|
2023-01-26 08:24:09 +03:00
|
|
|
/// simple keys for caching responses
|
2023-05-13 21:13:02 +03:00
|
|
|
#[derive(Copy, Clone, Hash, PartialEq, Eq, EnumCount, EnumIter)]
|
2023-05-17 00:58:00 +03:00
|
|
|
pub enum ResponseCacheKey {
|
2023-05-13 21:13:02 +03:00
|
|
|
BackupsNeeded,
|
|
|
|
Health,
|
2022-11-16 23:17:33 +03:00
|
|
|
Status,
|
|
|
|
}
|
|
|
|
|
2023-05-17 00:58:00 +03:00
|
|
|
pub type ResponseCache = quick_cache_ttl::CacheWithTTL<
|
|
|
|
ResponseCacheKey,
|
2023-05-17 01:27:18 +03:00
|
|
|
(StatusCode, &'static str, axum::body::Bytes),
|
2023-05-15 20:48:59 +03:00
|
|
|
UnitWeighter,
|
|
|
|
quick_cache_ttl::DefaultHashBuilder,
|
|
|
|
>;
|
2022-08-16 03:33:26 +03:00
|
|
|
|
2022-11-16 23:17:33 +03:00
|
|
|
/// Start the frontend server.
|
2023-01-26 08:24:09 +03:00
|
|
|
pub async fn serve(
|
|
|
|
port: u16,
|
|
|
|
proxy_app: Arc<Web3ProxyApp>,
|
|
|
|
mut shutdown_receiver: broadcast::Receiver<()>,
|
|
|
|
shutdown_complete_sender: broadcast::Sender<()>,
|
|
|
|
) -> anyhow::Result<()> {
|
2022-11-16 23:17:33 +03:00
|
|
|
// setup caches for whatever the frontend needs
|
2023-01-26 08:24:09 +03:00
|
|
|
// no need for max items since it is limited by the enum key
|
2023-05-13 01:15:32 +03:00
|
|
|
// TODO: latest moka allows for different ttls for different
|
2023-05-17 00:58:00 +03:00
|
|
|
let response_cache_size = ResponseCacheKey::COUNT;
|
2023-02-03 00:58:04 +03:00
|
|
|
|
2023-05-17 00:58:00 +03:00
|
|
|
let response_cache =
|
|
|
|
ResponseCache::new_with_unit_weights(response_cache_size, Duration::from_secs(1)).await;
|
2022-11-16 23:17:33 +03:00
|
|
|
|
2023-01-18 00:34:33 +03:00
|
|
|
// TODO: read config for if fastest/versus should be available publicly. default off
|
|
|
|
|
2022-08-21 11:18:57 +03:00
|
|
|
// build our axum Router
|
2022-06-05 22:58:47 +03:00
|
|
|
let app = Router::new()
|
2023-01-17 09:54:40 +03:00
|
|
|
// TODO: i think these routes could be done a lot better
|
|
|
|
//
|
|
|
|
// HTTP RPC (POST)
|
|
|
|
//
|
2023-05-13 01:15:32 +03:00
|
|
|
// Websocket RPC (GET)
|
|
|
|
// If not an RPC, GET will redirect to urls in the config
|
|
|
|
//
|
2023-01-17 09:54:40 +03:00
|
|
|
// public
|
2023-05-13 01:15:32 +03:00
|
|
|
.route(
|
|
|
|
"/",
|
|
|
|
post(rpc_proxy_http::proxy_web3_rpc).get(rpc_proxy_ws::websocket_handler),
|
|
|
|
)
|
2023-01-17 09:54:40 +03:00
|
|
|
// authenticated with and without trailing slash
|
|
|
|
.route(
|
|
|
|
"/rpc/:rpc_key/",
|
2023-05-13 01:15:32 +03:00
|
|
|
post(rpc_proxy_http::proxy_web3_rpc_with_key)
|
|
|
|
.get(rpc_proxy_ws::websocket_handler_with_key),
|
2023-01-17 09:54:40 +03:00
|
|
|
)
|
2023-01-07 02:58:52 +03:00
|
|
|
.route(
|
2022-10-27 03:12:42 +03:00
|
|
|
"/rpc/:rpc_key",
|
2023-05-13 01:15:32 +03:00
|
|
|
post(rpc_proxy_http::proxy_web3_rpc_with_key)
|
|
|
|
.get(rpc_proxy_ws::websocket_handler_with_key),
|
2022-09-24 07:31:06 +03:00
|
|
|
)
|
2023-03-03 04:39:50 +03:00
|
|
|
// authenticated debug route with and without trailing slash
|
|
|
|
.route(
|
|
|
|
"/debug/:rpc_key/",
|
2023-05-13 01:15:32 +03:00
|
|
|
post(rpc_proxy_http::debug_proxy_web3_rpc_with_key)
|
|
|
|
.get(rpc_proxy_ws::debug_websocket_handler_with_key),
|
2023-03-03 04:39:50 +03:00
|
|
|
)
|
|
|
|
.route(
|
|
|
|
"/debug/:rpc_key",
|
2023-05-13 01:15:32 +03:00
|
|
|
post(rpc_proxy_http::debug_proxy_web3_rpc_with_key)
|
|
|
|
.get(rpc_proxy_ws::debug_websocket_handler_with_key),
|
2023-03-03 04:39:50 +03:00
|
|
|
)
|
2023-01-17 09:54:40 +03:00
|
|
|
// public fastest with and without trailing slash
|
|
|
|
.route(
|
2023-05-13 01:15:32 +03:00
|
|
|
"/fastest/",
|
|
|
|
post(rpc_proxy_http::fastest_proxy_web3_rpc)
|
|
|
|
.get(rpc_proxy_ws::fastest_websocket_handler),
|
2023-01-17 09:54:40 +03:00
|
|
|
)
|
|
|
|
.route(
|
2023-05-13 01:15:32 +03:00
|
|
|
"/fastest",
|
|
|
|
post(rpc_proxy_http::fastest_proxy_web3_rpc)
|
|
|
|
.get(rpc_proxy_ws::fastest_websocket_handler),
|
2023-01-17 09:54:40 +03:00
|
|
|
)
|
|
|
|
// authenticated fastest with and without trailing slash
|
2023-01-07 02:58:52 +03:00
|
|
|
.route(
|
2023-01-17 09:54:40 +03:00
|
|
|
"/fastest/:rpc_key/",
|
2023-05-13 01:15:32 +03:00
|
|
|
post(rpc_proxy_http::fastest_proxy_web3_rpc_with_key)
|
|
|
|
.get(rpc_proxy_ws::fastest_websocket_handler_with_key),
|
2023-01-17 09:54:40 +03:00
|
|
|
)
|
|
|
|
.route(
|
|
|
|
"/fastest/:rpc_key",
|
2023-05-13 01:15:32 +03:00
|
|
|
post(rpc_proxy_http::fastest_proxy_web3_rpc_with_key)
|
|
|
|
.get(rpc_proxy_ws::fastest_websocket_handler_with_key),
|
2023-01-17 09:54:40 +03:00
|
|
|
)
|
|
|
|
// public versus
|
|
|
|
.route(
|
|
|
|
"/versus/",
|
2023-05-13 01:15:32 +03:00
|
|
|
post(rpc_proxy_http::versus_proxy_web3_rpc).get(rpc_proxy_ws::versus_websocket_handler),
|
2023-01-07 02:58:52 +03:00
|
|
|
)
|
2023-01-17 09:54:40 +03:00
|
|
|
.route(
|
|
|
|
"/versus",
|
2023-05-13 01:15:32 +03:00
|
|
|
post(rpc_proxy_http::versus_proxy_web3_rpc).get(rpc_proxy_ws::versus_websocket_handler),
|
2023-01-17 09:54:40 +03:00
|
|
|
)
|
|
|
|
// authenticated versus with and without trailing slash
|
|
|
|
.route(
|
|
|
|
"/versus/:rpc_key/",
|
2023-05-13 01:15:32 +03:00
|
|
|
post(rpc_proxy_http::versus_proxy_web3_rpc_with_key)
|
|
|
|
.get(rpc_proxy_ws::versus_websocket_handler_with_key),
|
2023-01-17 09:54:40 +03:00
|
|
|
)
|
|
|
|
.route(
|
|
|
|
"/versus/:rpc_key",
|
2023-05-13 01:15:32 +03:00
|
|
|
post(rpc_proxy_http::versus_proxy_web3_rpc_with_key)
|
|
|
|
.get(rpc_proxy_ws::versus_websocket_handler_with_key),
|
2023-01-17 09:54:40 +03:00
|
|
|
)
|
|
|
|
//
|
|
|
|
// System things
|
|
|
|
//
|
2022-09-25 19:37:45 +03:00
|
|
|
.route("/health", get(status::health))
|
2023-01-17 09:54:40 +03:00
|
|
|
.route("/status", get(status::status))
|
2023-04-14 03:15:01 +03:00
|
|
|
.route("/status/backups_needed", get(status::backups_needed))
|
2023-01-17 09:54:40 +03:00
|
|
|
//
|
|
|
|
// User stuff
|
|
|
|
//
|
User Balance + Referral Logic (#44)
* will implement balance topup endpoint
* will quickly fix other PR reviews
* merging from master
* will finish up godmoe
* will finish up login
* added logic to top up balance (first iteration)
* should implement additional columns soon (currency, amount, tx-hash), as well as a new table for spend
* updated migrations, will account for spend next
* get back to this later
* will merge PR from stats-v2
* stats v2
rebased all my commits and squashed them down to one
* cargo upgrade
* added migrtation for spend in accounting table. will run test-deposit next
* trying to get request from polygon
* first iteration /user/balance/:tx_hash works, needs to add accepted tokens next
* creating the referral code seems to work
* will now check if spending enough credits will lead to both parties receiving credits
* rpcstats takes care of accounting for spend data
* removed track spend from table
* Revert "removed track spend from table"
This reverts commit a50802d6ae75f786864c5ec42d0ceb2cb27124ed.
* Revert "rpcstats takes care of accounting for spend data"
This reverts commit 1cec728bf241e4cfd24351134637ed81c1a5a10b.
* removed rpc request table entity
* updated referral code to use ulid s
* credits used are aggregated
* added a bunch of fields to referrer
* added database logic whenever an aggregate stats is added. will have to iterate over this a couple times i think. go to (1) detecting accepted stables next, (2) fix influxdb bug and (3) start to write test
* removed track spend as this will occur in the database
* will first work on "balance", then referral. these should really be treated as two separate PRs (although already convoluted)
* balance logic initial commit
* breaking WIP, changing the RPC call logic functions
* will start testing next
* got rid of warnings & lint
* will proceed with subtracting / adding to balance
* added decimal points, balance tracking seems to work
* will beautify code a bit
* removed deprecated dependency, and added topic + deposit contract to app.yaml
* brownie test suite does not rely on local contract files it pulls all from polygonscan
* will continue with referral
* should perhaps (in a future revision) recordhow much the referees got for free. marking referrals seems to work rn
* user is upgraded to premium if they deposit more than 10$. we dont accept more than $10M in a single tx
* will start PR, referral seems to be fine so far, perhaps up to some numbers that still may need tweaking
* will start PR
* removed rogue comments, cleaned up payments a bit
* changes before PR
* apply stats
* added unique constraint
* some refactoring such that the user file is not too bloated
* compiling
* progress with subusers, creating a table entry seems to work
* good response type is there as well now, will work on getters from primary user and secondary user next
* subuser logic also seems fine now
* downgrade logic
* fixed bug influxdb does not support different types in same query (which makes sense)
* WIP temporary commit
* merging with PR
* Delete daemon.rs
there are multiple daemons now, so this was moved to `proxyd`
* will remove request clone to &mut
* multiple request handles for payment
* making requests still seem fine
* removed redundant commented out bits
* added deposit endpoint, added deposit amount and deposit user, untested yet
* small bug with downgrade tier id
* will add authorization so balance can be received for users
* balance history should be set now too
* will check balance over time again
* subususer can see rpc key balance if admin or owner
* stats also seems to work fine now with historical balance
* things seem to be building and working
* removed clone from OpenRequestHandle
* removed influxdb from workspace members
* changed config files
* reran sea-orm generate entities, added a foreign key, should be proper now
* removed contract from commit
* made deposit contract optional
* added topic in polygon dev
* changed deposit contract to deposit factory contract
* added selfrelation on user_tier
* added payment required
* changed chain id to u64
* add wss in polygon llamarpc
* removed origin and method from the table
* added onchain transactions naming (and forgot to add a migration before)
* changed foreign key to be the referrer (id), not the code itself
* forgot to add id as the target foreign key
* WIP adding cache to update role
* fixed merge conflicts
---------
Co-authored-by: Bryan Stitt <bryan@llamanodes.com>
Co-authored-by: Bryan Stitt <bryan@stitthappens.com>
2023-05-12 19:45:15 +03:00
|
|
|
.route(
|
|
|
|
"/user/login/:user_address",
|
|
|
|
get(users::authentication::user_login_get),
|
|
|
|
)
|
2022-09-24 00:46:27 +03:00
|
|
|
.route(
|
2022-09-25 19:37:45 +03:00
|
|
|
"/user/login/:user_address/:message_eip",
|
User Balance + Referral Logic (#44)
* will implement balance topup endpoint
* will quickly fix other PR reviews
* merging from master
* will finish up godmoe
* will finish up login
* added logic to top up balance (first iteration)
* should implement additional columns soon (currency, amount, tx-hash), as well as a new table for spend
* updated migrations, will account for spend next
* get back to this later
* will merge PR from stats-v2
* stats v2
rebased all my commits and squashed them down to one
* cargo upgrade
* added migrtation for spend in accounting table. will run test-deposit next
* trying to get request from polygon
* first iteration /user/balance/:tx_hash works, needs to add accepted tokens next
* creating the referral code seems to work
* will now check if spending enough credits will lead to both parties receiving credits
* rpcstats takes care of accounting for spend data
* removed track spend from table
* Revert "removed track spend from table"
This reverts commit a50802d6ae75f786864c5ec42d0ceb2cb27124ed.
* Revert "rpcstats takes care of accounting for spend data"
This reverts commit 1cec728bf241e4cfd24351134637ed81c1a5a10b.
* removed rpc request table entity
* updated referral code to use ulid s
* credits used are aggregated
* added a bunch of fields to referrer
* added database logic whenever an aggregate stats is added. will have to iterate over this a couple times i think. go to (1) detecting accepted stables next, (2) fix influxdb bug and (3) start to write test
* removed track spend as this will occur in the database
* will first work on "balance", then referral. these should really be treated as two separate PRs (although already convoluted)
* balance logic initial commit
* breaking WIP, changing the RPC call logic functions
* will start testing next
* got rid of warnings & lint
* will proceed with subtracting / adding to balance
* added decimal points, balance tracking seems to work
* will beautify code a bit
* removed deprecated dependency, and added topic + deposit contract to app.yaml
* brownie test suite does not rely on local contract files it pulls all from polygonscan
* will continue with referral
* should perhaps (in a future revision) recordhow much the referees got for free. marking referrals seems to work rn
* user is upgraded to premium if they deposit more than 10$. we dont accept more than $10M in a single tx
* will start PR, referral seems to be fine so far, perhaps up to some numbers that still may need tweaking
* will start PR
* removed rogue comments, cleaned up payments a bit
* changes before PR
* apply stats
* added unique constraint
* some refactoring such that the user file is not too bloated
* compiling
* progress with subusers, creating a table entry seems to work
* good response type is there as well now, will work on getters from primary user and secondary user next
* subuser logic also seems fine now
* downgrade logic
* fixed bug influxdb does not support different types in same query (which makes sense)
* WIP temporary commit
* merging with PR
* Delete daemon.rs
there are multiple daemons now, so this was moved to `proxyd`
* will remove request clone to &mut
* multiple request handles for payment
* making requests still seem fine
* removed redundant commented out bits
* added deposit endpoint, added deposit amount and deposit user, untested yet
* small bug with downgrade tier id
* will add authorization so balance can be received for users
* balance history should be set now too
* will check balance over time again
* subususer can see rpc key balance if admin or owner
* stats also seems to work fine now with historical balance
* things seem to be building and working
* removed clone from OpenRequestHandle
* removed influxdb from workspace members
* changed config files
* reran sea-orm generate entities, added a foreign key, should be proper now
* removed contract from commit
* made deposit contract optional
* added topic in polygon dev
* changed deposit contract to deposit factory contract
* added selfrelation on user_tier
* added payment required
* changed chain id to u64
* add wss in polygon llamarpc
* removed origin and method from the table
* added onchain transactions naming (and forgot to add a migration before)
* changed foreign key to be the referrer (id), not the code itself
* forgot to add id as the target foreign key
* WIP adding cache to update role
* fixed merge conflicts
---------
Co-authored-by: Bryan Stitt <bryan@llamanodes.com>
Co-authored-by: Bryan Stitt <bryan@stitthappens.com>
2023-05-12 19:45:15 +03:00
|
|
|
get(users::authentication::user_login_get),
|
|
|
|
)
|
|
|
|
.route("/user/login", post(users::authentication::user_login_post))
|
|
|
|
.route(
|
|
|
|
// /:rpc_key/:subuser_address/:new_status/:new_role
|
|
|
|
"/user/subuser",
|
|
|
|
get(users::subuser::modify_subuser),
|
|
|
|
)
|
|
|
|
.route("/user/subusers", get(users::subuser::get_subusers))
|
|
|
|
.route(
|
|
|
|
"/subuser/rpc_keys",
|
|
|
|
get(users::subuser::get_keys_as_subuser),
|
2022-09-24 00:46:27 +03:00
|
|
|
)
|
2022-10-26 00:10:05 +03:00
|
|
|
.route("/user", get(users::user_get))
|
|
|
|
.route("/user", post(users::user_post))
|
User Balance + Referral Logic (#44)
* will implement balance topup endpoint
* will quickly fix other PR reviews
* merging from master
* will finish up godmoe
* will finish up login
* added logic to top up balance (first iteration)
* should implement additional columns soon (currency, amount, tx-hash), as well as a new table for spend
* updated migrations, will account for spend next
* get back to this later
* will merge PR from stats-v2
* stats v2
rebased all my commits and squashed them down to one
* cargo upgrade
* added migrtation for spend in accounting table. will run test-deposit next
* trying to get request from polygon
* first iteration /user/balance/:tx_hash works, needs to add accepted tokens next
* creating the referral code seems to work
* will now check if spending enough credits will lead to both parties receiving credits
* rpcstats takes care of accounting for spend data
* removed track spend from table
* Revert "removed track spend from table"
This reverts commit a50802d6ae75f786864c5ec42d0ceb2cb27124ed.
* Revert "rpcstats takes care of accounting for spend data"
This reverts commit 1cec728bf241e4cfd24351134637ed81c1a5a10b.
* removed rpc request table entity
* updated referral code to use ulid s
* credits used are aggregated
* added a bunch of fields to referrer
* added database logic whenever an aggregate stats is added. will have to iterate over this a couple times i think. go to (1) detecting accepted stables next, (2) fix influxdb bug and (3) start to write test
* removed track spend as this will occur in the database
* will first work on "balance", then referral. these should really be treated as two separate PRs (although already convoluted)
* balance logic initial commit
* breaking WIP, changing the RPC call logic functions
* will start testing next
* got rid of warnings & lint
* will proceed with subtracting / adding to balance
* added decimal points, balance tracking seems to work
* will beautify code a bit
* removed deprecated dependency, and added topic + deposit contract to app.yaml
* brownie test suite does not rely on local contract files it pulls all from polygonscan
* will continue with referral
* should perhaps (in a future revision) recordhow much the referees got for free. marking referrals seems to work rn
* user is upgraded to premium if they deposit more than 10$. we dont accept more than $10M in a single tx
* will start PR, referral seems to be fine so far, perhaps up to some numbers that still may need tweaking
* will start PR
* removed rogue comments, cleaned up payments a bit
* changes before PR
* apply stats
* added unique constraint
* some refactoring such that the user file is not too bloated
* compiling
* progress with subusers, creating a table entry seems to work
* good response type is there as well now, will work on getters from primary user and secondary user next
* subuser logic also seems fine now
* downgrade logic
* fixed bug influxdb does not support different types in same query (which makes sense)
* WIP temporary commit
* merging with PR
* Delete daemon.rs
there are multiple daemons now, so this was moved to `proxyd`
* will remove request clone to &mut
* multiple request handles for payment
* making requests still seem fine
* removed redundant commented out bits
* added deposit endpoint, added deposit amount and deposit user, untested yet
* small bug with downgrade tier id
* will add authorization so balance can be received for users
* balance history should be set now too
* will check balance over time again
* subususer can see rpc key balance if admin or owner
* stats also seems to work fine now with historical balance
* things seem to be building and working
* removed clone from OpenRequestHandle
* removed influxdb from workspace members
* changed config files
* reran sea-orm generate entities, added a foreign key, should be proper now
* removed contract from commit
* made deposit contract optional
* added topic in polygon dev
* changed deposit contract to deposit factory contract
* added selfrelation on user_tier
* added payment required
* changed chain id to u64
* add wss in polygon llamarpc
* removed origin and method from the table
* added onchain transactions naming (and forgot to add a migration before)
* changed foreign key to be the referrer (id), not the code itself
* forgot to add id as the target foreign key
* WIP adding cache to update role
* fixed merge conflicts
---------
Co-authored-by: Bryan Stitt <bryan@llamanodes.com>
Co-authored-by: Bryan Stitt <bryan@stitthappens.com>
2023-05-12 19:45:15 +03:00
|
|
|
.route("/user/balance", get(users::payment::user_balance_get))
|
|
|
|
.route("/user/deposits", get(users::payment::user_deposits_get))
|
|
|
|
.route(
|
|
|
|
"/user/balance/:tx_hash",
|
|
|
|
get(users::payment::user_balance_post),
|
|
|
|
)
|
|
|
|
.route("/user/keys", get(users::rpc_keys::rpc_keys_get))
|
|
|
|
.route("/user/keys", post(users::rpc_keys::rpc_keys_management))
|
|
|
|
.route("/user/keys", put(users::rpc_keys::rpc_keys_management))
|
|
|
|
// .route("/user/referral/:referral_link", get(users::user_referral_link_get))
|
|
|
|
.route(
|
|
|
|
"/user/referral",
|
|
|
|
get(users::referral::user_referral_link_get),
|
|
|
|
)
|
|
|
|
.route("/user/revert_logs", get(users::stats::user_revert_logs_get))
|
2022-10-19 03:56:57 +03:00
|
|
|
.route(
|
|
|
|
"/user/stats/aggregate",
|
User Balance + Referral Logic (#44)
* will implement balance topup endpoint
* will quickly fix other PR reviews
* merging from master
* will finish up godmoe
* will finish up login
* added logic to top up balance (first iteration)
* should implement additional columns soon (currency, amount, tx-hash), as well as a new table for spend
* updated migrations, will account for spend next
* get back to this later
* will merge PR from stats-v2
* stats v2
rebased all my commits and squashed them down to one
* cargo upgrade
* added migrtation for spend in accounting table. will run test-deposit next
* trying to get request from polygon
* first iteration /user/balance/:tx_hash works, needs to add accepted tokens next
* creating the referral code seems to work
* will now check if spending enough credits will lead to both parties receiving credits
* rpcstats takes care of accounting for spend data
* removed track spend from table
* Revert "removed track spend from table"
This reverts commit a50802d6ae75f786864c5ec42d0ceb2cb27124ed.
* Revert "rpcstats takes care of accounting for spend data"
This reverts commit 1cec728bf241e4cfd24351134637ed81c1a5a10b.
* removed rpc request table entity
* updated referral code to use ulid s
* credits used are aggregated
* added a bunch of fields to referrer
* added database logic whenever an aggregate stats is added. will have to iterate over this a couple times i think. go to (1) detecting accepted stables next, (2) fix influxdb bug and (3) start to write test
* removed track spend as this will occur in the database
* will first work on "balance", then referral. these should really be treated as two separate PRs (although already convoluted)
* balance logic initial commit
* breaking WIP, changing the RPC call logic functions
* will start testing next
* got rid of warnings & lint
* will proceed with subtracting / adding to balance
* added decimal points, balance tracking seems to work
* will beautify code a bit
* removed deprecated dependency, and added topic + deposit contract to app.yaml
* brownie test suite does not rely on local contract files it pulls all from polygonscan
* will continue with referral
* should perhaps (in a future revision) recordhow much the referees got for free. marking referrals seems to work rn
* user is upgraded to premium if they deposit more than 10$. we dont accept more than $10M in a single tx
* will start PR, referral seems to be fine so far, perhaps up to some numbers that still may need tweaking
* will start PR
* removed rogue comments, cleaned up payments a bit
* changes before PR
* apply stats
* added unique constraint
* some refactoring such that the user file is not too bloated
* compiling
* progress with subusers, creating a table entry seems to work
* good response type is there as well now, will work on getters from primary user and secondary user next
* subuser logic also seems fine now
* downgrade logic
* fixed bug influxdb does not support different types in same query (which makes sense)
* WIP temporary commit
* merging with PR
* Delete daemon.rs
there are multiple daemons now, so this was moved to `proxyd`
* will remove request clone to &mut
* multiple request handles for payment
* making requests still seem fine
* removed redundant commented out bits
* added deposit endpoint, added deposit amount and deposit user, untested yet
* small bug with downgrade tier id
* will add authorization so balance can be received for users
* balance history should be set now too
* will check balance over time again
* subususer can see rpc key balance if admin or owner
* stats also seems to work fine now with historical balance
* things seem to be building and working
* removed clone from OpenRequestHandle
* removed influxdb from workspace members
* changed config files
* reran sea-orm generate entities, added a foreign key, should be proper now
* removed contract from commit
* made deposit contract optional
* added topic in polygon dev
* changed deposit contract to deposit factory contract
* added selfrelation on user_tier
* added payment required
* changed chain id to u64
* add wss in polygon llamarpc
* removed origin and method from the table
* added onchain transactions naming (and forgot to add a migration before)
* changed foreign key to be the referrer (id), not the code itself
* forgot to add id as the target foreign key
* WIP adding cache to update role
* fixed merge conflicts
---------
Co-authored-by: Bryan Stitt <bryan@llamanodes.com>
Co-authored-by: Bryan Stitt <bryan@stitthappens.com>
2023-05-12 19:45:15 +03:00
|
|
|
get(users::stats::user_stats_aggregated_get),
|
2022-12-12 22:00:15 +03:00
|
|
|
)
|
|
|
|
.route(
|
|
|
|
"/user/stats/aggregated",
|
User Balance + Referral Logic (#44)
* will implement balance topup endpoint
* will quickly fix other PR reviews
* merging from master
* will finish up godmoe
* will finish up login
* added logic to top up balance (first iteration)
* should implement additional columns soon (currency, amount, tx-hash), as well as a new table for spend
* updated migrations, will account for spend next
* get back to this later
* will merge PR from stats-v2
* stats v2
rebased all my commits and squashed them down to one
* cargo upgrade
* added migrtation for spend in accounting table. will run test-deposit next
* trying to get request from polygon
* first iteration /user/balance/:tx_hash works, needs to add accepted tokens next
* creating the referral code seems to work
* will now check if spending enough credits will lead to both parties receiving credits
* rpcstats takes care of accounting for spend data
* removed track spend from table
* Revert "removed track spend from table"
This reverts commit a50802d6ae75f786864c5ec42d0ceb2cb27124ed.
* Revert "rpcstats takes care of accounting for spend data"
This reverts commit 1cec728bf241e4cfd24351134637ed81c1a5a10b.
* removed rpc request table entity
* updated referral code to use ulid s
* credits used are aggregated
* added a bunch of fields to referrer
* added database logic whenever an aggregate stats is added. will have to iterate over this a couple times i think. go to (1) detecting accepted stables next, (2) fix influxdb bug and (3) start to write test
* removed track spend as this will occur in the database
* will first work on "balance", then referral. these should really be treated as two separate PRs (although already convoluted)
* balance logic initial commit
* breaking WIP, changing the RPC call logic functions
* will start testing next
* got rid of warnings & lint
* will proceed with subtracting / adding to balance
* added decimal points, balance tracking seems to work
* will beautify code a bit
* removed deprecated dependency, and added topic + deposit contract to app.yaml
* brownie test suite does not rely on local contract files it pulls all from polygonscan
* will continue with referral
* should perhaps (in a future revision) recordhow much the referees got for free. marking referrals seems to work rn
* user is upgraded to premium if they deposit more than 10$. we dont accept more than $10M in a single tx
* will start PR, referral seems to be fine so far, perhaps up to some numbers that still may need tweaking
* will start PR
* removed rogue comments, cleaned up payments a bit
* changes before PR
* apply stats
* added unique constraint
* some refactoring such that the user file is not too bloated
* compiling
* progress with subusers, creating a table entry seems to work
* good response type is there as well now, will work on getters from primary user and secondary user next
* subuser logic also seems fine now
* downgrade logic
* fixed bug influxdb does not support different types in same query (which makes sense)
* WIP temporary commit
* merging with PR
* Delete daemon.rs
there are multiple daemons now, so this was moved to `proxyd`
* will remove request clone to &mut
* multiple request handles for payment
* making requests still seem fine
* removed redundant commented out bits
* added deposit endpoint, added deposit amount and deposit user, untested yet
* small bug with downgrade tier id
* will add authorization so balance can be received for users
* balance history should be set now too
* will check balance over time again
* subususer can see rpc key balance if admin or owner
* stats also seems to work fine now with historical balance
* things seem to be building and working
* removed clone from OpenRequestHandle
* removed influxdb from workspace members
* changed config files
* reran sea-orm generate entities, added a foreign key, should be proper now
* removed contract from commit
* made deposit contract optional
* added topic in polygon dev
* changed deposit contract to deposit factory contract
* added selfrelation on user_tier
* added payment required
* changed chain id to u64
* add wss in polygon llamarpc
* removed origin and method from the table
* added onchain transactions naming (and forgot to add a migration before)
* changed foreign key to be the referrer (id), not the code itself
* forgot to add id as the target foreign key
* WIP adding cache to update role
* fixed merge conflicts
---------
Co-authored-by: Bryan Stitt <bryan@llamanodes.com>
Co-authored-by: Bryan Stitt <bryan@stitthappens.com>
2023-05-12 19:45:15 +03:00
|
|
|
get(users::stats::user_stats_aggregated_get),
|
|
|
|
)
|
|
|
|
.route(
|
|
|
|
"/user/stats/detailed",
|
|
|
|
get(users::stats::user_stats_detailed_get),
|
|
|
|
)
|
|
|
|
.route(
|
|
|
|
"/user/logout",
|
|
|
|
post(users::authentication::user_logout_post),
|
2022-10-19 03:56:57 +03:00
|
|
|
)
|
2023-02-19 23:34:39 +03:00
|
|
|
.route("/admin/modify_role", get(admin::admin_change_user_roles))
|
2023-03-03 04:39:50 +03:00
|
|
|
.route(
|
|
|
|
"/admin/imitate-login/:admin_address/:user_address",
|
|
|
|
get(admin::admin_login_get),
|
|
|
|
)
|
2023-02-19 23:34:39 +03:00
|
|
|
.route(
|
2023-02-15 17:20:16 +03:00
|
|
|
"/admin/imitate-login/:admin_address/:user_address/:message_eip",
|
2023-02-19 23:34:39 +03:00
|
|
|
get(admin::admin_login_get),
|
|
|
|
)
|
|
|
|
.route("/admin/imitate-login", post(admin::admin_login_post))
|
2023-02-27 12:56:06 +03:00
|
|
|
.route("/admin/imitate-logout", post(admin::admin_logout_post))
|
2023-01-17 09:54:40 +03:00
|
|
|
//
|
|
|
|
// Axum layers
|
2022-08-21 11:18:57 +03:00
|
|
|
// layers are ordered bottom up
|
|
|
|
// the last layer is first for requests and last for responses
|
2023-01-17 09:54:40 +03:00
|
|
|
//
|
2022-09-25 19:35:01 +03:00
|
|
|
// Mark the `Authorization` request header as sensitive so it doesn't show in logs
|
|
|
|
.layer(SetSensitiveRequestHeadersLayer::new(once(AUTHORIZATION)))
|
2022-09-25 07:26:13 +03:00
|
|
|
// handle cors
|
|
|
|
.layer(CorsLayer::very_permissive())
|
2022-09-25 19:35:01 +03:00
|
|
|
// application state
|
2023-05-13 01:15:32 +03:00
|
|
|
.layer(Extension(proxy_app))
|
2022-11-16 23:17:33 +03:00
|
|
|
// frontend caches
|
2023-05-17 00:58:00 +03:00
|
|
|
.layer(Extension(Arc::new(response_cache)))
|
2022-08-07 22:35:24 +03:00
|
|
|
// 404 for any unknown routes
|
2022-12-14 05:13:23 +03:00
|
|
|
.fallback(errors::handler_404);
|
2022-06-05 22:58:47 +03:00
|
|
|
|
2023-05-13 01:15:32 +03:00
|
|
|
let server_builder = if let Some(listener) = ListenFd::from_env().take_tcp_listener(0)? {
|
|
|
|
// use systemd socket magic for no downtime deploys
|
|
|
|
let addr = listener.local_addr()?;
|
2022-08-11 05:57:01 +03:00
|
|
|
|
2023-05-13 01:15:32 +03:00
|
|
|
info!("listening with fd at {}", addr);
|
|
|
|
|
|
|
|
axum::Server::from_tcp(listener)?
|
|
|
|
} else {
|
|
|
|
info!("listening on port {}", port);
|
|
|
|
// TODO: allow only listening on localhost? top_config.app.host.parse()?
|
|
|
|
let addr = SocketAddr::from(([0, 0, 0, 0], port));
|
|
|
|
|
|
|
|
axum::Server::try_bind(&addr)?
|
|
|
|
};
|
|
|
|
|
|
|
|
// into_make_service is enough if we always run behind a proxy
|
2022-08-11 05:57:01 +03:00
|
|
|
/*
|
|
|
|
It sequentially looks for an IP in:
|
|
|
|
- x-forwarded-for header (de-facto standard)
|
|
|
|
- x-real-ip header
|
|
|
|
- forwarded header (new standard)
|
|
|
|
- axum::extract::ConnectInfo (if not behind proxy)
|
|
|
|
*/
|
2023-05-13 01:15:32 +03:00
|
|
|
#[cfg(feature = "connectinfo")]
|
|
|
|
let make_service = {
|
|
|
|
info!("connectinfo feature enabled");
|
|
|
|
app.into_make_service_with_connect_info::<SocketAddr>()
|
|
|
|
};
|
|
|
|
|
|
|
|
#[cfg(not(feature = "connectinfo"))]
|
|
|
|
let make_service = {
|
|
|
|
info!("connectinfo feature disabled");
|
|
|
|
app.into_make_service()
|
|
|
|
};
|
2022-08-11 05:57:01 +03:00
|
|
|
|
2023-05-13 01:15:32 +03:00
|
|
|
let server = server_builder
|
|
|
|
.serve(make_service)
|
2022-08-07 09:48:57 +03:00
|
|
|
// TODO: option to use with_connect_info. we want it in dev, but not when running behind a proxy, but not
|
2023-04-04 15:40:22 +03:00
|
|
|
.with_graceful_shutdown(async move {
|
|
|
|
let _ = shutdown_receiver.recv().await;
|
|
|
|
})
|
|
|
|
.await
|
|
|
|
.map_err(Into::into);
|
|
|
|
|
|
|
|
let _ = shutdown_complete_sender.send(());
|
2023-01-26 08:24:09 +03:00
|
|
|
|
2023-04-04 15:40:22 +03:00
|
|
|
server
|
2022-06-05 22:58:47 +03:00
|
|
|
}
|