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/routes.rs | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) (limited to 'src/routes.rs') diff --git a/src/routes.rs b/src/routes.rs index fc4426a..9054fb6 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -4,12 +4,15 @@ use crate::custom_filters; use crate::handlers; use crate::schema::Db; -// Root, all routes combined +/// Root, all routes combined pub fn consensus_routes(db: Db) -> impl Filter + Clone { - transaction_list(db.clone()).or(transaction_propose(db.clone())) + transaction_list(db.clone()) + .or(transaction_propose(db.clone())) + .or(block_propose(db.clone())) + .or(block_list(db.clone())) } -// GET /transaction +/// GET /transaction pub fn transaction_list(db: Db) -> impl Filter + Clone { warp::path!("transaction") .and(warp::get()) @@ -17,15 +20,32 @@ pub fn transaction_list(db: Db) -> impl Filter impl Filter + Clone { + warp::path!("block") + .and(warp::get()) + .and(custom_filters::with_db(db)) + .and_then(handlers::list_blocks) +} + +/// POST /transaction pub fn transaction_propose(db: Db) -> impl Filter + Clone { warp::path!("transaction") .and(warp::post()) - .and(custom_filters::json_body()) + .and(custom_filters::transaction_json_body()) .and(custom_filters::with_db(db)) .and_then(handlers::propose_transaction) } +/// POST /block +pub fn block_propose(db: Db) -> impl Filter + Clone { + warp::path!("block") + .and(warp::post()) + .and(custom_filters::block_json_body()) + .and(custom_filters::with_db(db)) + .and_then(handlers::propose_block) +} + /////////////////////////// // below are not mine. // /////////////////////////// -- cgit v1.2.3-70-g09d2