aboutsummaryrefslogtreecommitdiffstats
path: root/src/custom_filters.rs
diff options
context:
space:
mode:
authorYigit Sever2021-04-07 04:33:45 +0300
committerYigit Sever2021-04-07 04:35:44 +0300
commit84d9c14a17e864058527981e3388cef148827c11 (patch)
tree19c7b4b4d67d2ba2d3d87ba7eca009ff997e0cd0 /src/custom_filters.rs
parent95ff6371303ac28d05b25fd9f6e436c5d0a58d4c (diff)
downloadgradecoin-84d9c14a17e864058527981e3388cef148827c11.tar.gz
gradecoin-84d9c14a17e864058527981e3388cef148827c11.tar.bz2
gradecoin-84d9c14a17e864058527981e3388cef148827c11.zip
Implement Block GET/PUT with new schema
- `Arc`+`Mutex` is replaced by `parking_lot::RwLock,` decoupled Read+Write and ability to upgrade read locks into write locks if needed - Schema has changed, `Db` is now a struct that implements `new()` to return a new instance of itself, pros/cons listed in code but tl;dr blockchain and pending transactions are separate now - `custom_filters` now supports extracting Block json and Transaction json in separate functions too - /block GET and PUT implemented, `Blocks` currently have one check (transactions appear in pending transaction) - debug is working after something, dunno how I fixed it
Diffstat (limited to 'src/custom_filters.rs')
-rw-r--r--src/custom_filters.rs11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/custom_filters.rs b/src/custom_filters.rs
index 86a78d4..7caf71a 100644
--- a/src/custom_filters.rs
+++ b/src/custom_filters.rs
@@ -3,7 +3,7 @@
3use std::convert::Infallible; 3use std::convert::Infallible;
4use warp::{Filter, Rejection}; 4use warp::{Filter, Rejection};
5 5
6use crate::schema::{Db, Transaction}; // `Block` coming later 6use crate::schema::{Block, Db, Transaction};
7 7
8// Database context for routes 8// Database context for routes
9pub fn with_db(db: Db) -> impl Filter<Extract = (Db,), Error = Infallible> + Clone { 9pub fn with_db(db: Db) -> impl Filter<Extract = (Db,), Error = Infallible> + Clone {
@@ -15,7 +15,12 @@ pub fn with_db(db: Db) -> impl Filter<Extract = (Db,), Error = Infallible> + Clo
15// warp::query::<ListOptions>() 15// warp::query::<ListOptions>()
16// } 16// }
17 17
18// Accept only JSON body and reject big payloads 18// Accept only json encoded Transaction body and reject big payloads
19pub fn json_body() -> impl Filter<Extract = (Transaction,), Error = Rejection> + Clone { 19pub fn transaction_json_body() -> impl Filter<Extract = (Transaction,), Error = Rejection> + Clone {
20 warp::body::content_length_limit(1024 * 32).and(warp::body::json())
21}
22
23// Accept only json encoded Transaction body and reject big payloads
24pub fn block_json_body() -> impl Filter<Extract = (Block,), Error = Rejection> + Clone {
20 warp::body::content_length_limit(1024 * 32).and(warp::body::json()) 25 warp::body::content_length_limit(1024 * 32).and(warp::body::json())
21} 26}