mirror of
https://github.com/mimblewimble/grin.git
synced 2025-02-08 04:11:08 +03:00
Use POST to compact and validate chain (#1541)
* More comments * Move HeaderHandler code
This commit is contained in:
parent
a0deb18e77
commit
b35950790b
1 changed files with 20 additions and 16 deletions
|
@ -542,13 +542,13 @@ impl Handler for ChainValidationHandler {
|
||||||
|
|
||||||
/// Chain compaction handler. Trigger a compaction of the chain state to regain
|
/// Chain compaction handler. Trigger a compaction of the chain state to regain
|
||||||
/// storage space.
|
/// storage space.
|
||||||
/// GET /v1/chain/compact
|
/// POST /v1/chain/compact
|
||||||
pub struct ChainCompactHandler {
|
pub struct ChainCompactHandler {
|
||||||
pub chain: Weak<chain::Chain>,
|
pub chain: Weak<chain::Chain>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Handler for ChainCompactHandler {
|
impl Handler for ChainCompactHandler {
|
||||||
fn get(&self, _req: Request<Body>) -> ResponseFuture {
|
fn post(&self, _req: Request<Body>) -> ResponseFuture {
|
||||||
match w(&self.chain).compact() {
|
match w(&self.chain).compact() {
|
||||||
Ok(_) => response(StatusCode::OK, ""),
|
Ok(_) => response(StatusCode::OK, ""),
|
||||||
Err(e) => response(
|
Err(e) => response(
|
||||||
|
@ -599,6 +599,18 @@ impl HeaderHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Handler for HeaderHandler {
|
||||||
|
fn get(&self, req: Request<Body>) -> 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
|
/// Gets block details given either a hash or an unspent commit
|
||||||
/// GET /v1/blocks/<hash>
|
/// GET /v1/blocks/<hash>
|
||||||
/// GET /v1/blocks/<height>
|
/// GET /v1/blocks/<height>
|
||||||
|
@ -683,17 +695,8 @@ impl Handler for BlockHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Handler for HeaderHandler {
|
/// Get basic information about the transaction pool.
|
||||||
fn get(&self, req: Request<Body>) -> ResponseFuture {
|
/// GET /v1/pool
|
||||||
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.
|
|
||||||
struct PoolInfoHandler {
|
struct PoolInfoHandler {
|
||||||
tx_pool: Weak<RwLock<pool::TransactionPool>>,
|
tx_pool: Weak<RwLock<pool::TransactionPool>>,
|
||||||
}
|
}
|
||||||
|
@ -715,7 +718,8 @@ struct TxWrapper {
|
||||||
tx_hex: String,
|
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 {
|
struct PoolPushHandler {
|
||||||
tx_pool: Weak<RwLock<pool::TransactionPool>>,
|
tx_pool: Weak<RwLock<pool::TransactionPool>>,
|
||||||
}
|
}
|
||||||
|
@ -909,8 +913,8 @@ pub fn build_router(
|
||||||
let route_list = vec![
|
let route_list = vec![
|
||||||
"get blocks".to_string(),
|
"get blocks".to_string(),
|
||||||
"get chain".to_string(),
|
"get chain".to_string(),
|
||||||
"get chain/compact".to_string(),
|
"post chain/compact".to_string(),
|
||||||
"get chain/validate".to_string(),
|
"post chain/validate".to_string(),
|
||||||
"get chain/outputs".to_string(),
|
"get chain/outputs".to_string(),
|
||||||
"get status".to_string(),
|
"get status".to_string(),
|
||||||
"get txhashset/roots".to_string(),
|
"get txhashset/roots".to_string(),
|
||||||
|
|
Loading…
Reference in a new issue