pub fn start_rest_apis<T>(
	addr: String,
	chain: Arc<chain::Chain>,
	tx_pool: Arc<RwLock<pool::TransactionPool<T>>>,
	peers: p2p::Peers,
) where
	T: pool::BlockChain + Send + Sync + 'static,
{
let _ = thread::Builder::new()
	.name("apis".to_string())
	.spawn(move || {
			// build handlers and register them under the appropriate endpoint
			let utxo_handler = UtxoHandler {
				chain: chain.clone(),
			};
			let block_handler = BlockHandler {
				chain: chain.clone(),
			};
			let chain_tip_handler = ChainHandler {
				chain: chain.clone(),
			};
			let sumtree_handler = SumTreeHandler {
				chain: chain.clone(),
			};
			let pool_info_handler = PoolInfoHandler {
				tx_pool: tx_pool.clone(),
			};
			let pool_push_handler = PoolPushHandler {
				tx_pool: tx_pool.clone(),
			};
			let peers_all_handler = PeersAllHandler {
				peers: peers.clone(),
			};
			let peers_connected_handler = PeersConnectedHandler {
				peers: peers.clone(),
			};
			let peer_handler = PeerHandler {
				peers: peers.clone(),
			};

			let route_list = vec!(
				"get blocks".to_string(),
				"get chain".to_string(),
				"get chain/utxos".to_string(),
				"get sumtrees/roots".to_string(),
				"get sumtrees/lastutxos?n=10".to_string(),
				"get sumtrees/lastrangeproofs".to_string(),
				"get sumtrees/lastkernels".to_string(),
				"get pool".to_string(),
				"post pool/push".to_string(),
				"post peers/a.b.c.d:p/ban".to_string(),
				"get peers/all".to_string(),
				"get peers/connected".to_string(),
			);
			// We allow manually banning, like this:
			// curl -v -X POST http://127.0.0.1:13413/v1/peers/88.99.251.87:13414/ban
			let index_handler = IndexHandler { list: route_list };
			let router = router!(
				index: get "/" => index_handler,
				blocks: get "/blocks/*" => block_handler,
				chain_tip: get "/chain" => chain_tip_handler,
				chain_utxos: get "/chain/utxos/*" => utxo_handler,
				sumtree_roots: get "/sumtrees/*" => sumtree_handler,
				pool_info: get "/pool" => pool_info_handler,
				pool_push: post "/pool/push" => pool_push_handler,
				peers_all: get "/peers/all" => peers_all_handler,
				peers_connected: get "/peers/connected" => peers_connected_handler,
				peer: post "/peers/*" => peer_handler,
			);

			let mut apis = ApiServer::new("/v1".to_string());
			apis.register_handler(router);

			info!(LOGGER, "Starting HTTP API server at {}.", addr);
			apis.start(&addr[..]).unwrap_or_else(|e| {
				error!(LOGGER, "Failed to start API HTTP server: {}.", e);
			});
	});
}
/// Start all server HTTP handlers. Register all of them with Iron
/// and runs the corresponding HTTP server.
Start all server HTTP handlers. Register all of them with Iron
and runs the corresponding HTTP server.
Start all server HTTP handlers . Register all of them with Iron and runs the corresponding HTTP server .
pub fn start_rest_apis<T>(
	addr: String,
	chain: Arc<chain::Chain>,
	tx_pool: Arc<RwLock<pool::TransactionPool<T>>>,
	peers: p2p::Peers,
) where
	T: pool::BlockChain + Send + Sync + 'static,
{
let _ = thread::Builder::new()
	.name("apis".to_string())
	.spawn(move || {
			// build handlers and register them under the appropriate endpoint
			let utxo_handler = UtxoHandler {
				chain: chain.clone(),
			};
			let block_handler = BlockHandler {
				chain: chain.clone(),
			};
			let chain_tip_handler = ChainHandler {
				chain: chain.clone(),
			};
			let sumtree_handler = SumTreeHandler {
				chain: chain.clone(),
			};
			let pool_info_handler = PoolInfoHandler {
				tx_pool: tx_pool.clone(),
			};
			let pool_push_handler = PoolPushHandler {
				tx_pool: tx_pool.clone(),
			};
			let peers_all_handler = PeersAllHandler {
				peers: peers.clone(),
			};
			let peers_connected_handler = PeersConnectedHandler {
				peers: peers.clone(),
			};
			let peer_handler = PeerHandler {
				peers: peers.clone(),
			};
			let route_list = vec!(
				"get blocks".to_string(),
				"get chain".to_string(),
				"get chain/utxos".to_string(),
				"get sumtrees/roots".to_string(),
				"get sumtrees/lastutxos?n=10".to_string(),
				"get sumtrees/lastrangeproofs".to_string(),
				"get sumtrees/lastkernels".to_string(),
				"get pool".to_string(),
				"post pool/push".to_string(),
				"post peers/a.b.c.d:p/ban".to_string(),
				"get peers/all".to_string(),
				"get peers/connected".to_string(),
			);
			// We allow manually banning, like this:
			// curl -v -X POST http://127.0.0.1:13413/v1/peers/88.99.251.87:13414/ban
			let index_handler = IndexHandler { list: route_list };
			let router = router!(
				index: get "/" => index_handler,
				blocks: get "/blocks/*" => block_handler,
				chain_tip: get "/chain" => chain_tip_handler,
				chain_utxos: get "/chain/utxos/*" => utxo_handler,
				sumtree_roots: get "/sumtrees/*" => sumtree_handler,
				pool_info: get "/pool" => pool_info_handler,
				pool_push: post "/pool/push" => pool_push_handler,
				peers_all: get "/peers/all" => peers_all_handler,
				peers_connected: get "/peers/connected" => peers_connected_handler,
				peer: post "/peers/*" => peer_handler,
			);
			let mut apis = ApiServer::new("/v1".to_string());
			apis.register_handler(router);
			info!(LOGGER, "Starting HTTP API server at {}.", addr);
			apis.start(&addr[..]).unwrap_or_else(|e| {
				error!(LOGGER, "Failed to start API HTTP server: {}.", e);
			});
	});
}
pub fn start_rest_apis < T > ( addr : String , chain : Arc < chain :: Chain > , tx_pool : Arc < RwLock < pool :: TransactionPool < T > > > , peers : p2p :: Peers , ) where T : pool :: BlockChain + Send + Sync + ' static , { let _ = thread :: Builder :: new ( ) . name ( " " . to_string ( ) ) . spawn ( move | | { // build handlers and register them under the appropriate endpoint let utxo_handler = UtxoHandler { chain : chain . clone ( ) , } ; let block_handler = BlockHandler { chain : chain . clone ( ) , } ; let chain_tip_handler = ChainHandler { chain : chain . clone ( ) , } ; let sumtree_handler = SumTreeHandler { chain : chain . clone ( ) , } ; let pool_info_handler = PoolInfoHandler { tx_pool : tx_pool . clone ( ) , } ; let pool_push_handler = PoolPushHandler { tx_pool : tx_pool . clone ( ) , } ; let peers_all_handler = PeersAllHandler { peers : peers . clone ( ) , } ; let peers_connected_handler = PeersConnectedHandler { peers : peers . clone ( ) , } ; let peer_handler = PeerHandler { peers : peers . clone ( ) , } ; let route_list = vec ! ( " " to_string ( ) " " to_string ( ) " " to_string ( ) " " to_string ( ) " " to_string ( ) " " to_string ( ) " " to_string ( ) " " to_string ( ) " " to_string ( ) " " to_string ( ) " " to_string ( ) " " to_string ( ) ) ; // We allow manually banning, like this: // curl -v -X POST http://127.0.0.1:13413/v1/peers/88.99.251.87:13414/ban let index_handler = IndexHandler { list : route_list } ; let router = router ! ( index get " " index_handler blocks get " " block_handler chain_tip get " " chain_tip_handler chain_utxos get " " utxo_handler sumtree_roots get " " sumtree_handler pool_info get " " pool_info_handler pool_push post " " pool_push_handler peers_all get " " peers_all_handler peers_connected get " " peers_connected_handler peer post " " peer_handler ) ; let mut apis = ApiServer :: new ( " " . to_string ( ) ) ; apis . register_handler ( router ) ; info ! ( LOGGER " " addr ) ; apis . start ( & addr [ .. ] ) . unwrap_or_else ( | e | { error ! ( LOGGER " " e ) ; } ) ; } ) ; }
Start all server HTTP handlers.
Start all server HTTP handlers .
addr
String
chain
Arc<chain::Chain>
tx_pool
Arc<RwLock<pool::TransactionPool<T>>>
peers
p2p::Peers