pub struct PendingTransactionBuilder<T, N: Network> { /* private fields */ }
Expand description
A builder for configuring a pending transaction watcher.
§Examples
Send and wait for a transaction to be confirmed 2 times, with a timeout of 60 seconds:
// Send a transaction, and configure the pending transaction.
let builder = provider.send_transaction(tx)
.await?
.with_required_confirmations(2)
.with_timeout(Some(std::time::Duration::from_secs(60)));
// Register the pending transaction with the provider.
let pending_tx = builder.register().await?;
// Wait for the transaction to be confirmed 2 times.
let tx_hash = pending_tx.await?;
This can also be more concisely written using watch
:
let tx_hash = provider.send_transaction(tx)
.await?
.with_required_confirmations(2)
.with_timeout(Some(std::time::Duration::from_secs(60)))
.watch()
.await?;
Implementations§
Source§impl<T: Transport + Clone, N: Network> PendingTransactionBuilder<T, N>
impl<T: Transport + Clone, N: Network> PendingTransactionBuilder<T, N>
Sourcepub const fn new(provider: RootProvider<T, N>, tx_hash: TxHash) -> Self
pub const fn new(provider: RootProvider<T, N>, tx_hash: TxHash) -> Self
Creates a new pending transaction builder.
Sourcepub const fn from_config(
provider: RootProvider<T, N>,
config: PendingTransactionConfig,
) -> Self
pub const fn from_config( provider: RootProvider<T, N>, config: PendingTransactionConfig, ) -> Self
Creates a new pending transaction builder from the given configuration.
Sourcepub const fn inner(&self) -> &PendingTransactionConfig
pub const fn inner(&self) -> &PendingTransactionConfig
Returns the inner configuration.
Sourcepub fn into_inner(self) -> PendingTransactionConfig
pub fn into_inner(self) -> PendingTransactionConfig
Consumes this builder, returning the inner configuration.
Sourcepub const fn provider(&self) -> &RootProvider<T, N>
pub const fn provider(&self) -> &RootProvider<T, N>
Returns the provider.
Sourcepub fn split(self) -> (RootProvider<T, N>, PendingTransactionConfig)
pub fn split(self) -> (RootProvider<T, N>, PendingTransactionConfig)
Consumes this builder, returning the provider and the configuration.
Sourcepub fn set_tx_hash(&mut self, tx_hash: TxHash)
pub fn set_tx_hash(&mut self, tx_hash: TxHash)
Sets the transaction hash.
Sourcepub const fn with_tx_hash(self, tx_hash: TxHash) -> Self
pub const fn with_tx_hash(self, tx_hash: TxHash) -> Self
Sets the transaction hash.
Sourcepub const fn required_confirmations(&self) -> u64
pub const fn required_confirmations(&self) -> u64
Returns the number of confirmations to wait for.
Sourcepub fn set_required_confirmations(&mut self, confirmations: u64)
pub fn set_required_confirmations(&mut self, confirmations: u64)
Sets the number of confirmations to wait for.
Sourcepub const fn with_required_confirmations(self, confirmations: u64) -> Self
pub const fn with_required_confirmations(self, confirmations: u64) -> Self
Sets the number of confirmations to wait for.
Sourcepub fn set_timeout(&mut self, timeout: Option<Duration>)
pub fn set_timeout(&mut self, timeout: Option<Duration>)
Sets the timeout.
Sourcepub const fn with_timeout(self, timeout: Option<Duration>) -> Self
pub const fn with_timeout(self, timeout: Option<Duration>) -> Self
Sets the timeout.
Sourcepub async fn register(
self,
) -> Result<PendingTransaction, PendingTransactionError>
pub async fn register( self, ) -> Result<PendingTransaction, PendingTransactionError>
Registers the watching configuration with the provider.
This does not wait for the transaction to be confirmed, but returns a PendingTransaction
that can be awaited at a later moment.
See:
watch
for watching the transaction without fetching the receipt.get_receipt
for fetching the receipt after the transaction has been confirmed.
Sourcepub async fn watch(self) -> Result<TxHash, PendingTransactionError>
pub async fn watch(self) -> Result<TxHash, PendingTransactionError>
Waits for the transaction to confirm with the given number of confirmations.
See:
register
: for registering the transaction without waiting for it to be confirmed.get_receipt
for fetching the receipt after the transaction has been confirmed.
Sourcepub async fn get_receipt(
self,
) -> Result<N::ReceiptResponse, PendingTransactionError>
pub async fn get_receipt( self, ) -> Result<N::ReceiptResponse, PendingTransactionError>
Waits for the transaction to confirm with the given number of confirmations, and then fetches its receipt.
Note that this method will call eth_getTransactionReceipt
on the root
provider, and not on a specific network provider. This means that any
overrides or customizations made to the network provider will not be used.
See:
Trait Implementations§
Auto Trait Implementations§
impl<T, N> Freeze for PendingTransactionBuilder<T, N>
impl<T, N> RefUnwindSafe for PendingTransactionBuilder<T, N>where
N: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, N> Send for PendingTransactionBuilder<T, N>
impl<T, N> Sync for PendingTransactionBuilder<T, N>
impl<T, N> Unpin for PendingTransactionBuilder<T, N>
impl<T, N> UnwindSafe for PendingTransactionBuilder<T, N>where
N: RefUnwindSafe,
T: RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more