From b35950790bb15094159853975c81217f4df5e9a4 Mon Sep 17 00:00:00 2001 From: hashmap Date: Tue, 18 Sep 2018 01:37:23 +0200 Subject: [PATCH] Use POST to compact and validate chain (#1541) * More comments * Move HeaderHandler code --- api/src/handlers.rs | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/api/src/handlers.rs b/api/src/handlers.rs index 2b401ad47..f7220c9a3 100644 --- a/api/src/handlers.rs +++ b/api/src/handlers.rs @@ -542,13 +542,13 @@ impl Handler for ChainValidationHandler { /// Chain compaction handler. Trigger a compaction of the chain state to regain /// storage space. -/// GET /v1/chain/compact +/// POST /v1/chain/compact pub struct ChainCompactHandler { pub chain: Weak, } impl Handler for ChainCompactHandler { - fn get(&self, _req: Request) -> ResponseFuture { + fn post(&self, _req: Request) -> ResponseFuture { match w(&self.chain).compact() { Ok(_) => response(StatusCode::OK, ""), Err(e) => response( @@ -599,6 +599,18 @@ impl HeaderHandler { } } +impl Handler for HeaderHandler { + fn get(&self, req: Request) -> ResponseFuture { + let el = match req.uri().path().trim_right_matches("/").rsplit("/").next() { + None => return response(StatusCode::BAD_REQUEST, "invalid url"), + Some(el) => el, + }; + result_to_response(self.get_header(el.to_string())) + } +} + + + /// Gets block details given either a hash or an unspent commit /// GET /v1/blocks/ /// GET /v1/blocks/ @@ -683,17 +695,8 @@ impl Handler for BlockHandler { } } -impl Handler for HeaderHandler { - fn get(&self, req: Request) -> ResponseFuture { - let el = match req.uri().path().trim_right_matches("/").rsplit("/").next() { - None => return response(StatusCode::BAD_REQUEST, "invalid url"), - Some(el) => el, - }; - result_to_response(self.get_header(el.to_string())) - } -} - -// Get basic information about the transaction pool. +/// Get basic information about the transaction pool. +/// GET /v1/pool struct PoolInfoHandler { tx_pool: Weak>, } @@ -715,7 +718,8 @@ struct TxWrapper { tx_hex: String, } -// Push new transaction to our local transaction pool. +/// Push new transaction to our local transaction pool. +/// POST /v1/pool/push struct PoolPushHandler { tx_pool: Weak>, } @@ -909,8 +913,8 @@ pub fn build_router( let route_list = vec![ "get blocks".to_string(), "get chain".to_string(), - "get chain/compact".to_string(), - "get chain/validate".to_string(), + "post chain/compact".to_string(), + "post chain/validate".to_string(), "get chain/outputs".to_string(), "get status".to_string(), "get txhashset/roots".to_string(),