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;
2321use 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 } ;
2725use alloy_rpc_types:: TransactionRequest ;
2826use 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" ) ) ]
7857pub 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) ]
368326mod 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