MCPcopy Create free account
hub / github.com/bwt-dev/bwt / setup

Function setup

src/http.rs:21–494  ·  view source on GitHub ↗
(
    access_token: Option<String>,
    cors: Option<String>,
    query: Arc<Query>,
    sync_tx: SyncChanSender,
    listeners: Listeners,
)

Source from the content-addressed store, hash-verified

19type SyncChanSender = Arc<Mutex<mpsc::Sender<()>>>;
20
21fn setup(
22 access_token: Option<String>,
23 cors: Option<String>,
24 query: Arc<Query>,
25 sync_tx: SyncChanSender,
26 listeners: Listeners,
27) -> warp::Server<impl warp::Filter<Extract = impl warp::Reply> + Clone> {
28 let query = warp::any().map(move || Arc::clone(&query));
29 let sync_tx = warp::any().map(move || Arc::clone(&sync_tx));
30 let listeners = warp::any().map(move || Arc::clone(&listeners));
31
32 let mut headers = header::HeaderMap::new();
33 if let Some(cors) = cors {
34 // allow using "any" as an alias for "*", avoiding expansion when passing "*" can be tricky
35 let cors = if cors == "any" { "*".into() } else { cors };
36 headers.insert("Access-Control-Allow-Origin", cors.parse().unwrap());
37 }
38
39 // GET /wallets
40 let wallets_handler = warp::get()
41 .and(warp::path!("wallets"))
42 .and(query.clone())
43 .map(|query: Arc<Query>| {
44 let wallets = query.get_wallets();
45 reply::json(&wallets)
46 });
47
48 // GET /wallet/:checksum
49 let wallet_handler = warp::get()
50 .and(warp::path!("wallet" / Checksum))
51 .and(query.clone())
52 .map(|checksum: Checksum, query: Arc<Query>| {
53 let wallet = query.get_wallet(&checksum).or_err(StatusCode::NOT_FOUND)?;
54 Ok(reply::json(&wallet))
55 })
56 .map(handle_error);
57
58 // GET /wallet/:checksum/:index
59 let wallet_key_handler = warp::get()
60 .and(warp::path!("wallet" / Checksum / u32))
61 .and(query.clone())
62 .map(|checksum: Checksum, index: u32, query: Arc<Query>| {
63 let script_info = query
64 .get_wallet_script_info(&checksum, index)
65 .or_err(StatusCode::NOT_FOUND)?;
66 Ok(reply::json(&script_info))
67 })
68 .map(handle_error);
69
70 // GET /wallet/:checksum/gap
71 let wallet_gap_handler = warp::get()
72 .and(warp::path!("wallet" / Checksum / "gap"))
73 .and(query.clone())
74 .map(|checksum: Checksum, query: Arc<Query>| {
75 let gap = query
76 .find_wallet_gap(&checksum)
77 .or_err(StatusCode::NOT_FOUND)?;
78 Ok(reply::json(&gap))

Callers 1

startMethod · 0.85

Calls 15

make_sse_streamFunction · 0.85
get_welcome_bannerFunction · 0.85
get_whitepaper_pdfFunction · 0.85
http_basic_authFunction · 0.85
intoMethod · 0.80
get_walletsMethod · 0.80
or_errMethod · 0.80
get_walletMethod · 0.80
find_wallet_gapMethod · 0.80
get_next_indexMethod · 0.80
and_thenMethod · 0.80

Tested by

no test coverage detected