Skip to content

Commit 73558f4

Browse files
committed
feat: Remove wallet_getCapabilities (#110)
Closes #99 Removed `get_capabilities` from the `WalletCapabilities` trait In `e2e_tests` the capabilities is initialised manually with the contract address being pulled in from `env` variables. Related PR: ithacaxyz/odyssey#104 (review) ---------
1 parent 99d4df2 commit 73558f4

File tree

3 files changed

+15
-116
lines changed

3 files changed

+15
-116
lines changed

bin/odyssey/src/main.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
//! - `min-trace-logs`: Disables all logs below `trace` level.
2525
2626
use alloy_network::{Ethereum, EthereumWallet, NetworkWallet};
27-
use alloy_primitives::Address;
2827
use alloy_signer_local::PrivateKeySigner;
2928
use clap::Parser;
3029
use eyre::Context;
@@ -91,21 +90,12 @@ fn main() {
9190

9291
// register traverse wallet namespace
9392
if let Some(wallet) = wallet {
94-
let raw_delegations = std::env::var("EXP1_WHITELIST")
95-
.wrap_err("No EXP0001 delegations specified")?;
96-
let valid_delegations: Vec<Address> = raw_delegations
97-
.split(',')
98-
.map(|addr| Address::parse_checksummed(addr, None))
99-
.collect::<Result<_, _>>()
100-
.wrap_err("No valid EXP0001 delegations specified")?;
101-
10293
ctx.modules.merge_configured(
10394
TraverseWallet::new(
10495
ctx.provider().clone(),
10596
wallet,
10697
ctx.registry.eth_api().clone(),
10798
ctx.config().chain.chain().id(),
108-
valid_delegations,
10999
)
110100
.into_rpc(),
111101
)?;

crates/e2e-tests/src/tests.rs

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
use std::{collections::BTreeMap, sync::LazyLock};
1+
use std::{str::FromStr, sync::LazyLock};
22

33
use alloy::{
44
eips::eip7702::Authorization,
5-
primitives::{b256, Address, B256, U256},
5+
primitives::{b256, Address, B256},
66
providers::{PendingTransactionBuilder, Provider, ProviderBuilder},
77
signers::SignerSync,
88
};
@@ -54,14 +54,11 @@ async fn test_wallet_api() -> Result<(), Box<dyn std::error::Error>> {
5454
"59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d"
5555
))?;
5656

57-
let capabilities: BTreeMap<U256, BTreeMap<String, BTreeMap<String, Vec<Address>>>> =
58-
provider.client().request_noparams("wallet_getCapabilities").await?;
59-
60-
let chain_id = U256::from(provider.get_chain_id().await?);
61-
62-
let delegation_address =
63-
capabilities.get(&chain_id).unwrap().get("delegation").unwrap().get("addresses").unwrap()
64-
[0];
57+
let delegation_address = Address::from_str(
58+
&std::env::var("DELEGATION_ADDRESS")
59+
.unwrap_or_else(|_| "0x90f79bf6eb2c4f870365e785982e1f101e93b906".to_string()),
60+
)
61+
.unwrap();
6562

6663
let auth = Authorization {
6764
chain_id: provider.get_chain_id().await?,
@@ -98,14 +95,11 @@ async fn test_new_wallet_api() -> Result<(), Box<dyn std::error::Error>> {
9895
"59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d"
9996
))?;
10097

101-
let capabilities: BTreeMap<U256, BTreeMap<String, BTreeMap<String, Vec<Address>>>> =
102-
provider.client().request_noparams("wallet_getCapabilities").await?;
103-
104-
let chain_id = U256::from(provider.get_chain_id().await?);
105-
106-
let delegation_address =
107-
capabilities.get(&chain_id).unwrap().get("delegation").unwrap().get("addresses").unwrap()
108-
[0];
98+
let delegation_address = Address::from_str(
99+
&std::env::var("DELEGATION_ADDRESS")
100+
.unwrap_or_else(|_| "0x90f79bf6eb2c4f870365e785982e1f101e93b906".to_string()),
101+
)
102+
.unwrap();
109103

110104
let auth = Authorization {
111105
chain_id: provider.get_chain_id().await?,

crates/wallet/src/lib.rs

Lines changed: 3 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
//!
33
//! Implementations of a custom `wallet_` namespace for Traverse experiment 1.
44
//!
5-
//! - `wallet_getCapabilities` based on [EIP-5792][eip-5792], with the only capability being
6-
//! `delegation`.
75
//! - `traverse_sendTransaction` that can perform sequencer-sponsored [EIP-7702][eip-7702]
86
//! delegations and send other sequencer-sponsored transactions on behalf of EOAs with delegated
97
//! code.
@@ -23,7 +21,7 @@ use alloy_eips::BlockId;
2321
use alloy_network::{
2422
eip2718::Encodable2718, Ethereum, EthereumWallet, NetworkWallet, TransactionBuilder,
2523
};
26-
use alloy_primitives::{map::HashMap, Address, ChainId, TxHash, TxKind, U256, U64};
24+
use alloy_primitives::{Address, ChainId, TxHash, TxKind, U256};
2725
use alloy_rpc_types::TransactionRequest;
2826
use jsonrpsee::{
2927
core::{async_trait, RpcResult},
@@ -53,39 +51,10 @@ pub struct DelegationCapability {
5351
pub addresses: Vec<Address>,
5452
}
5553

56-
/// Wallet capabilities for a specific chain.
57-
#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)]
58-
pub struct Capabilities {
59-
/// The capability to delegate.
60-
pub delegation: DelegationCapability,
61-
}
62-
63-
/// A map of wallet capabilities per chain ID.
64-
// NOTE(onbjerg): We use `U64` to serialize the chain ID as a quantity. This can be changed back to `ChainId` with https://github.com/alloy-rs/alloy/issues/1502
65-
#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)]
66-
pub struct WalletCapabilities(pub HashMap<U64, Capabilities>);
67-
68-
impl WalletCapabilities {
69-
/// Get the capabilities of the wallet API for the specified chain ID.
70-
pub fn get(&self, chain_id: ChainId) -> Option<&Capabilities> {
71-
self.0.get(&U64::from(chain_id))
72-
}
73-
}
74-
7554
/// Traverse `wallet_` RPC namespace.
7655
#[cfg_attr(not(test), rpc(server, namespace = "wallet"))]
7756
#[cfg_attr(test, rpc(server, client, namespace = "wallet"))]
7857
pub trait TraverseWalletApi {
79-
/// Get the capabilities of the wallet.
80-
///
81-
/// Currently the only capability is [`DelegationCapability`].
82-
///
83-
/// See also [EIP-5792][eip-5792].
84-
///
85-
/// [eip-5792]: https://eips.ethereum.org/EIPS/eip-5792
86-
#[method(name = "getCapabilities")]
87-
fn get_capabilities(&self) -> RpcResult<WalletCapabilities>;
88-
8958
/// Send a sequencer-sponsored transaction.
9059
///
9160
/// The transaction will only be processed if:
@@ -172,17 +141,12 @@ impl<Provider, Eth> TraverseWallet<Provider, Eth> {
172141
wallet: EthereumWallet,
173142
eth_api: Eth,
174143
chain_id: ChainId,
175-
valid_designations: Vec<Address>,
176144
) -> Self {
177145
let inner = TraverseWalletInner {
178146
provider,
179147
wallet,
180148
eth_api,
181149
chain_id,
182-
capabilities: WalletCapabilities(HashMap::from_iter([(
183-
U64::from(chain_id),
184-
Capabilities { delegation: DelegationCapability { addresses: valid_designations } },
185-
)])),
186150
permit: Default::default(),
187151
metrics: WalletMetrics::default(),
188152
};
@@ -200,11 +164,6 @@ where
200164
Provider: StateProviderFactory + Send + Sync + 'static,
201165
Eth: FullEthApi + Send + Sync + 'static,
202166
{
203-
fn get_capabilities(&self) -> RpcResult<WalletCapabilities> {
204-
trace!(target: "rpc::wallet", "Serving wallet_getCapabilities");
205-
Ok(self.inner.capabilities.clone())
206-
}
207-
208167
async fn send_transaction(&self, mut request: TransactionRequest) -> RpcResult<TxHash> {
209168
trace!(target: "rpc::wallet", ?request, "Serving traverse_sendTransaction");
210169

@@ -328,7 +287,6 @@ struct TraverseWalletInner<Provider, Eth> {
328287
eth_api: Eth,
329288
wallet: EthereumWallet,
330289
chain_id: ChainId,
331-
capabilities: WalletCapabilities,
332290
/// Used to guard tx signing
333291
permit: Mutex<()>,
334292
/// Metrics for the `wallet_` RPC namespace.
@@ -366,52 +324,9 @@ struct WalletMetrics {
366324

367325
#[cfg(test)]
368326
mod tests {
369-
use crate::{
370-
validate_tx_request, Capabilities, DelegationCapability, TraverseWalletError,
371-
WalletCapabilities,
372-
};
373-
use alloy_primitives::{address, map::HashMap, Address, U256, U64};
327+
use crate::{validate_tx_request, TraverseWalletError};
328+
use alloy_primitives::{Address, U256};
374329
use alloy_rpc_types::TransactionRequest;
375-
376-
#[test]
377-
fn ser() {
378-
let caps = WalletCapabilities(HashMap::from_iter([(
379-
U64::from(0x69420),
380-
Capabilities {
381-
delegation: DelegationCapability {
382-
addresses: vec![address!("90f79bf6eb2c4f870365e785982e1f101e93b906")],
383-
},
384-
},
385-
)]));
386-
assert_eq!(serde_json::to_string(&caps).unwrap(), "{\"0x69420\":{\"delegation\":{\"addresses\":[\"0x90f79bf6eb2c4f870365e785982e1f101e93b906\"]}}}");
387-
}
388-
389-
#[test]
390-
fn de() {
391-
let caps: WalletCapabilities = serde_json::from_str(
392-
r#"{
393-
"0x69420": {
394-
"delegation": {
395-
"addresses": ["0x90f79bf6eb2c4f870365e785982e1f101e93b906"]
396-
}
397-
}
398-
}"#,
399-
)
400-
.expect("could not deser");
401-
402-
assert_eq!(
403-
caps,
404-
WalletCapabilities(HashMap::from_iter([(
405-
U64::from(0x69420),
406-
Capabilities {
407-
delegation: DelegationCapability {
408-
addresses: vec![address!("90f79bf6eb2c4f870365e785982e1f101e93b906")],
409-
},
410-
},
411-
)]))
412-
);
413-
}
414-
415330
#[test]
416331
fn no_value_allowed() {
417332
assert_eq!(

0 commit comments

Comments
 (0)