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