From 1fdc41e17c74b6727e2bc22b842107179da1db09 Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Thu, 23 Dec 2021 15:01:36 +0100 Subject: [PATCH] Box all warp filters --- .../routes/api/plugins/debug/white_flag.rs | 5 +- .../src/endpoints/routes/api/v1/add_peer.rs | 5 +- .../endpoints/routes/api/v1/balance_bech32.rs | 5 +- .../routes/api/v1/balance_ed25519.rs | 5 +- .../src/endpoints/routes/api/v1/info.rs | 5 +- .../src/endpoints/routes/api/v1/message.rs | 5 +- .../routes/api/v1/message_children.rs | 5 +- .../routes/api/v1/message_metadata.rs | 5 +- .../endpoints/routes/api/v1/message_raw.rs | 5 +- .../endpoints/routes/api/v1/messages_find.rs | 5 +- .../src/endpoints/routes/api/v1/milestone.rs | 5 +- .../routes/api/v1/milestone_utxo_changes.rs | 5 +- .../src/endpoints/routes/api/v1/output.rs | 5 +- .../endpoints/routes/api/v1/outputs_bech32.rs | 5 +- .../routes/api/v1/outputs_ed25519.rs | 5 +- .../src/endpoints/routes/api/v1/peer.rs | 5 +- .../src/endpoints/routes/api/v1/peers.rs | 5 +- .../src/endpoints/routes/api/v1/receipts.rs | 5 +- .../endpoints/routes/api/v1/receipts_at.rs | 5 +- .../endpoints/routes/api/v1/remove_peer.rs | 5 +- .../endpoints/routes/api/v1/submit_message.rs | 49 ++++++++++--------- .../src/endpoints/routes/api/v1/tips.rs | 5 +- .../api/v1/transaction_included_message.rs | 5 +- .../src/endpoints/routes/api/v1/treasury.rs | 5 +- .../src/endpoints/routes/health.rs | 5 +- 25 files changed, 98 insertions(+), 71 deletions(-) diff --git a/bee-api/bee-rest-api/src/endpoints/routes/api/plugins/debug/white_flag.rs b/bee-api/bee-rest-api/src/endpoints/routes/api/plugins/debug/white_flag.rs index ead5d71abb..d5a3d8b6db 100644 --- a/bee-api/bee-rest-api/src/endpoints/routes/api/plugins/debug/white_flag.rs +++ b/bee-api/bee-rest-api/src/endpoints/routes/api/plugins/debug/white_flag.rs @@ -23,7 +23,7 @@ use bee_tangle::Tangle; use futures::channel::oneshot; use serde_json::Value as JsonValue; use tokio::time::timeout; -use warp::{reject, Filter, Rejection, Reply}; +use warp::{filters::BoxedFilter, reject, Filter, Rejection, Reply}; use std::{ any::TypeId, @@ -47,7 +47,7 @@ pub(crate) fn filter( message_requester: MessageRequesterWorker, requested_messages: ResourceHandle, rest_api_config: RestApiConfig, -) -> impl Filter + Clone { +) -> BoxedFilter<(impl Reply,)> { self::path() .and(warp::post()) .and(has_permission(ROUTE_WHITE_FLAG, public_routes, allowed_ips)) @@ -59,6 +59,7 @@ pub(crate) fn filter( .and(with_requested_messages(requested_messages)) .and(with_rest_api_config(rest_api_config)) .and_then(white_flag) + .boxed() } pub(crate) async fn white_flag( diff --git a/bee-api/bee-rest-api/src/endpoints/routes/api/v1/add_peer.rs b/bee-api/bee-rest-api/src/endpoints/routes/api/v1/add_peer.rs index d1645654aa..23210abd26 100644 --- a/bee-api/bee-rest-api/src/endpoints/routes/api/v1/add_peer.rs +++ b/bee-api/bee-rest-api/src/endpoints/routes/api/v1/add_peer.rs @@ -20,7 +20,7 @@ use bee_protocol::workers::PeerManager; use bee_runtime::resource::ResourceHandle; use serde_json::Value as JsonValue; -use warp::{http::StatusCode, reject, Filter, Rejection, Reply}; +use warp::{filters::BoxedFilter, http::StatusCode, reject, Filter, Rejection, Reply}; use std::net::IpAddr; @@ -33,7 +33,7 @@ pub(crate) fn filter( allowed_ips: Box<[IpAddr]>, peer_manager: ResourceHandle, network_command_sender: ResourceHandle, -) -> impl Filter + Clone { +) -> BoxedFilter<(impl Reply,)> { self::path() .and(warp::post()) .and(has_permission(ROUTE_ADD_PEER, public_routes, allowed_ips)) @@ -41,6 +41,7 @@ pub(crate) fn filter( .and(with_peer_manager(peer_manager)) .and(with_network_command_sender(network_command_sender)) .and_then(add_peer) + .boxed() } pub(crate) async fn add_peer( diff --git a/bee-api/bee-rest-api/src/endpoints/routes/api/v1/balance_bech32.rs b/bee-api/bee-rest-api/src/endpoints/routes/api/v1/balance_bech32.rs index 2cfe0f8c29..b0f575fb1a 100644 --- a/bee-api/bee-rest-api/src/endpoints/routes/api/v1/balance_bech32.rs +++ b/bee-api/bee-rest-api/src/endpoints/routes/api/v1/balance_bech32.rs @@ -10,7 +10,7 @@ use bee_ledger::workers::consensus::ConsensusWorkerCommand; use bee_message::address::Address; use tokio::sync::mpsc; -use warp::{Filter, Rejection, Reply}; +use warp::{filters::BoxedFilter, Filter, Rejection, Reply}; use std::net::IpAddr; @@ -25,12 +25,13 @@ pub(crate) fn filter( public_routes: Box<[String]>, allowed_ips: Box<[IpAddr]>, consensus_worker: mpsc::UnboundedSender, -) -> impl Filter + Clone { +) -> BoxedFilter<(impl Reply,)> { self::path() .and(warp::get()) .and(has_permission(ROUTE_BALANCE_BECH32, public_routes, allowed_ips)) .and(with_consensus_worker(consensus_worker)) .and_then(|addr, consensus_worker| async move { balance_bech32(addr, consensus_worker).await }) + .boxed() } pub(crate) async fn balance_bech32( diff --git a/bee-api/bee-rest-api/src/endpoints/routes/api/v1/balance_ed25519.rs b/bee-api/bee-rest-api/src/endpoints/routes/api/v1/balance_ed25519.rs index fe5d33e08e..98430365ba 100644 --- a/bee-api/bee-rest-api/src/endpoints/routes/api/v1/balance_ed25519.rs +++ b/bee-api/bee-rest-api/src/endpoints/routes/api/v1/balance_ed25519.rs @@ -18,7 +18,7 @@ use bee_message::address::{Address, Ed25519Address}; use futures::channel::oneshot; use log::error; use tokio::sync::mpsc; -use warp::{reject, Filter, Rejection, Reply}; +use warp::{filters::BoxedFilter, reject, Filter, Rejection, Reply}; use std::net::IpAddr; @@ -34,12 +34,13 @@ pub(crate) fn filter( public_routes: Box<[String]>, allowed_ips: Box<[IpAddr]>, consensus_worker: mpsc::UnboundedSender, -) -> impl Filter + Clone { +) -> BoxedFilter<(impl Reply,)> { self::path() .and(warp::get()) .and(has_permission(ROUTE_BALANCE_ED25519, public_routes, allowed_ips)) .and(with_consensus_worker(consensus_worker)) .and_then(|addr, consensus_worker| async move { balance_ed25519(addr, consensus_worker).await }) + .boxed() } pub(crate) async fn balance_ed25519( diff --git a/bee-api/bee-rest-api/src/endpoints/routes/api/v1/info.rs b/bee-api/bee-rest-api/src/endpoints/routes/api/v1/info.rs index 817c335255..0981d73bbd 100644 --- a/bee-api/bee-rest-api/src/endpoints/routes/api/v1/info.rs +++ b/bee-api/bee-rest-api/src/endpoints/routes/api/v1/info.rs @@ -20,7 +20,7 @@ use bee_protocol::workers::{config::ProtocolConfig, PeerManager}; use bee_runtime::{node::NodeInfo, resource::ResourceHandle}; use bee_tangle::Tangle; -use warp::{Filter, Rejection, Reply}; +use warp::{filters::BoxedFilter, Filter, Reply}; use std::{convert::Infallible, net::IpAddr}; @@ -39,7 +39,7 @@ pub(crate) fn filter( protocol_config: ProtocolConfig, node_info: ResourceHandle, peer_manager: ResourceHandle, -) -> impl Filter + Clone { +) -> BoxedFilter<(impl Reply,)> { self::path() .and(warp::get()) .and(has_permission(ROUTE_INFO, public_routes, allowed_ips)) @@ -51,6 +51,7 @@ pub(crate) fn filter( .and(with_node_info(node_info)) .and(with_peer_manager(peer_manager)) .and_then(info) + .boxed() } pub(crate) async fn info( diff --git a/bee-api/bee-rest-api/src/endpoints/routes/api/v1/message.rs b/bee-api/bee-rest-api/src/endpoints/routes/api/v1/message.rs index 25b9fb1388..0563037588 100644 --- a/bee-api/bee-rest-api/src/endpoints/routes/api/v1/message.rs +++ b/bee-api/bee-rest-api/src/endpoints/routes/api/v1/message.rs @@ -13,7 +13,7 @@ use bee_message::MessageId; use bee_runtime::resource::ResourceHandle; use bee_tangle::Tangle; -use warp::{reject, Filter, Rejection, Reply}; +use warp::{filters::BoxedFilter, reject, Filter, Rejection, Reply}; use std::net::IpAddr; @@ -28,12 +28,13 @@ pub(crate) fn filter( public_routes: Box<[String]>, allowed_ips: Box<[IpAddr]>, tangle: ResourceHandle>, -) -> impl Filter + Clone { +) -> BoxedFilter<(impl Reply,)> { self::path() .and(warp::get()) .and(has_permission(ROUTE_MESSAGE, public_routes, allowed_ips)) .and(with_tangle(tangle)) .and_then(message) + .boxed() } pub(crate) async fn message( diff --git a/bee-api/bee-rest-api/src/endpoints/routes/api/v1/message_children.rs b/bee-api/bee-rest-api/src/endpoints/routes/api/v1/message_children.rs index 63f964bde6..7b17ea07c4 100644 --- a/bee-api/bee-rest-api/src/endpoints/routes/api/v1/message_children.rs +++ b/bee-api/bee-rest-api/src/endpoints/routes/api/v1/message_children.rs @@ -13,7 +13,7 @@ use bee_message::MessageId; use bee_runtime::resource::ResourceHandle; use bee_tangle::Tangle; -use warp::{Filter, Rejection, Reply}; +use warp::{filters::BoxedFilter, Filter, Rejection, Reply}; use std::net::IpAddr; @@ -29,12 +29,13 @@ pub(crate) fn filter( public_routes: Box<[String]>, allowed_ips: Box<[IpAddr]>, tangle: ResourceHandle>, -) -> impl Filter + Clone { +) -> BoxedFilter<(impl Reply,)> { self::path() .and(warp::get()) .and(has_permission(ROUTE_MESSAGE_CHILDREN, public_routes, allowed_ips)) .and(with_tangle(tangle)) .and_then(message_children) + .boxed() } pub async fn message_children( diff --git a/bee-api/bee-rest-api/src/endpoints/routes/api/v1/message_metadata.rs b/bee-api/bee-rest-api/src/endpoints/routes/api/v1/message_metadata.rs index 6648705b7e..012a315e48 100644 --- a/bee-api/bee-rest-api/src/endpoints/routes/api/v1/message_metadata.rs +++ b/bee-api/bee-rest-api/src/endpoints/routes/api/v1/message_metadata.rs @@ -13,7 +13,7 @@ use bee_message::{payload::Payload, MessageId}; use bee_runtime::resource::ResourceHandle; use bee_tangle::{ConflictReason, Tangle}; -use warp::{reject, Filter, Rejection, Reply}; +use warp::{filters::BoxedFilter, reject, Filter, Rejection, Reply}; use std::net::IpAddr; @@ -29,12 +29,13 @@ pub(crate) fn filter( public_routes: Box<[String]>, allowed_ips: Box<[IpAddr]>, tangle: ResourceHandle>, -) -> impl Filter + Clone { +) -> BoxedFilter<(impl Reply,)> { self::path() .and(warp::get()) .and(has_permission(ROUTE_MESSAGE_METADATA, public_routes, allowed_ips)) .and(with_tangle(tangle)) .and_then(message_metadata) + .boxed() } pub(crate) async fn message_metadata( diff --git a/bee-api/bee-rest-api/src/endpoints/routes/api/v1/message_raw.rs b/bee-api/bee-rest-api/src/endpoints/routes/api/v1/message_raw.rs index c3ab113f0c..f7c1fda757 100644 --- a/bee-api/bee-rest-api/src/endpoints/routes/api/v1/message_raw.rs +++ b/bee-api/bee-rest-api/src/endpoints/routes/api/v1/message_raw.rs @@ -11,7 +11,7 @@ use bee_message::MessageId; use bee_runtime::resource::ResourceHandle; use bee_tangle::Tangle; -use warp::{http::Response, reject, Filter, Rejection, Reply}; +use warp::{filters::BoxedFilter, http::Response, reject, Filter, Rejection, Reply}; use std::net::IpAddr; @@ -27,12 +27,13 @@ pub(crate) fn filter( public_routes: Box<[String]>, allowed_ips: Box<[IpAddr]>, tangle: ResourceHandle>, -) -> impl Filter + Clone { +) -> BoxedFilter<(impl Reply,)> { self::path() .and(warp::get()) .and(has_permission(ROUTE_MESSAGE_RAW, public_routes, allowed_ips)) .and(with_tangle(tangle)) .and_then(message_raw) + .boxed() } pub async fn message_raw( diff --git a/bee-api/bee-rest-api/src/endpoints/routes/api/v1/messages_find.rs b/bee-api/bee-rest-api/src/endpoints/routes/api/v1/messages_find.rs index 412bfc15ad..e69c53ebec 100644 --- a/bee-api/bee-rest-api/src/endpoints/routes/api/v1/messages_find.rs +++ b/bee-api/bee-rest-api/src/endpoints/routes/api/v1/messages_find.rs @@ -16,7 +16,7 @@ use bee_message::{ use bee_runtime::resource::ResourceHandle; use bee_storage::access::Fetch; -use warp::{reject, Filter, Rejection, Reply}; +use warp::{filters::BoxedFilter, reject, Filter, Rejection, Reply}; use std::{collections::HashMap, net::IpAddr}; @@ -28,7 +28,7 @@ pub(crate) fn filter( public_routes: Box<[String]>, allowed_ips: Box<[IpAddr]>, storage: ResourceHandle, -) -> impl Filter + Clone { +) -> BoxedFilter<(impl Reply,)> { self::path() .and(warp::get()) .and(has_permission(ROUTE_MESSAGES_FIND, public_routes, allowed_ips)) @@ -42,6 +42,7 @@ pub(crate) fn filter( })) .and(with_storage(storage)) .and_then(|index, storage| async move { messages_find(index, storage) }) + .boxed() } pub(crate) fn messages_find( diff --git a/bee-api/bee-rest-api/src/endpoints/routes/api/v1/milestone.rs b/bee-api/bee-rest-api/src/endpoints/routes/api/v1/milestone.rs index 7ed1bedc4b..436ae91731 100644 --- a/bee-api/bee-rest-api/src/endpoints/routes/api/v1/milestone.rs +++ b/bee-api/bee-rest-api/src/endpoints/routes/api/v1/milestone.rs @@ -13,7 +13,7 @@ use bee_message::milestone::MilestoneIndex; use bee_runtime::resource::ResourceHandle; use bee_tangle::Tangle; -use warp::{reject, Filter, Rejection, Reply}; +use warp::{filters::BoxedFilter, reject, Filter, Rejection, Reply}; use std::net::IpAddr; @@ -28,12 +28,13 @@ pub(crate) fn filter( public_routes: Box<[String]>, allowed_ips: Box<[IpAddr]>, tangle: ResourceHandle>, -) -> impl Filter + Clone { +) -> BoxedFilter<(impl Reply,)> { self::path() .and(warp::get()) .and(has_permission(ROUTE_MILESTONE, public_routes, allowed_ips)) .and(with_tangle(tangle)) .and_then(milestone) + .boxed() } pub(crate) async fn milestone( diff --git a/bee-api/bee-rest-api/src/endpoints/routes/api/v1/milestone_utxo_changes.rs b/bee-api/bee-rest-api/src/endpoints/routes/api/v1/milestone_utxo_changes.rs index b3fbc3f1b5..4ee1736a72 100644 --- a/bee-api/bee-rest-api/src/endpoints/routes/api/v1/milestone_utxo_changes.rs +++ b/bee-api/bee-rest-api/src/endpoints/routes/api/v1/milestone_utxo_changes.rs @@ -14,7 +14,7 @@ use bee_message::milestone::MilestoneIndex; use bee_runtime::resource::ResourceHandle; use bee_storage::access::Fetch; -use warp::{reject, Filter, Rejection, Reply}; +use warp::{filters::BoxedFilter, reject, Filter, Rejection, Reply}; use std::net::IpAddr; @@ -30,12 +30,13 @@ pub(crate) fn filter( public_routes: Box<[String]>, allowed_ips: Box<[IpAddr]>, storage: ResourceHandle, -) -> impl Filter + Clone { +) -> BoxedFilter<(impl Reply,)> { self::path() .and(warp::get()) .and(has_permission(ROUTE_MILESTONE_UTXO_CHANGES, public_routes, allowed_ips)) .and(with_storage(storage)) .and_then(|index, storage| async move { milestone_utxo_changes(index, storage) }) + .boxed() } pub(crate) fn milestone_utxo_changes( diff --git a/bee-api/bee-rest-api/src/endpoints/routes/api/v1/output.rs b/bee-api/bee-rest-api/src/endpoints/routes/api/v1/output.rs index 01d9b99f6e..917d463656 100644 --- a/bee-api/bee-rest-api/src/endpoints/routes/api/v1/output.rs +++ b/bee-api/bee-rest-api/src/endpoints/routes/api/v1/output.rs @@ -24,7 +24,7 @@ use bee_storage::access::Fetch; use futures::channel::oneshot; use log::error; use tokio::sync::mpsc; -use warp::{reject, Filter, Rejection, Reply}; +use warp::{filters::BoxedFilter, reject, Filter, Rejection, Reply}; use std::net::IpAddr; @@ -40,7 +40,7 @@ pub(crate) fn filter( allowed_ips: Box<[IpAddr]>, storage: ResourceHandle, consensus_worker: mpsc::UnboundedSender, -) -> impl Filter + Clone { +) -> BoxedFilter<(impl Reply,)> { self::path() .and(warp::get()) .and(has_permission(ROUTE_OUTPUT, public_routes, allowed_ips)) @@ -49,6 +49,7 @@ pub(crate) fn filter( .and_then( |output_id, storage, consensus_worker| async move { output(output_id, storage, consensus_worker).await }, ) + .boxed() } pub(crate) async fn output( diff --git a/bee-api/bee-rest-api/src/endpoints/routes/api/v1/outputs_bech32.rs b/bee-api/bee-rest-api/src/endpoints/routes/api/v1/outputs_bech32.rs index 265cf3f620..fdd113a8e9 100644 --- a/bee-api/bee-rest-api/src/endpoints/routes/api/v1/outputs_bech32.rs +++ b/bee-api/bee-rest-api/src/endpoints/routes/api/v1/outputs_bech32.rs @@ -10,7 +10,7 @@ use bee_ledger::workers::consensus::ConsensusWorkerCommand; use bee_message::address::Address; use tokio::sync::mpsc; -use warp::{Filter, Rejection, Reply}; +use warp::{filters::BoxedFilter, Filter, Rejection, Reply}; use std::net::IpAddr; @@ -26,12 +26,13 @@ pub(crate) fn filter( public_routes: Box<[String]>, allowed_ips: Box<[IpAddr]>, consensus_worker: mpsc::UnboundedSender, -) -> impl Filter + Clone { +) -> BoxedFilter<(impl Reply,)> { self::path() .and(warp::get()) .and(has_permission(ROUTE_OUTPUTS_BECH32, public_routes, allowed_ips)) .and(with_consensus_worker(consensus_worker)) .and_then(|addr, consensus_worker| async move { outputs_bech32(addr, consensus_worker).await }) + .boxed() } pub(crate) async fn outputs_bech32( diff --git a/bee-api/bee-rest-api/src/endpoints/routes/api/v1/outputs_ed25519.rs b/bee-api/bee-rest-api/src/endpoints/routes/api/v1/outputs_ed25519.rs index ffd54506bd..7a26f3a00a 100644 --- a/bee-api/bee-rest-api/src/endpoints/routes/api/v1/outputs_ed25519.rs +++ b/bee-api/bee-rest-api/src/endpoints/routes/api/v1/outputs_ed25519.rs @@ -18,7 +18,7 @@ use bee_message::{address::Ed25519Address, output::OutputId, prelude::Address}; use futures::channel::oneshot; use log::error; use tokio::sync::mpsc; -use warp::{reject, Filter, Rejection, Reply}; +use warp::{filters::BoxedFilter, reject, Filter, Rejection, Reply}; use std::net::IpAddr; @@ -35,12 +35,13 @@ pub(crate) fn filter( public_routes: Box<[String]>, allowed_ips: Box<[IpAddr]>, consensus_worker: mpsc::UnboundedSender, -) -> impl Filter + Clone { +) -> BoxedFilter<(impl Reply,)> { self::path() .and(warp::get()) .and(has_permission(ROUTE_OUTPUTS_ED25519, public_routes, allowed_ips)) .and(with_consensus_worker(consensus_worker)) .and_then(|addr, consensus_worker| async move { outputs_ed25519(addr, consensus_worker).await }) + .boxed() } pub(crate) async fn outputs_ed25519( diff --git a/bee-api/bee-rest-api/src/endpoints/routes/api/v1/peer.rs b/bee-api/bee-rest-api/src/endpoints/routes/api/v1/peer.rs index de022ff271..cfc3f6d5a5 100644 --- a/bee-api/bee-rest-api/src/endpoints/routes/api/v1/peer.rs +++ b/bee-api/bee-rest-api/src/endpoints/routes/api/v1/peer.rs @@ -13,7 +13,7 @@ use bee_network::PeerId; use bee_protocol::workers::PeerManager; use bee_runtime::resource::ResourceHandle; -use warp::{reject, Filter, Rejection, Reply}; +use warp::{filters::BoxedFilter, reject, Filter, Rejection, Reply}; use std::net::IpAddr; @@ -28,12 +28,13 @@ pub(crate) fn filter( public_routes: Box<[String]>, allowed_ips: Box<[IpAddr]>, peer_manager: ResourceHandle, -) -> impl Filter + Clone { +) -> BoxedFilter<(impl Reply,)> { self::path() .and(warp::get()) .and(has_permission(ROUTE_PEER, public_routes, allowed_ips)) .and(with_peer_manager(peer_manager)) .and_then(peer) + .boxed() } pub(crate) async fn peer(peer_id: PeerId, peer_manager: ResourceHandle) -> Result { diff --git a/bee-api/bee-rest-api/src/endpoints/routes/api/v1/peers.rs b/bee-api/bee-rest-api/src/endpoints/routes/api/v1/peers.rs index 94322a4270..f493e82138 100644 --- a/bee-api/bee-rest-api/src/endpoints/routes/api/v1/peers.rs +++ b/bee-api/bee-rest-api/src/endpoints/routes/api/v1/peers.rs @@ -9,7 +9,7 @@ use crate::{ use bee_protocol::workers::PeerManager; use bee_runtime::resource::ResourceHandle; -use warp::{Filter, Rejection, Reply}; +use warp::{filters::BoxedFilter, Filter, Rejection, Reply}; use std::{convert::Infallible, net::IpAddr}; @@ -21,12 +21,13 @@ pub(crate) fn filter( public_routes: Box<[String]>, allowed_ips: Box<[IpAddr]>, peer_manager: ResourceHandle, -) -> impl Filter + Clone { +) -> BoxedFilter<(impl Reply,)> { self::path() .and(warp::get()) .and(has_permission(ROUTE_PEERS, public_routes, allowed_ips)) .and(with_peer_manager(peer_manager)) .and_then(peers) + .boxed() } pub(crate) async fn peers(peer_manager: ResourceHandle) -> Result { diff --git a/bee-api/bee-rest-api/src/endpoints/routes/api/v1/receipts.rs b/bee-api/bee-rest-api/src/endpoints/routes/api/v1/receipts.rs index 6727e9f447..11c2436ab1 100644 --- a/bee-api/bee-rest-api/src/endpoints/routes/api/v1/receipts.rs +++ b/bee-api/bee-rest-api/src/endpoints/routes/api/v1/receipts.rs @@ -14,7 +14,7 @@ use bee_message::milestone::MilestoneIndex; use bee_runtime::resource::ResourceHandle; use bee_storage::access::AsIterator; -use warp::{Filter, Rejection, Reply}; +use warp::{filters::BoxedFilter, Filter, Rejection, Reply}; use std::net::IpAddr; @@ -26,12 +26,13 @@ pub(crate) fn filter( public_routes: Box<[String]>, allowed_ips: Box<[IpAddr]>, storage: ResourceHandle, -) -> impl Filter + Clone { +) -> BoxedFilter<(impl Reply,)> { self::path() .and(warp::get()) .and(has_permission(ROUTE_RECEIPTS, public_routes, allowed_ips)) .and(with_storage(storage)) .and_then(|storage| async move { receipts(storage) }) + .boxed() } pub(crate) fn receipts(storage: ResourceHandle) -> Result { diff --git a/bee-api/bee-rest-api/src/endpoints/routes/api/v1/receipts_at.rs b/bee-api/bee-rest-api/src/endpoints/routes/api/v1/receipts_at.rs index 11a6e8ea79..52b4c76988 100644 --- a/bee-api/bee-rest-api/src/endpoints/routes/api/v1/receipts_at.rs +++ b/bee-api/bee-rest-api/src/endpoints/routes/api/v1/receipts_at.rs @@ -14,7 +14,7 @@ use bee_message::milestone::MilestoneIndex; use bee_runtime::resource::ResourceHandle; use bee_storage::access::Fetch; -use warp::{Filter, Rejection, Reply}; +use warp::{filters::BoxedFilter, Filter, Rejection, Reply}; use std::net::IpAddr; @@ -29,12 +29,13 @@ pub(crate) fn filter( public_routes: Box<[String]>, allowed_ips: Box<[IpAddr]>, storage: ResourceHandle, -) -> impl Filter + Clone { +) -> BoxedFilter<(impl Reply,)> { self::path() .and(warp::get()) .and(has_permission(ROUTE_RECEIPTS_AT, public_routes, allowed_ips)) .and(with_storage(storage)) .and_then(|milestone_index, storage| async move { receipts_at(milestone_index, storage) }) + .boxed() } pub(crate) fn receipts_at( diff --git a/bee-api/bee-rest-api/src/endpoints/routes/api/v1/remove_peer.rs b/bee-api/bee-rest-api/src/endpoints/routes/api/v1/remove_peer.rs index 826113eef9..0b8c077821 100644 --- a/bee-api/bee-rest-api/src/endpoints/routes/api/v1/remove_peer.rs +++ b/bee-api/bee-rest-api/src/endpoints/routes/api/v1/remove_peer.rs @@ -9,7 +9,7 @@ use crate::endpoints::{ use bee_network::{Command::RemovePeer, NetworkCommandSender, PeerId}; use bee_runtime::resource::ResourceHandle; -use warp::{http::StatusCode, reject, Filter, Rejection, Reply}; +use warp::{filters::BoxedFilter, http::StatusCode, reject, Filter, Rejection, Reply}; use std::net::IpAddr; @@ -24,12 +24,13 @@ pub(crate) fn filter( public_routes: Box<[String]>, allowed_ips: Box<[IpAddr]>, network_command_sender: ResourceHandle, -) -> impl Filter + Clone { +) -> BoxedFilter<(impl Reply,)> { self::path() .and(warp::delete()) .and(has_permission(ROUTE_REMOVE_PEER, public_routes, allowed_ips)) .and(with_network_command_sender(network_command_sender)) .and_then(remove_peer) + .boxed() } pub(crate) async fn remove_peer( diff --git a/bee-api/bee-rest-api/src/endpoints/routes/api/v1/submit_message.rs b/bee-api/bee-rest-api/src/endpoints/routes/api/v1/submit_message.rs index f34f3532d1..d170d73b6f 100644 --- a/bee-api/bee-rest-api/src/endpoints/routes/api/v1/submit_message.rs +++ b/bee-api/bee-rest-api/src/endpoints/routes/api/v1/submit_message.rs @@ -24,7 +24,7 @@ use futures::channel::oneshot; use log::error; use serde_json::Value as JsonValue; use tokio::sync::mpsc; -use warp::{http::StatusCode, reject, Filter, Rejection, Reply}; +use warp::{filters::BoxedFilter, http::StatusCode, reject, Filter, Rejection, Reply}; use std::net::IpAddr; @@ -40,28 +40,31 @@ pub(crate) fn filter( network_id: NetworkId, rest_api_config: RestApiConfig, protocol_config: ProtocolConfig, -) -> impl Filter + Clone { - self::path().and(warp::post()).and( - (warp::header::exact("content-type", "application/json") - .and(has_permission( - ROUTE_SUBMIT_MESSAGE, - public_routes.clone(), - allowed_ips.clone(), - )) - .and(warp::body::json()) - .and(with_tangle(tangle.clone())) - .and(with_message_submitter(message_submitter.clone())) - .and(with_network_id(network_id)) - .and(with_rest_api_config(rest_api_config)) - .and(with_protocol_config(protocol_config)) - .and_then(submit_message)) - .or(warp::header::exact("content-type", "application/octet-stream") - .and(has_permission(ROUTE_SUBMIT_MESSAGE_RAW, public_routes, allowed_ips)) - .and(warp::body::bytes()) - .and(with_tangle(tangle)) - .and(with_message_submitter(message_submitter)) - .and_then(submit_message_raw)), - ) +) -> BoxedFilter<(impl Reply,)> { + self::path() + .and(warp::post()) + .and( + (warp::header::exact("content-type", "application/json") + .and(has_permission( + ROUTE_SUBMIT_MESSAGE, + public_routes.clone(), + allowed_ips.clone(), + )) + .and(warp::body::json()) + .and(with_tangle(tangle.clone())) + .and(with_message_submitter(message_submitter.clone())) + .and(with_network_id(network_id)) + .and(with_rest_api_config(rest_api_config)) + .and(with_protocol_config(protocol_config)) + .and_then(submit_message)) + .or(warp::header::exact("content-type", "application/octet-stream") + .and(has_permission(ROUTE_SUBMIT_MESSAGE_RAW, public_routes, allowed_ips)) + .and(warp::body::bytes()) + .and(with_tangle(tangle)) + .and(with_message_submitter(message_submitter)) + .and_then(submit_message_raw)), + ) + .boxed() } pub(crate) async fn submit_message( diff --git a/bee-api/bee-rest-api/src/endpoints/routes/api/v1/tips.rs b/bee-api/bee-rest-api/src/endpoints/routes/api/v1/tips.rs index e1dd0fb2ac..67e41e4925 100644 --- a/bee-api/bee-rest-api/src/endpoints/routes/api/v1/tips.rs +++ b/bee-api/bee-rest-api/src/endpoints/routes/api/v1/tips.rs @@ -12,7 +12,7 @@ use crate::{ use bee_runtime::resource::ResourceHandle; use bee_tangle::Tangle; -use warp::{reject, Filter, Rejection, Reply}; +use warp::{filters::BoxedFilter, reject, Filter, Rejection, Reply}; use std::net::IpAddr; @@ -24,12 +24,13 @@ pub(crate) fn filter( public_routes: Box<[String]>, allowed_ips: Box<[IpAddr]>, tangle: ResourceHandle>, -) -> impl Filter + Clone { +) -> BoxedFilter<(impl Reply,)> { self::path() .and(warp::get()) .and(has_permission(ROUTE_TIPS, public_routes, allowed_ips)) .and(with_tangle(tangle)) .and_then(tips) + .boxed() } pub(crate) async fn tips(tangle: ResourceHandle>) -> Result { diff --git a/bee-api/bee-rest-api/src/endpoints/routes/api/v1/transaction_included_message.rs b/bee-api/bee-rest-api/src/endpoints/routes/api/v1/transaction_included_message.rs index 849b58b2ea..2ea78a1a4f 100644 --- a/bee-api/bee-rest-api/src/endpoints/routes/api/v1/transaction_included_message.rs +++ b/bee-api/bee-rest-api/src/endpoints/routes/api/v1/transaction_included_message.rs @@ -17,7 +17,7 @@ use bee_runtime::resource::ResourceHandle; use bee_storage::access::Fetch; use bee_tangle::Tangle; -use warp::{reject, Filter, Rejection, Reply}; +use warp::{filters::BoxedFilter, reject, Filter, Rejection, Reply}; use std::net::IpAddr; @@ -34,7 +34,7 @@ pub(crate) fn filter( allowed_ips: Box<[IpAddr]>, storage: ResourceHandle, tangle: ResourceHandle>, -) -> impl Filter + Clone { +) -> BoxedFilter<(impl Reply,)> { self::path() .and(warp::get()) .and(has_permission( @@ -45,6 +45,7 @@ pub(crate) fn filter( .and(with_storage(storage)) .and(with_tangle(tangle)) .and_then(transaction_included_message) + .boxed() } pub(crate) async fn transaction_included_message( diff --git a/bee-api/bee-rest-api/src/endpoints/routes/api/v1/treasury.rs b/bee-api/bee-rest-api/src/endpoints/routes/api/v1/treasury.rs index 5f00aeeb6c..1551a4c341 100644 --- a/bee-api/bee-rest-api/src/endpoints/routes/api/v1/treasury.rs +++ b/bee-api/bee-rest-api/src/endpoints/routes/api/v1/treasury.rs @@ -12,7 +12,7 @@ use crate::{ use bee_ledger::workers::storage; use bee_runtime::resource::ResourceHandle; -use warp::{Filter, Rejection, Reply}; +use warp::{filters::BoxedFilter, Filter, Rejection, Reply}; use std::net::IpAddr; @@ -24,12 +24,13 @@ pub(crate) fn filter( public_routes: Box<[String]>, allowed_ips: Box<[IpAddr]>, storage: ResourceHandle, -) -> impl Filter + Clone { +) -> BoxedFilter<(impl Reply,)> { self::path() .and(warp::get()) .and(has_permission(ROUTE_TREASURY, public_routes, allowed_ips)) .and(with_storage(storage)) .and_then(|storage| async move { treasury(storage) }) + .boxed() } pub(crate) fn treasury(storage: ResourceHandle) -> Result { diff --git a/bee-api/bee-rest-api/src/endpoints/routes/health.rs b/bee-api/bee-rest-api/src/endpoints/routes/health.rs index e0183ac8a6..5f2ddafd12 100644 --- a/bee-api/bee-rest-api/src/endpoints/routes/health.rs +++ b/bee-api/bee-rest-api/src/endpoints/routes/health.rs @@ -12,7 +12,7 @@ use bee_protocol::workers::PeerManager; use bee_runtime::resource::ResourceHandle; use bee_tangle::Tangle; -use warp::{http::StatusCode, Filter, Rejection, Reply}; +use warp::{filters::BoxedFilter, http::StatusCode, Filter, Reply}; use std::{ convert::Infallible, @@ -32,13 +32,14 @@ pub(crate) fn filter( allowed_ips: Box<[IpAddr]>, tangle: ResourceHandle>, peer_manager: ResourceHandle, -) -> impl Filter + Clone { +) -> BoxedFilter<(impl Reply,)> { self::path() .and(warp::get()) .and(has_permission(ROUTE_HEALTH, public_routes, allowed_ips)) .and(with_tangle(tangle)) .and(with_peer_manager(peer_manager)) .and_then(health) + .boxed() } pub(crate) async fn health(