Skip to content
This repository has been archived by the owner on Nov 25, 2024. It is now read-only.

Commit

Permalink
Merge pull request #142 from paradigmxyz/matt/add-permit
Browse files Browse the repository at this point in the history
feat: add permit
  • Loading branch information
mattsse authored Oct 8, 2024
2 parents 0505bce + c6f1039 commit 7726f7e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/wallet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jsonrpsee = { workspace = true, features = ["server", "macros"] }
serde = { workspace = true, features = ["derive"] }
thiserror.workspace = true
tracing.workspace = true
tokio = { workspace = true, features = ["sync"] }

[dev-dependencies]
serde_json.workspace = true
Expand Down
9 changes: 8 additions & 1 deletion crates/wallet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ use std::sync::Arc;
use tracing::{trace, warn};

use reth_revm as _;
use tokio::sync::Mutex;

/// The capability to perform [EIP-7702][eip-7702] delegations, sponsored by the sequencer.
///
Expand Down Expand Up @@ -175,6 +176,7 @@ impl<Provider, Eth> AlphaNetWallet<Provider, Eth> {
chain_id,
Capabilities { delegation: DelegationCapability { addresses: valid_designations } },
)])),
permit: Default::default(),
};
Self { inner: Arc::new(inner) }
}
Expand Down Expand Up @@ -244,6 +246,9 @@ where
_ => return Err(AlphaNetWalletError::IllegalDestination.into()),
}

// we acquire the permit here so that all following operations are performed exclusively
let _permit = self.inner.permit.lock().await;

// set nonce
let tx_count = EthState::transaction_count(
&self.inner.eth_api,
Expand Down Expand Up @@ -295,10 +300,12 @@ where
/// Implementation of the AlphaNet `wallet_` namespace.
struct AlphaNetWalletInner<Provider, Eth> {
provider: Provider,
eth_api: Eth,
wallet: EthereumWallet,
chain_id: ChainId,
capabilities: WalletCapabilities,
eth_api: Eth,
/// Used to guard tx signing
permit: Mutex<()>,
}

fn validate_tx_request(request: &TransactionRequest) -> Result<(), AlphaNetWalletError> {
Expand Down

0 comments on commit 7726f7e

Please sign in to comment.