1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
use crate::v0::context::SharedContext;

use super::handlers::{get_delegator_info, get_voters_info};
use warp::filters::BoxedFilter;
use warp::{Filter, Rejection, Reply};

pub fn filter(
    root: BoxedFilter<()>,
    context: SharedContext,
) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
    let with_context = warp::any().map(move || context.clone());

    let get_voters_info = warp::path!("voter" / String / String)
        .and(warp::get())
        .and(with_context.clone())
        .and_then(get_voters_info);

    let get_delegator_info = warp::path!("delegator" / String / String)
        .and(warp::get())
        .and(with_context)
        .and_then(get_delegator_info);

    root.and(get_voters_info.or(get_delegator_info))
}