From f1a82bbca97bb9d69c2ecd01bd8ab93df0f3b125 Mon Sep 17 00:00:00 2001 From: IAvecilla Date: Fri, 13 Sep 2024 10:20:32 -0300 Subject: [PATCH] Fix format --- examples/paymaster/main.rs | 54 +++++++++++++++++++++++++++----------- src/zks_provider/mod.rs | 1 + 2 files changed, 39 insertions(+), 16 deletions(-) diff --git a/examples/paymaster/main.rs b/examples/paymaster/main.rs index f90d614..1f84614 100644 --- a/examples/paymaster/main.rs +++ b/examples/paymaster/main.rs @@ -12,8 +12,8 @@ use std::str::FromStr; use std::sync::Arc; use zksync_web3_rs::core::abi::{Contract, Token}; use zksync_web3_rs::eip712::{Eip712Meta, Eip712TransactionRequest, PaymasterParams}; -use zksync_web3_rs::ZKSWallet; use zksync_web3_rs::zks_provider::ZKSProvider; +use zksync_web3_rs::ZKSWallet; static ERA_PROVIDER_URL: &str = "http://127.0.0.1:3050"; static PK: &str = "0x27593fea79697e947890ecbecce7901b0008345e5d7259710d0dd5e500d040be"; @@ -46,24 +46,34 @@ pub struct PaymasterFlow { } impl PaymasterFlow { - pub fn new(private_key: String, - paymaster_address: H160, - chain_id: u64, - provider:Provider) -> Self { - let paymaster_contract = Contract::load(PAYMASTER_ABI.as_bytes()).expect("Failed to load the paymaster ABI"); - let paymaster_general_fn = paymaster_contract.function("general").expect("Failed to get the general function"); - let wallet = Wallet::from_str(private_key.as_str()).expect("Failed to create wallet from private key"); + pub fn new( + private_key: String, + paymaster_address: H160, + chain_id: u64, + provider: Provider, + ) -> Self { + let paymaster_contract = + Contract::load(PAYMASTER_ABI.as_bytes()).expect("Failed to load the paymaster ABI"); + let paymaster_general_fn = paymaster_contract + .function("general") + .expect("Failed to get the general function"); + let wallet = Wallet::from_str(private_key.as_str()) + .expect("Failed to create wallet from private key"); let signer = Wallet::with_chain_id(wallet, chain_id); let zk_wallet = ZKSWallet::new(signer, None, Some(provider.clone()), None).unwrap(); - let era_provider = zk_wallet.get_era_provider().expect("Failed to get era provider from zk wallet"); - let paymaster_encoded_input = paymaster_general_fn.encode_input(&[Token::Bytes(vec![])]).expect("Failed to encode paymaster input"); - + let era_provider = zk_wallet + .get_era_provider() + .expect("Failed to get era provider from zk wallet"); + let paymaster_encoded_input = paymaster_general_fn + .encode_input(&[Token::Bytes(vec![])]) + .expect("Failed to encode paymaster input"); + Self { paymaster: paymaster_address, amount: U256::from_dec_str("1").expect("Failed to parse amount"), paymaster_encoded_input, zk_wallet, - era_provider + era_provider, } } @@ -75,12 +85,13 @@ impl PaymasterFlow { .value(self.amount) .custom_data(Eip712Meta::new().paymaster_params(PaymasterParams { paymaster: self.paymaster, - paymaster_input: self.paymaster_encoded_input.clone() + paymaster_input: self.paymaster_encoded_input.clone(), })) } async fn send_transaction(&self) -> anyhow::Result> { - let result = self.era_provider + let result = self + .era_provider .send_transaction_eip712(&self.zk_wallet.l2_wallet, self.tx_request()) .await?; Ok(result) @@ -92,7 +103,18 @@ async fn main() { let era_provider = Provider::try_from(ERA_PROVIDER_URL).unwrap(); let paymaster_address = Address::from_str(PAYMASTER_ADDRESS).unwrap(); let chain_id = era_provider.get_chainid().await.unwrap(); - let flow = PaymasterFlow::new(PK.to_string(), paymaster_address, chain_id.as_u64(), era_provider.clone()); - let tx = flow.send_transaction().await.unwrap().await.unwrap().unwrap(); + let flow = PaymasterFlow::new( + PK.to_string(), + paymaster_address, + chain_id.as_u64(), + era_provider.clone(), + ); + let tx = flow + .send_transaction() + .await + .unwrap() + .await + .unwrap() + .unwrap(); println!("Transaction sent: {:#?}", tx); } diff --git a/src/zks_provider/mod.rs b/src/zks_provider/mod.rs index ffc23ff..8365e01 100644 --- a/src/zks_provider/mod.rs +++ b/src/zks_provider/mod.rs @@ -726,6 +726,7 @@ impl ZKSProvider for Provider

{ .sign_typed_data(&signable_data) .await .map_err(|e| ProviderError::CustomError(format!("error signing transaction: {e}")))?; + println!("signature: {:#?}", signature); request = request.custom_data(custom_data.custom_signature(signature.to_vec())); let encoded_rlp = &*request .rlp_signed(signature)