1mod accounts;
4mod eth;
5mod eth_filter;
6mod net;
7mod parity;
8mod parity_accounts;
9mod parity_set;
10mod personal;
11mod txpool;
13mod web3;
14
15pub use self::{
16 accounts::Accounts,
17 eth::Eth,
18 eth_filter::{BaseFilter, EthFilter},
19 net::Net,
20 parity::Parity,
21 parity_accounts::ParityAccounts,
22 parity_set::ParitySet,
23 personal::Personal,
24 txpool::Txpool,
26 web3::Web3 as Web3Api,
27};
28
29use crate::{
30 confirm, error,
31 types::{Bytes, TransactionReceipt, TransactionRequest, U64},
32 Transport,
33};
34use futures::Future;
35use core::time::Duration;
36
37pub trait Namespace<T: Transport>: Clone {
39 fn new(transport: T) -> Self;
41
42 fn transport(&self) -> &T;
44}
45
46#[derive(Debug, Clone)]
48pub struct Web3<T: Transport> {
49 transport: T,
50}
51
52impl<T: Transport> Web3<T> {
53 pub fn new(transport: T) -> Self {
55 Web3 { transport }
56 }
57
58 pub fn transport(&self) -> &T {
60 &self.transport
61 }
62
63 pub fn api<A: Namespace<T>>(&self) -> A {
65 A::new(self.transport.clone())
66 }
67
68 pub fn accounts(&self) -> accounts::Accounts<T> {
70 self.api()
71 }
72
73 pub fn eth(&self) -> eth::Eth<T> {
75 self.api()
76 }
77
78 pub fn net(&self) -> net::Net<T> {
80 self.api()
81 }
82
83 pub fn web3(&self) -> web3::Web3<T> {
85 self.api()
86 }
87
88 pub fn eth_filter(&self) -> eth_filter::EthFilter<T> {
90 self.api()
91 }
92
93 pub fn parity(&self) -> parity::Parity<T> {
95 self.api()
96 }
97
98 pub fn parity_accounts(&self) -> parity_accounts::ParityAccounts<T> {
100 self.api()
101 }
102
103 pub fn parity_set(&self) -> parity_set::ParitySet<T> {
105 self.api()
106 }
107
108 pub fn personal(&self) -> personal::Personal<T> {
110 self.api()
111 }
112
113 pub fn txpool(&self) -> txpool::Txpool<T> {
120 self.api()
121 }
122
123 pub async fn wait_for_confirmations<F, V>(
125 &self,
126 poll_interval: Duration,
127 confirmations: usize,
128 check: V,
129 ) -> error::Result<()>
130 where
131 F: Future<Output = error::Result<Option<U64>>>,
132 V: confirm::ConfirmationCheck<Check = F>,
133 {
134 confirm::wait_for_confirmations(self.eth(), self.eth_filter(), poll_interval, confirmations, check).await
135 }
136
137 pub async fn send_transaction_with_confirmation(
139 &self,
140 tx: TransactionRequest,
141 poll_interval: Duration,
142 confirmations: usize,
143 ) -> error::Result<TransactionReceipt> {
144 confirm::send_transaction_with_confirmation(self.transport.clone(), tx, poll_interval, confirmations).await
145 }
146
147 pub async fn send_raw_transaction_with_confirmation(
149 &self,
150 tx: Bytes,
151 poll_interval: Duration,
152 confirmations: usize,
153 ) -> error::Result<TransactionReceipt> {
154 confirm::send_raw_transaction_with_confirmation(self.transport.clone(), tx, poll_interval, confirmations).await
155 }
156}