forked from interledger/interledger-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.rs
53 lines (49 loc) · 1.4 KB
/
server.rs
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
use super::packet::*;
use super::Account;
use futures::future::ok;
use interledger_packet::*;
use interledger_service::*;
use log::debug;
use std::marker::PhantomData;
/// A simple service that intercepts incoming ILDCP requests
/// and responds using the information in the Account struct.
#[derive(Clone)]
pub struct IldcpService<I, A> {
next: I,
account_type: PhantomData<A>,
}
impl<I, A> IldcpService<I, A>
where
I: IncomingService<A>,
A: Account,
{
pub fn new(next: I) -> Self {
IldcpService {
next,
account_type: PhantomData,
}
}
}
impl<I, A> IncomingService<A> for IldcpService<I, A>
where
I: IncomingService<A>,
A: Account,
{
type Future = BoxedIlpFuture;
fn handle_request(&mut self, request: IncomingRequest<A>) -> Self::Future {
if is_ildcp_request(&request.prepare) {
let from = request.from.ilp_address();
let builder = IldcpResponseBuilder {
ilp_address: &from,
asset_code: request.from.asset_code(),
asset_scale: request.from.asset_scale(),
};
debug!("Responding to query for ildcp info by account: {:?}", from);
let response = builder.build();
let fulfill = Fulfill::from(response);
Box::new(ok(fulfill))
} else {
Box::new(self.next.handle_request(request))
}
}
}