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
95
96
97
98
99
100
101
102
103
104
mod eth;
mod eth_filter;
mod net;
mod personal;
mod web3;
pub use self::eth::Eth;
pub use self::eth_filter::{BaseFilter, CreateFilter, EthFilter, FilterStream};
pub use self::net::Net;
pub use self::personal::Personal;
pub use self::web3::Web3;
use std::time::Duration;
use futures::{IntoFuture};
use {confirm, Transport, Error};
use types::{U256, TransactionRequest};
pub trait Namespace<T: Transport> {
fn new(transport: T) -> Self where Self: Sized;
fn transport(&self) -> &T;
}
pub struct Web3Main<T: Transport> {
transport: T,
}
pub type ErasedWeb3 = Web3Main<::Erased>;
impl<T: Transport> Web3Main<T> {
pub fn new(transport: T) -> Self {
Web3Main {
transport,
}
}
pub fn transport(&self) -> &T {
&self.transport
}
pub fn api<'a, A: Namespace<&'a T>>(&'a self) -> A {
A::new(&self.transport)
}
pub fn eth(&self) -> eth::Eth<&T> {
self.api()
}
pub fn net(&self) -> net::Net<&T> {
self.api()
}
pub fn web3(&self) -> web3::Web3<&T> {
self.api()
}
pub fn eth_filter(&self) -> eth_filter::EthFilter<&T> {
self.api()
}
pub fn personal(&self) -> personal::Personal<&T> {
self.api()
}
pub fn wait_for_confirmations<F, V>(
&self,
poll_interval: Duration,
confirmations: u64,
check: V
) -> confirm::Confirmations<&T, V, F::Future> where
F: IntoFuture<Item = Option<U256>, Error = Error>,
V: confirm::ConfirmationCheck<Check = F>,
{
confirm::wait_for_confirmations(&self.transport, poll_interval, confirmations, check)
}
pub fn send_transaction_with_confirmation(
&self,
tx: TransactionRequest,
poll_interval: Duration,
confirmations: u64
) -> confirm::SendTransactionWithConfirmation<&T> {
confirm::send_transaction_with_confirmation(&self.transport, tx, poll_interval, confirmations)
}
}