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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
mod advisor_reviews;
pub mod challenges;
mod funds;
mod genesis;
mod health;
pub mod proposals;
pub mod search;
pub mod service_version;
pub mod snapshot;
mod votes;

use crate::v0::context::SharedContext;

use crate::v0::api_token;
use warp::filters::BoxedFilter;
use warp::{Filter, Rejection, Reply};

pub async fn filter(
    root: BoxedFilter<()>,
    context: SharedContext,
    enable_api_tokens: bool,
) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
    // mount health endpoint
    let health_root = warp::path!("health" / ..);
    let health_filter = health::filter(health_root.boxed(), context.clone()).await;

    // mount chain-data endpoint
    let chain_data_root = warp::path!("proposals" / ..);
    let chain_data_filter =
        proposals::proposals_filter(chain_data_root.boxed(), context.clone()).await;

    // mount single proposal endpoint
    let proposal_filter =
        proposals::proposal_filter((warp::path!("proposal" / ..)).boxed(), context.clone()).await;

    // mount funds endpoint
    let funds_root = warp::path!("fund" / ..);
    let funds_filter = funds::filter(funds_root.boxed(), context.clone()).await;

    // mount challenges endpoint
    let challenges_root = warp::path!("challenges" / ..);
    let challenges_filter = challenges::filter(challenges_root.boxed(), context.clone()).await;

    // mount genesis endpoint
    let genesis_root = warp::path!("block0" / ..);
    let genesis_filter = genesis::filter(genesis_root.boxed(), context.clone());

    let reviews_root = warp::path!("reviews" / ..);
    let reviews_filter = advisor_reviews::filter(reviews_root.boxed(), context.clone()).await;

    let votes_root = warp::path!("votes" / ..);
    let votes_filter = votes::filter(votes_root.boxed(), context.clone()).await;

    let search_root = warp::path!("search" / ..);
    let search_filter = search::search_filter(search_root.boxed(), context.clone()).await;

    let search_count_root = warp::path!("search_count" / ..);
    let search_count_filter =
        search::search_count_filter(search_count_root.boxed(), context.clone()).await;

    let snapshot_root = warp::path!("snapshot" / ..);
    let snapshot_rx_filter = snapshot::filter(snapshot_root.boxed(), context.clone());

    let admin_filter = {
        let base = warp::path!("admin" / ..);
        let fund_filter = warp::path!("fund" / ..).and(funds::admin_filter(context.clone()));

        base.and(fund_filter)
    };

    let api_token_filter = if enable_api_tokens {
        api_token::api_token_filter(context).await.boxed()
    } else {
        warp::any().boxed()
    };

    root.and(
        api_token_filter.and(
            health_filter
                .or(genesis_filter)
                .or(chain_data_filter)
                .or(proposal_filter)
                .or(funds_filter)
                .or(challenges_filter)
                .or(reviews_filter)
                .or(votes_filter)
                .or(search_filter)
                .or(search_count_filter)
                .or(snapshot_rx_filter)
                .or(admin_filter),
        ),
    )
    .boxed()
}