aboutsummaryrefslogtreecommitdiffstats
path: root/src/routes.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/routes.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/routes.rs')
-rw-r--r--src/routes.rs30
1 files changed, 25 insertions, 5 deletions
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;
4use crate::handlers; 4use crate::handlers;
5use crate::schema::Db; 5use crate::schema::Db;
6 6
7// Root, all routes combined 7/// Root, all routes combined
8pub fn consensus_routes(db: Db) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone { 8pub fn consensus_routes(db: Db) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
9 transaction_list(db.clone()).or(transaction_propose(db.clone())) 9 transaction_list(db.clone())
10 .or(transaction_propose(db.clone()))
11 .or(block_propose(db.clone()))
12 .or(block_list(db.clone()))
10} 13}
11 14
12// GET /transaction 15/// GET /transaction
13pub fn transaction_list(db: Db) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone { 16pub fn transaction_list(db: Db) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
14 warp::path!("transaction") 17 warp::path!("transaction")
15 .and(warp::get()) 18 .and(warp::get())
@@ -17,15 +20,32 @@ pub fn transaction_list(db: Db) -> impl Filter<Extract = impl Reply, Error = Rej
17 .and_then(handlers::list_transactions) 20 .and_then(handlers::list_transactions)
18} 21}
19 22
20// POST /transaction 23/// GET /block
24pub fn block_list(db: Db) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
25 warp::path!("block")
26 .and(warp::get())
27 .and(custom_filters::with_db(db))
28 .and_then(handlers::list_blocks)
29}
30
31/// POST /transaction
21pub fn transaction_propose(db: Db) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone { 32pub fn transaction_propose(db: Db) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
22 warp::path!("transaction") 33 warp::path!("transaction")
23 .and(warp::post()) 34 .and(warp::post())
24 .and(custom_filters::json_body()) 35 .and(custom_filters::transaction_json_body())
25 .and(custom_filters::with_db(db)) 36 .and(custom_filters::with_db(db))
26 .and_then(handlers::propose_transaction) 37 .and_then(handlers::propose_transaction)
27} 38}
28 39
40/// POST /block
41pub fn block_propose(db: Db) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
42 warp::path!("block")
43 .and(warp::post())
44 .and(custom_filters::block_json_body())
45 .and(custom_filters::with_db(db))
46 .and_then(handlers::propose_block)
47}
48
29/////////////////////////// 49///////////////////////////
30// below are not mine. // 50// below are not mine. //
31/////////////////////////// 51///////////////////////////