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

Commit 7726f7e

Browse files
authored
Merge pull request #142 from paradigmxyz/matt/add-permit
feat: add permit
2 parents 0505bce + c6f1039 commit 7726f7e

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/wallet/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ jsonrpsee = { workspace = true, features = ["server", "macros"] }
2323
serde = { workspace = true, features = ["derive"] }
2424
thiserror.workspace = true
2525
tracing.workspace = true
26+
tokio = { workspace = true, features = ["sync"] }
2627

2728
[dev-dependencies]
2829
serde_json.workspace = true

crates/wallet/src/lib.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ use std::sync::Arc;
3434
use tracing::{trace, warn};
3535

3636
use reth_revm as _;
37+
use tokio::sync::Mutex;
3738

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

249+
// we acquire the permit here so that all following operations are performed exclusively
250+
let _permit = self.inner.permit.lock().await;
251+
247252
// set nonce
248253
let tx_count = EthState::transaction_count(
249254
&self.inner.eth_api,
@@ -295,10 +300,12 @@ where
295300
/// Implementation of the AlphaNet `wallet_` namespace.
296301
struct AlphaNetWalletInner<Provider, Eth> {
297302
provider: Provider,
303+
eth_api: Eth,
298304
wallet: EthereumWallet,
299305
chain_id: ChainId,
300306
capabilities: WalletCapabilities,
301-
eth_api: Eth,
307+
/// Used to guard tx signing
308+
permit: Mutex<()>,
302309
}
303310

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

0 commit comments

Comments
 (0)