2020-01-20 14:40:58 +03:00
|
|
|
// Copyright 2020 The Grin Developers
|
2018-11-03 09:46:12 +03:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2019-12-06 13:57:53 +03:00
|
|
|
pub mod blocks_api;
|
|
|
|
pub mod chain_api;
|
|
|
|
pub mod peers_api;
|
|
|
|
pub mod pool_api;
|
|
|
|
pub mod server_api;
|
|
|
|
pub mod transactions_api;
|
|
|
|
pub mod utils;
|
|
|
|
pub mod version_api;
|
2018-11-03 09:46:12 +03:00
|
|
|
|
|
|
|
use self::blocks_api::BlockHandler;
|
|
|
|
use self::blocks_api::HeaderHandler;
|
|
|
|
use self::chain_api::ChainCompactHandler;
|
|
|
|
use self::chain_api::ChainHandler;
|
|
|
|
use self::chain_api::ChainValidationHandler;
|
2019-08-30 12:03:12 +03:00
|
|
|
use self::chain_api::KernelHandler;
|
2018-11-03 09:46:12 +03:00
|
|
|
use self::chain_api::OutputHandler;
|
|
|
|
use self::peers_api::PeerHandler;
|
|
|
|
use self::peers_api::PeersAllHandler;
|
|
|
|
use self::peers_api::PeersConnectedHandler;
|
2019-03-18 21:34:35 +03:00
|
|
|
use self::pool_api::PoolInfoHandler;
|
|
|
|
use self::pool_api::PoolPushHandler;
|
|
|
|
use self::server_api::IndexHandler;
|
2019-06-27 11:19:17 +03:00
|
|
|
use self::server_api::StatusHandler;
|
2019-03-18 21:34:35 +03:00
|
|
|
use self::transactions_api::TxHashSetHandler;
|
2019-06-27 11:19:17 +03:00
|
|
|
use self::version_api::VersionHandler;
|
2019-12-06 13:57:53 +03:00
|
|
|
use crate::auth::{
|
|
|
|
BasicAuthMiddleware, BasicAuthURIMiddleware, GRIN_BASIC_REALM, GRIN_FOREIGN_BASIC_REALM,
|
|
|
|
};
|
2018-12-08 02:59:40 +03:00
|
|
|
use crate::chain;
|
2019-12-06 13:57:53 +03:00
|
|
|
use crate::chain::{Chain, SyncState};
|
2020-04-30 18:41:49 +03:00
|
|
|
use crate::core::core::verifier_cache::VerifierCache;
|
2019-12-06 13:57:53 +03:00
|
|
|
use crate::foreign::Foreign;
|
|
|
|
use crate::foreign_rpc::ForeignRpc;
|
|
|
|
use crate::owner::Owner;
|
|
|
|
use crate::owner_rpc::OwnerRpc;
|
2018-12-08 02:59:40 +03:00
|
|
|
use crate::p2p;
|
|
|
|
use crate::pool;
|
2020-04-30 18:41:49 +03:00
|
|
|
use crate::pool::{BlockChain, PoolAdapter};
|
2019-12-06 13:57:53 +03:00
|
|
|
use crate::rest::{ApiServer, Error, TLSConfig};
|
|
|
|
use crate::router::ResponseFuture;
|
2019-03-18 21:34:35 +03:00
|
|
|
use crate::router::{Router, RouterError};
|
2019-12-06 13:57:53 +03:00
|
|
|
use crate::util::to_base64;
|
2018-12-08 02:59:40 +03:00
|
|
|
use crate::util::RwLock;
|
2019-12-06 13:57:53 +03:00
|
|
|
use crate::web::*;
|
|
|
|
use easy_jsonrpc_mw::{Handler, MaybeReply};
|
|
|
|
use hyper::{Body, Request, Response, StatusCode};
|
|
|
|
use serde::Serialize;
|
2018-11-03 09:46:12 +03:00
|
|
|
use std::net::SocketAddr;
|
2019-12-06 13:57:53 +03:00
|
|
|
use std::sync::{Arc, Weak};
|
2018-11-03 09:46:12 +03:00
|
|
|
|
2019-12-06 13:57:53 +03:00
|
|
|
/// Listener version, providing same API but listening for requests on a
|
|
|
|
/// port and wrapping the calls
|
2020-04-30 18:41:49 +03:00
|
|
|
pub fn node_apis<B, P, V>(
|
2019-12-06 13:57:53 +03:00
|
|
|
addr: &str,
|
2018-11-03 09:46:12 +03:00
|
|
|
chain: Arc<chain::Chain>,
|
2020-04-30 18:41:49 +03:00
|
|
|
tx_pool: Arc<RwLock<pool::TransactionPool<B, P, V>>>,
|
2018-11-03 09:46:12 +03:00
|
|
|
peers: Arc<p2p::Peers>,
|
2019-09-17 18:12:42 +03:00
|
|
|
sync_state: Arc<chain::SyncState>,
|
2018-11-03 09:46:12 +03:00
|
|
|
api_secret: Option<String>,
|
2019-12-06 13:57:53 +03:00
|
|
|
foreign_api_secret: Option<String>,
|
2018-11-03 09:46:12 +03:00
|
|
|
tls_config: Option<TLSConfig>,
|
2020-04-30 18:41:49 +03:00
|
|
|
) -> Result<(), Error>
|
|
|
|
where
|
|
|
|
B: BlockChain + 'static,
|
|
|
|
P: PoolAdapter + 'static,
|
|
|
|
V: VerifierCache + 'static,
|
|
|
|
{
|
2019-12-06 13:57:53 +03:00
|
|
|
// Manually build router when getting rid of v1
|
|
|
|
//let mut router = Router::new();
|
|
|
|
let mut router = build_router(
|
|
|
|
chain.clone(),
|
|
|
|
tx_pool.clone(),
|
|
|
|
peers.clone(),
|
|
|
|
sync_state.clone(),
|
|
|
|
)
|
|
|
|
.expect("unable to build API router");
|
|
|
|
|
|
|
|
// Add basic auth to v1 API and owner v2 API
|
2019-03-18 21:34:35 +03:00
|
|
|
if let Some(api_secret) = api_secret {
|
2019-12-06 13:57:53 +03:00
|
|
|
let api_basic_auth =
|
|
|
|
"Basic ".to_string() + &to_base64(&("grin:".to_string() + &api_secret));
|
2019-09-12 13:35:18 +03:00
|
|
|
let basic_auth_middleware = Arc::new(BasicAuthMiddleware::new(
|
|
|
|
api_basic_auth,
|
|
|
|
&GRIN_BASIC_REALM,
|
2019-12-06 13:57:53 +03:00
|
|
|
Some("/v2/foreign".into()),
|
2019-09-12 13:35:18 +03:00
|
|
|
));
|
2018-11-03 09:46:12 +03:00
|
|
|
router.add_middleware(basic_auth_middleware);
|
|
|
|
}
|
|
|
|
|
2019-12-06 13:57:53 +03:00
|
|
|
let api_handler_v2 = OwnerAPIHandlerV2::new(
|
|
|
|
Arc::downgrade(&chain),
|
|
|
|
Arc::downgrade(&peers),
|
|
|
|
Arc::downgrade(&sync_state),
|
|
|
|
);
|
|
|
|
router.add_route("/v2/owner", Arc::new(api_handler_v2))?;
|
|
|
|
|
|
|
|
// Add basic auth to v2 foreign API only
|
|
|
|
if let Some(api_secret) = foreign_api_secret {
|
|
|
|
let api_basic_auth =
|
|
|
|
"Basic ".to_string() + &to_base64(&("grin:".to_string() + &api_secret));
|
|
|
|
let basic_auth_middleware = Arc::new(BasicAuthURIMiddleware::new(
|
|
|
|
api_basic_auth,
|
|
|
|
&GRIN_FOREIGN_BASIC_REALM,
|
|
|
|
"/v2/foreign".into(),
|
|
|
|
));
|
|
|
|
router.add_middleware(basic_auth_middleware);
|
|
|
|
}
|
|
|
|
|
|
|
|
let api_handler_v2 = ForeignAPIHandlerV2::new(
|
|
|
|
Arc::downgrade(&chain),
|
|
|
|
Arc::downgrade(&tx_pool),
|
|
|
|
Arc::downgrade(&sync_state),
|
|
|
|
);
|
|
|
|
router.add_route("/v2/foreign", Arc::new(api_handler_v2))?;
|
|
|
|
|
|
|
|
let mut apis = ApiServer::new();
|
|
|
|
warn!("Starting HTTP Node APIs server at {}.", addr);
|
2018-11-03 09:46:12 +03:00
|
|
|
let socket_addr: SocketAddr = addr.parse().expect("unable to parse socket address");
|
2019-12-06 13:57:53 +03:00
|
|
|
let api_thread = apis.start(socket_addr, router, tls_config);
|
|
|
|
|
|
|
|
warn!("HTTP Node listener started.");
|
|
|
|
|
|
|
|
match api_thread {
|
|
|
|
Ok(_) => Ok(()),
|
2019-01-07 22:42:11 +03:00
|
|
|
Err(e) => {
|
|
|
|
error!("HTTP API server failed to start. Err: {}", e);
|
2019-12-06 13:57:53 +03:00
|
|
|
Err(e)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// V2 API Handler/Wrapper for owner functions
|
|
|
|
pub struct OwnerAPIHandlerV2 {
|
|
|
|
pub chain: Weak<Chain>,
|
|
|
|
pub peers: Weak<p2p::Peers>,
|
|
|
|
pub sync_state: Weak<SyncState>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl OwnerAPIHandlerV2 {
|
|
|
|
/// Create a new owner API handler for GET methods
|
|
|
|
pub fn new(chain: Weak<Chain>, peers: Weak<p2p::Peers>, sync_state: Weak<SyncState>) -> Self {
|
|
|
|
OwnerAPIHandlerV2 {
|
|
|
|
chain,
|
|
|
|
peers,
|
|
|
|
sync_state,
|
|
|
|
}
|
|
|
|
}
|
2020-02-19 01:45:27 +03:00
|
|
|
}
|
2019-12-06 13:57:53 +03:00
|
|
|
|
2020-02-19 01:45:27 +03:00
|
|
|
impl crate::router::Handler for OwnerAPIHandlerV2 {
|
|
|
|
fn post(&self, req: Request<Body>) -> ResponseFuture {
|
2019-12-06 13:57:53 +03:00
|
|
|
let api = Owner::new(
|
|
|
|
self.chain.clone(),
|
|
|
|
self.peers.clone(),
|
|
|
|
self.sync_state.clone(),
|
|
|
|
);
|
|
|
|
|
2020-02-19 01:45:27 +03:00
|
|
|
Box::pin(async move {
|
|
|
|
match parse_body(req).await {
|
|
|
|
Ok(val) => {
|
|
|
|
let owner_api = &api as &dyn OwnerRpc;
|
|
|
|
let res = match owner_api.handle_request(val) {
|
|
|
|
MaybeReply::Reply(r) => r,
|
|
|
|
MaybeReply::DontReply => {
|
|
|
|
// Since it's http, we need to return something. We return [] because jsonrpc
|
|
|
|
// clients will parse it as an empty batch response.
|
|
|
|
serde_json::json!([])
|
|
|
|
}
|
|
|
|
};
|
|
|
|
Ok(json_response_pretty(&res))
|
|
|
|
}
|
|
|
|
Err(e) => {
|
|
|
|
error!("Request Error: {:?}", e);
|
|
|
|
Ok(create_error_response(e))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2019-12-06 13:57:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
fn options(&self, _req: Request<Body>) -> ResponseFuture {
|
2020-02-19 01:45:27 +03:00
|
|
|
Box::pin(async { Ok(create_ok_response("{}")) })
|
2019-12-06 13:57:53 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// V2 API Handler/Wrapper for foreign functions
|
2020-04-30 18:41:49 +03:00
|
|
|
pub struct ForeignAPIHandlerV2<B, P, V>
|
|
|
|
where
|
|
|
|
B: BlockChain,
|
|
|
|
P: PoolAdapter,
|
|
|
|
V: VerifierCache + 'static,
|
|
|
|
{
|
2019-12-06 13:57:53 +03:00
|
|
|
pub chain: Weak<Chain>,
|
2020-04-30 18:41:49 +03:00
|
|
|
pub tx_pool: Weak<RwLock<pool::TransactionPool<B, P, V>>>,
|
2019-12-06 13:57:53 +03:00
|
|
|
pub sync_state: Weak<SyncState>,
|
|
|
|
}
|
|
|
|
|
2020-04-30 18:41:49 +03:00
|
|
|
impl<B, P, V> ForeignAPIHandlerV2<B, P, V>
|
|
|
|
where
|
|
|
|
B: BlockChain,
|
|
|
|
P: PoolAdapter,
|
|
|
|
V: VerifierCache + 'static,
|
|
|
|
{
|
2019-12-06 13:57:53 +03:00
|
|
|
/// Create a new foreign API handler for GET methods
|
|
|
|
pub fn new(
|
|
|
|
chain: Weak<Chain>,
|
2020-04-30 18:41:49 +03:00
|
|
|
tx_pool: Weak<RwLock<pool::TransactionPool<B, P, V>>>,
|
2019-12-06 13:57:53 +03:00
|
|
|
sync_state: Weak<SyncState>,
|
|
|
|
) -> Self {
|
|
|
|
ForeignAPIHandlerV2 {
|
|
|
|
chain,
|
|
|
|
tx_pool,
|
|
|
|
sync_state,
|
2019-01-07 22:42:11 +03:00
|
|
|
}
|
|
|
|
}
|
2020-02-19 01:45:27 +03:00
|
|
|
}
|
2019-12-06 13:57:53 +03:00
|
|
|
|
2020-04-30 18:41:49 +03:00
|
|
|
impl<B, P, V> crate::router::Handler for ForeignAPIHandlerV2<B, P, V>
|
|
|
|
where
|
|
|
|
B: BlockChain + 'static,
|
|
|
|
P: PoolAdapter + 'static,
|
|
|
|
V: VerifierCache + 'static,
|
|
|
|
{
|
2020-02-19 01:45:27 +03:00
|
|
|
fn post(&self, req: Request<Body>) -> ResponseFuture {
|
2019-12-06 13:57:53 +03:00
|
|
|
let api = Foreign::new(
|
|
|
|
self.chain.clone(),
|
|
|
|
self.tx_pool.clone(),
|
|
|
|
self.sync_state.clone(),
|
|
|
|
);
|
|
|
|
|
2020-02-19 01:45:27 +03:00
|
|
|
Box::pin(async move {
|
|
|
|
match parse_body(req).await {
|
|
|
|
Ok(val) => {
|
|
|
|
let foreign_api = &api as &dyn ForeignRpc;
|
|
|
|
let res = match foreign_api.handle_request(val) {
|
|
|
|
MaybeReply::Reply(r) => r,
|
|
|
|
MaybeReply::DontReply => {
|
|
|
|
// Since it's http, we need to return something. We return [] because jsonrpc
|
|
|
|
// clients will parse it as an empty batch response.
|
|
|
|
serde_json::json!([])
|
|
|
|
}
|
|
|
|
};
|
|
|
|
Ok(json_response_pretty(&res))
|
|
|
|
}
|
|
|
|
Err(e) => {
|
|
|
|
error!("Request Error: {:?}", e);
|
|
|
|
Ok(create_error_response(e))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2019-12-06 13:57:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
fn options(&self, _req: Request<Body>) -> ResponseFuture {
|
2020-02-19 01:45:27 +03:00
|
|
|
Box::pin(async { Ok(create_ok_response("{}")) })
|
2019-12-06 13:57:53 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// pretty-printed version of above
|
|
|
|
fn json_response_pretty<T>(s: &T) -> Response<Body>
|
|
|
|
where
|
|
|
|
T: Serialize,
|
|
|
|
{
|
|
|
|
match serde_json::to_string_pretty(s) {
|
|
|
|
Ok(json) => response(StatusCode::OK, json),
|
|
|
|
Err(_) => response(StatusCode::INTERNAL_SERVER_ERROR, ""),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn create_error_response(e: Error) -> Response<Body> {
|
|
|
|
Response::builder()
|
|
|
|
.status(StatusCode::INTERNAL_SERVER_ERROR)
|
|
|
|
.header("access-control-allow-origin", "*")
|
|
|
|
.header(
|
|
|
|
"access-control-allow-headers",
|
|
|
|
"Content-Type, Authorization",
|
|
|
|
)
|
|
|
|
.body(format!("{}", e).into())
|
|
|
|
.unwrap()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn create_ok_response(json: &str) -> Response<Body> {
|
|
|
|
Response::builder()
|
|
|
|
.status(StatusCode::OK)
|
|
|
|
.header("access-control-allow-origin", "*")
|
|
|
|
.header(
|
|
|
|
"access-control-allow-headers",
|
|
|
|
"Content-Type, Authorization",
|
|
|
|
)
|
|
|
|
.header(hyper::header::CONTENT_TYPE, "application/json")
|
|
|
|
.body(json.to_string().into())
|
|
|
|
.unwrap()
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Build a new hyper Response with the status code and body provided.
|
|
|
|
///
|
|
|
|
/// Whenever the status code is `StatusCode::OK` the text parameter should be
|
|
|
|
/// valid JSON as the content type header will be set to `application/json'
|
|
|
|
fn response<T: Into<Body>>(status: StatusCode, text: T) -> Response<Body> {
|
2020-02-19 01:45:27 +03:00
|
|
|
let mut builder = Response::builder();
|
2019-12-06 13:57:53 +03:00
|
|
|
|
|
|
|
builder = builder
|
|
|
|
.status(status)
|
|
|
|
.header("access-control-allow-origin", "*")
|
|
|
|
.header(
|
|
|
|
"access-control-allow-headers",
|
|
|
|
"Content-Type, Authorization",
|
|
|
|
);
|
|
|
|
|
|
|
|
if status == StatusCode::OK {
|
|
|
|
builder = builder.header(hyper::header::CONTENT_TYPE, "application/json");
|
|
|
|
}
|
|
|
|
|
|
|
|
builder.body(text.into()).unwrap()
|
2018-11-03 09:46:12 +03:00
|
|
|
}
|
|
|
|
|
2019-12-06 13:57:53 +03:00
|
|
|
// Legacy V1 router
|
2020-04-28 19:17:34 +03:00
|
|
|
#[deprecated(
|
|
|
|
since = "4.0.0",
|
|
|
|
note = "The V1 Node API will be removed in grin 5.0.0. Please migrate to the V2 API as soon as possible."
|
|
|
|
)]
|
2020-04-30 18:41:49 +03:00
|
|
|
pub fn build_router<B, P, V>(
|
2018-11-03 09:46:12 +03:00
|
|
|
chain: Arc<chain::Chain>,
|
2020-04-30 18:41:49 +03:00
|
|
|
tx_pool: Arc<RwLock<pool::TransactionPool<B, P, V>>>,
|
2018-11-03 09:46:12 +03:00
|
|
|
peers: Arc<p2p::Peers>,
|
2019-09-17 18:12:42 +03:00
|
|
|
sync_state: Arc<chain::SyncState>,
|
2020-04-30 18:41:49 +03:00
|
|
|
) -> Result<Router, RouterError>
|
|
|
|
where
|
|
|
|
B: BlockChain + 'static,
|
|
|
|
P: PoolAdapter + 'static,
|
|
|
|
V: VerifierCache + 'static,
|
|
|
|
{
|
2018-11-03 09:46:12 +03:00
|
|
|
let route_list = vec![
|
|
|
|
"get blocks".to_string(),
|
2019-03-11 06:18:21 +03:00
|
|
|
"get headers".to_string(),
|
2018-11-03 09:46:12 +03:00
|
|
|
"get chain".to_string(),
|
|
|
|
"post chain/compact".to_string(),
|
2019-03-11 06:18:21 +03:00
|
|
|
"get chain/validate".to_string(),
|
2019-09-26 18:44:44 +03:00
|
|
|
"get chain/kernels/xxx?min_height=yyy&max_height=zzz".to_string(),
|
2019-03-11 06:18:21 +03:00
|
|
|
"get chain/outputs/byids?id=xxx,yyy,zzz".to_string(),
|
|
|
|
"get chain/outputs/byheight?start_height=101&end_height=200".to_string(),
|
2018-11-03 09:46:12 +03:00
|
|
|
"get status".to_string(),
|
|
|
|
"get txhashset/roots".to_string(),
|
|
|
|
"get txhashset/lastoutputs?n=10".to_string(),
|
|
|
|
"get txhashset/lastrangeproofs".to_string(),
|
|
|
|
"get txhashset/lastkernels".to_string(),
|
|
|
|
"get txhashset/outputs?start_index=1&max=100".to_string(),
|
2019-03-11 06:18:21 +03:00
|
|
|
"get txhashset/merkleproof?n=1".to_string(),
|
2018-11-03 09:46:12 +03:00
|
|
|
"get pool".to_string(),
|
2019-06-27 11:19:17 +03:00
|
|
|
"post pool/push_tx".to_string(),
|
2018-11-03 09:46:12 +03:00
|
|
|
"post peers/a.b.c.d:p/ban".to_string(),
|
|
|
|
"post peers/a.b.c.d:p/unban".to_string(),
|
|
|
|
"get peers/all".to_string(),
|
|
|
|
"get peers/connected".to_string(),
|
|
|
|
"get peers/a.b.c.d".to_string(),
|
2019-06-27 11:19:17 +03:00
|
|
|
"get version".to_string(),
|
2018-11-03 09:46:12 +03:00
|
|
|
];
|
|
|
|
let index_handler = IndexHandler { list: route_list };
|
|
|
|
|
|
|
|
let output_handler = OutputHandler {
|
|
|
|
chain: Arc::downgrade(&chain),
|
|
|
|
};
|
2019-08-30 12:03:12 +03:00
|
|
|
let kernel_handler = KernelHandler {
|
|
|
|
chain: Arc::downgrade(&chain),
|
|
|
|
};
|
2018-11-03 09:46:12 +03:00
|
|
|
let block_handler = BlockHandler {
|
|
|
|
chain: Arc::downgrade(&chain),
|
|
|
|
};
|
|
|
|
let header_handler = HeaderHandler {
|
|
|
|
chain: Arc::downgrade(&chain),
|
|
|
|
};
|
|
|
|
let chain_tip_handler = ChainHandler {
|
|
|
|
chain: Arc::downgrade(&chain),
|
|
|
|
};
|
|
|
|
let chain_compact_handler = ChainCompactHandler {
|
|
|
|
chain: Arc::downgrade(&chain),
|
|
|
|
};
|
|
|
|
let chain_validation_handler = ChainValidationHandler {
|
|
|
|
chain: Arc::downgrade(&chain),
|
|
|
|
};
|
|
|
|
let status_handler = StatusHandler {
|
|
|
|
chain: Arc::downgrade(&chain),
|
|
|
|
peers: Arc::downgrade(&peers),
|
2019-09-17 18:12:42 +03:00
|
|
|
sync_state: Arc::downgrade(&sync_state),
|
2018-11-03 09:46:12 +03:00
|
|
|
};
|
|
|
|
let txhashset_handler = TxHashSetHandler {
|
|
|
|
chain: Arc::downgrade(&chain),
|
|
|
|
};
|
|
|
|
let pool_info_handler = PoolInfoHandler {
|
|
|
|
tx_pool: Arc::downgrade(&tx_pool),
|
|
|
|
};
|
|
|
|
let pool_push_handler = PoolPushHandler {
|
|
|
|
tx_pool: Arc::downgrade(&tx_pool),
|
|
|
|
};
|
|
|
|
let peers_all_handler = PeersAllHandler {
|
|
|
|
peers: Arc::downgrade(&peers),
|
|
|
|
};
|
|
|
|
let peers_connected_handler = PeersConnectedHandler {
|
|
|
|
peers: Arc::downgrade(&peers),
|
|
|
|
};
|
|
|
|
let peer_handler = PeerHandler {
|
|
|
|
peers: Arc::downgrade(&peers),
|
|
|
|
};
|
2019-06-27 11:19:17 +03:00
|
|
|
let version_handler = VersionHandler {
|
|
|
|
chain: Arc::downgrade(&chain),
|
|
|
|
};
|
2018-11-03 09:46:12 +03:00
|
|
|
|
|
|
|
let mut router = Router::new();
|
|
|
|
|
|
|
|
router.add_route("/v1/", Arc::new(index_handler))?;
|
|
|
|
router.add_route("/v1/blocks/*", Arc::new(block_handler))?;
|
|
|
|
router.add_route("/v1/headers/*", Arc::new(header_handler))?;
|
|
|
|
router.add_route("/v1/chain", Arc::new(chain_tip_handler))?;
|
|
|
|
router.add_route("/v1/chain/outputs/*", Arc::new(output_handler))?;
|
2019-08-30 12:03:12 +03:00
|
|
|
router.add_route("/v1/chain/kernels/*", Arc::new(kernel_handler))?;
|
2018-11-03 09:46:12 +03:00
|
|
|
router.add_route("/v1/chain/compact", Arc::new(chain_compact_handler))?;
|
|
|
|
router.add_route("/v1/chain/validate", Arc::new(chain_validation_handler))?;
|
|
|
|
router.add_route("/v1/txhashset/*", Arc::new(txhashset_handler))?;
|
|
|
|
router.add_route("/v1/status", Arc::new(status_handler))?;
|
|
|
|
router.add_route("/v1/pool", Arc::new(pool_info_handler))?;
|
2019-06-27 11:19:17 +03:00
|
|
|
router.add_route("/v1/pool/push_tx", Arc::new(pool_push_handler))?;
|
2018-11-03 09:46:12 +03:00
|
|
|
router.add_route("/v1/peers/all", Arc::new(peers_all_handler))?;
|
|
|
|
router.add_route("/v1/peers/connected", Arc::new(peers_connected_handler))?;
|
|
|
|
router.add_route("/v1/peers/**", Arc::new(peer_handler))?;
|
2019-06-27 11:19:17 +03:00
|
|
|
router.add_route("/v1/version", Arc::new(version_handler))?;
|
2018-11-03 09:46:12 +03:00
|
|
|
Ok(router)
|
|
|
|
}
|