forked from tomusdrw/rust-web3
-
Notifications
You must be signed in to change notification settings - Fork 27
/
batch.rs
35 lines (26 loc) · 876 Bytes
/
batch.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
extern crate tokio_core;
extern crate web3;
use web3::futures::Future;
const MAX_PARALLEL_REQUESTS: usize = 64;
fn main() {
let mut event_loop = tokio_core::reactor::Core::new().unwrap();
let remote = event_loop.remote();
let http =
web3::transports::Http::with_event_loop("http://localhost:8545", &event_loop.handle(), MAX_PARALLEL_REQUESTS)
.unwrap();
let web3 = web3::Web3::new(web3::transports::Batch::new(http));
let _ = web3.eth().accounts();
let block = web3.eth().block_number().then(|block| {
println!("Best Block: {:?}", block);
Ok(())
});
let result = web3.transport().submit_batch().then(|accounts| {
println!("Result: {:?}", accounts);
Ok(())
});
remote.spawn(move |_| block);
remote.spawn(move |_| result);
loop {
event_loop.turn(None);
}
}