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

Feat/wait for user operation receipt #22

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
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
14 changes: 14 additions & 0 deletions crates/ffi/src/account_client.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use super::ffi;
use yttrium::bundler::models::user_operation_receipt::UserOperationReceipt;
use super::ffi::{FFIAccountClientConfig, FFIError};
use yttrium::{
account_client::{AccountClient, SignerType},
Expand Down Expand Up @@ -127,6 +128,19 @@ impl FFIAccountClient {
.sign_message_with_mnemonic(message, mnemonic)
.map_err(|e| FFIError::Unknown(e.to_string()))
}

pub async fn wait_for_user_operation_receipt(
&self,
user_operation_hash: String
) -> Result<String, FFIError> {
self.account_client
.wait_for_user_operation_receipt(user_operation_hash)
.await
.map_err(|e: eyre::Error| FFIError::Unknown(e.to_string()))
.iter()
.flat_map(|receipt|{serde_json::to_string(&receipt)?.into_iter()})
.collect::<String>()
}
}

impl From<ffi::FFITransaction> for Transaction {
Expand Down
5 changes: 5 additions & 0 deletions crates/ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ mod ffi {
message: String,
mnemonic: String,
) -> Result<String, FFIError>;

pub async fn wait_for_user_operation_receipt(
&self,
user_operation_hash: String
) -> Result<String, FFIError>;
}

extern "Rust" {
Expand Down
32 changes: 32 additions & 0 deletions crates/yttrium/src/account_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@ use crate::private_key_service::PrivateKeyService;
use crate::sign_service::SignService;
use crate::transaction::send::safe_test;
use crate::transaction::{send::send_transaction, Transaction};
use crate::user_operation::user_operation_hash;
use alloy::primitives::Address;
use alloy::signers::local::PrivateKeySigner;
use std::sync::Arc;
use tokio::sync::Mutex;
use crate::bundler::models::user_operation_receipt::UserOperationReceipt;
use crate::
bundler::{
client::BundlerClient, config::BundlerConfig
};

#[derive(Clone)]
pub enum SignerType {
Expand Down Expand Up @@ -161,8 +167,34 @@ impl AccountClient {

Ok(signature)
}

pub async fn wait_for_user_operation_receipt(
&self,
user_operation_hash: String
) -> eyre::Result<UserOperationReceipt> {

println!("Querying for receipts...");

let bundler_base_url = self.config.clone().endpoints.bundler.base_url;

let bundler_client =
BundlerClient::new(BundlerConfig::new(bundler_base_url.clone()));
let receipt = bundler_client
.wait_for_user_operation_receipt(user_operation_hash.clone())
.await?;

println!("Received User Operation receipt: {:?}", receipt);

let tx_hash = receipt.clone().receipt.transaction_hash;
println!(
"UserOperation included: https://sepolia.etherscan.io/tx/{}",
tx_hash
);
Ok(receipt)
}
}


impl AccountClient {
pub fn mock() -> Self {
AccountClient {
Expand Down
4 changes: 2 additions & 2 deletions crates/yttrium/src/bundler/models/user_operation_receipt.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use alloy::primitives::Address;
use serde::{Deserialize, Serialize};

#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct UserOperationReceiptReceipt {
pub transaction_hash: String,
Expand All @@ -19,7 +19,7 @@ pub struct UserOperationReceiptReceipt {
pub effective_gas_price: String,
}

#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize,)]
#[serde(rename_all = "camelCase")]
pub struct UserOperationReceipt {
pub user_op_hash: String,
Expand Down
18 changes: 0 additions & 18 deletions crates/yttrium/src/transaction/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,24 +349,6 @@ mod tests {

println!("Received User Operation hash: {:?}", user_operation_hash);

// let receipt = bundler_client
// .get_user_operation_receipt(user_operation_hash.clone())
// .await?;

// println!("Received User Operation receipt: {:?}", receipt);

// println!("Querying for receipts...");

// let receipt = bundler_client
// .wait_for_user_operation_receipt(user_operation_hash.clone())
// .await?;

// let tx_hash = receipt.receipt.transaction_hash;
// println!(
// "UserOperation included: https://sepolia.etherscan.io/tx/{}",
// tx_hash
// );

Ok(user_operation_hash)
}

Expand Down
12 changes: 0 additions & 12 deletions crates/yttrium/src/transaction/send/safe_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,18 +406,6 @@ pub async fn send_transaction(

println!("Received User Operation hash: {:?}", user_operation_hash);

println!("Querying for receipts...");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A call to this new function needs to be added to the tests


let receipt = bundler_client
.wait_for_user_operation_receipt(user_operation_hash.clone())
.await?;

let tx_hash = receipt.receipt.transaction_hash;
println!(
"SAFE UserOperation included: https://sepolia.etherscan.io/tx/{}",
tx_hash
);

// Some extra calls to wait for/get the actual transaction. But these
// aren't required since eth_getUserOperationReceipt already waits
// let tx_hash = FixedBytes::from_slice(
Expand Down
36 changes: 0 additions & 36 deletions crates/yttrium/src/transaction/send/simple_account_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,28 +252,6 @@ pub async fn send_transaction_with_signer(

println!("Received User Operation hash: {:?}", user_operation_hash);

// TODO convert to polling
use std::time::Duration;
tokio::time::sleep(Duration::from_secs(2)).await;

let receipt = bundler_client
.get_user_operation_receipt(user_operation_hash.clone())
.await?;

println!("Received User Operation receipt: {:?}", receipt);

println!("Querying for receipts...");

let receipt = bundler_client
.wait_for_user_operation_receipt(user_operation_hash.clone())
.await?;

let tx_hash = receipt.receipt.transaction_hash;
println!(
"UserOperation included: https://sepolia.etherscan.io/tx/{}",
tx_hash
);

Ok(user_operation_hash)
}

Expand Down Expand Up @@ -479,20 +457,6 @@ mod tests {
)
.await?;

println!("Querying for receipts...");

let receipt = bundler_client
.wait_for_user_operation_receipt(user_operation_hash.clone())
.await?;

println!("Received User Operation receipt: {:?}", receipt);

let tx_hash = receipt.receipt.transaction_hash;
println!(
"UserOperation included: https://sepolia.etherscan.io/tx/{}",
tx_hash
);

Ok(user_operation_hash)
}

Expand Down
9 changes: 9 additions & 0 deletions platforms/swift/Sources/Yttrium/AccountClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,15 @@ public final class AccountClient: AccountClientProtocol {
)
.toString()
}

public func waitForUserOperationReceipt(
userOperationHash: String
) async throws -> String {
try await coreAccountClient.wait_for_user_operation_receipt(
userOperationHash.intoRustString()
)
.toString()
}
}

extension Transaction {
Expand Down
Loading