1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
use super::handlers::get_genesis;
use crate::v0::context::SharedContext;
use crate::v0::endpoints::genesis::handlers::get_genesis_for_fund;
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 default_block0 = warp::path::end()
        .and(warp::get())
        .and(with_context.clone())
        .and_then(get_genesis)
        .boxed();

    let block0_per_fund = warp::path!(i32)
        .and(warp::get())
        .and(with_context)
        .and_then(get_genesis_for_fund)
        .boxed();

    root.and(default_block0.or(block0_per_fund)).boxed()
}