mod accounts;
mod eth;
mod eth_filter;
mod net;
mod parity;
mod parity_accounts;
mod parity_set;
mod personal;
mod txpool;
mod web3;
pub use self::{
accounts::Accounts,
eth::Eth,
eth_filter::{BaseFilter, EthFilter},
net::Net,
parity::Parity,
parity_accounts::ParityAccounts,
parity_set::ParitySet,
personal::Personal,
txpool::Txpool,
web3::Web3 as Web3Api,
};
use crate::{
confirm, error,
types::{Bytes, TransactionReceipt, TransactionRequest, U64},
Transport,
};
use futures::Future;
use core::time::Duration;
pub trait Namespace<T: Transport>: Clone {
fn new(transport: T) -> Self;
fn transport(&self) -> &T;
}
#[derive(Debug, Clone)]
pub struct Web3<T: Transport> {
transport: T,
}
impl<T: Transport> Web3<T> {
pub fn new(transport: T) -> Self {
Web3 { transport }
}
pub fn transport(&self) -> &T {
&self.transport
}
pub fn api<A: Namespace<T>>(&self) -> A {
A::new(self.transport.clone())
}
pub fn accounts(&self) -> accounts::Accounts<T> {
self.api()
}
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 parity(&self) -> parity::Parity<T> {
self.api()
}
pub fn parity_accounts(&self) -> parity_accounts::ParityAccounts<T> {
self.api()
}
pub fn parity_set(&self) -> parity_set::ParitySet<T> {
self.api()
}
pub fn personal(&self) -> personal::Personal<T> {
self.api()
}
pub fn txpool(&self) -> txpool::Txpool<T> {
self.api()
}
pub async fn wait_for_confirmations<F, V>(
&self,
poll_interval: Duration,
confirmations: usize,
check: V,
) -> error::Result<()>
where
F: Future<Output = error::Result<Option<U64>>>,
V: confirm::ConfirmationCheck<Check = F>,
{
confirm::wait_for_confirmations(self.eth(), self.eth_filter(), poll_interval, confirmations, check).await
}
pub async fn send_transaction_with_confirmation(
&self,
tx: TransactionRequest,
poll_interval: Duration,
confirmations: usize,
) -> error::Result<TransactionReceipt> {
confirm::send_transaction_with_confirmation(self.transport.clone(), tx, poll_interval, confirmations).await
}
pub async fn send_raw_transaction_with_confirmation(
&self,
tx: Bytes,
poll_interval: Duration,
confirmations: usize,
) -> error::Result<TransactionReceipt> {
confirm::send_raw_transaction_with_confirmation(self.transport.clone(), tx, poll_interval, confirmations).await
}
}