Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

signed_call (without confirmations) #581

Merged
merged 5 commits into from
Feb 2, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 40 additions & 8 deletions src/contract/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,20 +330,20 @@ impl<T: Transport> Contract<T> {
#[cfg(feature = "signing")]
mod contract_signing {
use super::*;
use crate::{api::Accounts, signing, types::TransactionParameters};
use crate::{
api::Accounts,
signing,
types::{SignedTransaction, TransactionParameters},
};

impl<T: Transport> Contract<T> {
/// Execute a signed contract function and wait for confirmations
pub async fn signed_call_with_confirmations(
async fn sign(
&self,
func: &str,
params: impl Tokenize,
options: Options,
confirmations: usize,
key: impl signing::Key,
) -> crate::Result<TransactionReceipt> {
let poll_interval = time::Duration::from_secs(1);

) -> crate::Result<SignedTransaction> {
let fn_data = self
.abi
.function(func)
Expand All @@ -365,7 +365,39 @@ mod contract_signing {
if let Some(value) = options.value {
tx.value = value;
}
let signed = accounts.sign_transaction(tx, key).await?;
accounts.sign_transaction(tx, key).await
}

/// Submit contract call transaction to the transaction pool.
///
/// Note this function DOES NOT wait for any confirmations, so there is no guarantees that the call is actually executed.
/// If you'd rather wait for block inclusion, please use [`signed_call_with_confirmations`] instead.
pub async fn signed_call(
&self,
func: &str,
params: impl Tokenize,
options: Options,
key: impl signing::Key,
) -> crate::Result<H256> {
let signed = self.sign(func, params, options, key).await?;
self.eth.send_raw_transaction(signed.raw_transaction).await
}

/// Submit contract call transaction to the transaction pool and wait for the transaction to be included in a block.
///
/// This function will wait for block inclusion of the transaction before returning.
// If you'd rather just submit transaction and receive it's hash, please use [`signed_call`] instead.
pub async fn signed_call_with_confirmations(
&self,
func: &str,
params: impl Tokenize,
options: Options,
confirmations: usize,
key: impl signing::Key,
) -> crate::Result<TransactionReceipt> {
let poll_interval = time::Duration::from_secs(1);
let signed = self.sign(func, params, options, key).await?;

confirm::send_raw_transaction_with_confirmation(
self.eth.transport().clone(),
signed.raw_transaction,
Expand Down