-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: more dedicated modules for zksync-specific code (#891)
* refactor(cast): move `ZkCast` to dedicated module * refactor(compile): extract zksync methods * chore: fmt * feat(create): move zksync code to dedicated module * chore: fmt * chore: clippy * chore: moar fmt
- Loading branch information
Showing
6 changed files
with
825 additions
and
759 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
//! Contains zksync specific logic for foundry's `cast` functionality | ||
use alloy_network::AnyNetwork; | ||
use alloy_provider::{PendingTransactionBuilder, Provider}; | ||
use alloy_transport::Transport; | ||
use alloy_zksync::network::{ | ||
transaction_request::TransactionRequest as ZkTransactionRequest, Zksync, | ||
}; | ||
use eyre::Result; | ||
|
||
use crate::Cast; | ||
|
||
pub struct ZkCast<P, T, Z> { | ||
provider: Z, | ||
inner: Cast<P, T>, | ||
} | ||
|
||
impl<P, T, Z> AsRef<Cast<P, T>> for ZkCast<P, T, Z> | ||
where | ||
P: Provider<T, AnyNetwork>, | ||
T: Transport + Clone, | ||
Z: Provider<T, Zksync>, | ||
{ | ||
fn as_ref(&self) -> &Cast<P, T> { | ||
&self.inner | ||
} | ||
} | ||
|
||
impl<P, T, Z> ZkCast<P, T, Z> | ||
where | ||
P: Provider<T, AnyNetwork>, | ||
T: Transport + Clone, | ||
Z: Provider<T, Zksync>, | ||
{ | ||
/// Creates a new ZkCast instance from the provided client and Cast instance | ||
/// | ||
/// # Example | ||
/// | ||
/// ``` | ||
/// use alloy_provider::{network::AnyNetwork, ProviderBuilder, RootProvider}; | ||
/// use cast::Cast; | ||
/// | ||
/// # async fn foo() -> eyre::Result<()> { | ||
/// let provider = | ||
/// ProviderBuilder::<_, _, AnyNetwork>::default().on_builtin("http://localhost:8545").await?; | ||
/// let cast = Cast::new(provider); | ||
/// let zk_provider = | ||
/// ProviderBuilder::<_, _, Zksync>::default().on_builtin("http://localhost:8011").await?; | ||
/// let zk_cast = ZkCast::new(provider, cast); | ||
/// # Ok(()) | ||
/// # } | ||
/// ``` | ||
pub fn new(provider: Z, cast: Cast<P, T>) -> Self { | ||
Self { provider, inner: cast } | ||
} | ||
|
||
pub async fn send_zk( | ||
&self, | ||
tx: ZkTransactionRequest, | ||
) -> Result<PendingTransactionBuilder<T, Zksync>> { | ||
let res = self.provider.send_transaction(tx).await?; | ||
|
||
Ok(res) | ||
} | ||
} |
Oops, something went wrong.