diff options
Diffstat (limited to 'src/routes.rs')
-rw-r--r-- | src/routes.rs | 38 |
1 files changed, 35 insertions, 3 deletions
diff --git a/src/routes.rs b/src/routes.rs index 95138e6..499ba35 100644 --- a/src/routes.rs +++ b/src/routes.rs | |||
@@ -1,8 +1,9 @@ | |||
1 | use warp::{Filter, Rejection, Reply}; | 1 | use warp::{Filter, Rejection, Reply}; |
2 | 2 | ||
3 | use crate::auth::with_auth; | ||
3 | use crate::custom_filters; | 4 | use crate::custom_filters; |
4 | use crate::handlers; | 5 | use crate::handlers; |
5 | use crate::schema::Db; | 6 | use crate::schema::{Db, Transaction}; |
6 | 7 | ||
7 | /// Root, all routes combined | 8 | /// Root, all routes combined |
8 | pub fn consensus_routes(db: Db) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone { | 9 | pub fn consensus_routes(db: Db) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone { |
@@ -14,7 +15,8 @@ pub fn consensus_routes(db: Db) -> impl Filter<Extract = impl Reply, Error = Rej | |||
14 | 15 | ||
15 | /// GET /transaction warp route | 16 | /// GET /transaction warp route |
16 | pub fn transaction_list(db: Db) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone { | 17 | pub fn transaction_list(db: Db) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone { |
17 | warp::path!("transaction") | 18 | warp::path("transaction") |
19 | .and(warp::path::end()) | ||
18 | .and(warp::get()) | 20 | .and(warp::get()) |
19 | .and(custom_filters::with_db(db)) | 21 | .and(custom_filters::with_db(db)) |
20 | .and_then(handlers::list_transactions) | 22 | .and_then(handlers::list_transactions) |
@@ -30,13 +32,43 @@ pub fn block_list(db: Db) -> impl Filter<Extract = impl Reply, Error = Rejection | |||
30 | 32 | ||
31 | /// POST /transaction warp route | 33 | /// POST /transaction warp route |
32 | pub fn transaction_propose(db: Db) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone { | 34 | pub fn transaction_propose(db: Db) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone { |
33 | warp::path!("transaction") | 35 | warp::path("transaction") |
36 | .and(warp::path::end()) | ||
34 | .and(warp::post()) | 37 | .and(warp::post()) |
35 | .and(custom_filters::transaction_json_body()) | 38 | .and(custom_filters::transaction_json_body()) |
36 | .and(custom_filters::with_db(db)) | 39 | .and(custom_filters::with_db(db)) |
37 | .and_then(handlers::propose_transaction) | 40 | .and_then(handlers::propose_transaction) |
38 | } | 41 | } |
39 | 42 | ||
43 | /// POST /transaction warp route with authentication | ||
44 | pub fn authenticated_transaction_propose( | ||
45 | db: Db, | ||
46 | ) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone { | ||
47 | warp::path("transaction") | ||
48 | .and(warp::path::end()) | ||
49 | .and(warp::post()) | ||
50 | .and(custom_filters::transaction_json_body()) | ||
51 | .map(|t: Transaction| { | ||
52 | with_auth(db.clone(), t) | ||
53 | }) | ||
54 | .untuple_one() | ||
55 | .and(custom_filters::transaction_json_body()) | ||
56 | .and(custom_filters::with_db(db)) | ||
57 | .and_then(handlers::propose_authenticated_transaction) | ||
58 | |||
59 | // .and(custom_filters::transaction_json_body()) | ||
60 | // // TODO: you might have to restore this | ||
61 | // // what we're trying to do is knowing which public key to use to decode the jwt in the | ||
62 | // // header of the request, we will either request it through a header (ugly, ugh) or get it | ||
63 | // // from json (then how do we chain these ugh) or we can just validate/check (move the | ||
64 | // // header/jwt logic to propose_transaction but that doesn't feel right either | ||
65 | // // good luck <10-04-21, yigit> // | ||
66 | // .map(|t: Transaction| with_auth(db.clone(), t)) | ||
67 | // .and(custom_filters::transaction_json_body()) | ||
68 | // .and(custom_filters::with_db(db)) | ||
69 | // .and_then(handlers::propose_transaction) | ||
70 | } | ||
71 | |||
40 | /// POST /block warp route | 72 | /// POST /block warp route |
41 | pub fn block_propose(db: Db) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone { | 73 | pub fn block_propose(db: Db) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone { |
42 | warp::path!("block") | 74 | warp::path!("block") |