From 84d9c14a17e864058527981e3388cef148827c11 Mon Sep 17 00:00:00 2001 From: Yigit Sever Date: Wed, 7 Apr 2021 04:33:45 +0300 Subject: 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 --- src/custom_filters.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/custom_filters.rs') 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 @@ use std::convert::Infallible; use warp::{Filter, Rejection}; -use crate::schema::{Db, Transaction}; // `Block` coming later +use crate::schema::{Block, Db, Transaction}; // Database context for routes pub fn with_db(db: Db) -> impl Filter + Clone { @@ -15,7 +15,12 @@ pub fn with_db(db: Db) -> impl Filter + Clo // warp::query::() // } -// Accept only JSON body and reject big payloads -pub fn json_body() -> impl Filter + Clone { +// Accept only json encoded Transaction body and reject big payloads +pub fn transaction_json_body() -> impl Filter + Clone { + warp::body::content_length_limit(1024 * 32).and(warp::body::json()) +} + +// Accept only json encoded Transaction body and reject big payloads +pub fn block_json_body() -> impl Filter + Clone { warp::body::content_length_limit(1024 * 32).and(warp::body::json()) } -- cgit v1.2.3-70-g09d2