@@ -9,7 +9,8 @@ use alloy_signer_local::{MnemonicBuilder, PrivateKeySigner, coins_bip39::English
99use alloy_signer_trezor:: { HDPath as TrezorHDPath , TrezorSigner } ;
1010use alloy_sol_types:: { Eip712Domain , SolStruct } ;
1111use async_trait:: async_trait;
12- use std:: path:: PathBuf ;
12+ use std:: { collections:: HashSet , path:: PathBuf } ;
13+ use tracing:: warn;
1314
1415#[ cfg( feature = "aws-kms" ) ]
1516use alloy_signer_aws:: { AwsSigner , aws_config:: BehaviorVersion , aws_sdk_kms:: Client as AwsClient } ;
@@ -129,47 +130,61 @@ impl WalletSigner {
129130 /// - the result for Ledger signers includes addresses available for both LedgerLive and Legacy
130131 /// derivation paths
131132 /// - for Local and AWS signers the result contains a single address
133+ /// - errors when retrieving addresses are logged but do not prevent returning available
134+ /// addresses
132135 pub async fn available_senders ( & self , max : usize ) -> Result < Vec < Address > > {
133- let mut senders = Vec :: new ( ) ;
136+ let mut senders = HashSet :: new ( ) ;
137+
134138 match self {
135139 Self :: Local ( local) => {
136- senders. push ( local. address ( ) ) ;
140+ senders. insert ( local. address ( ) ) ;
137141 }
138142 Self :: Ledger ( ledger) => {
143+ // Try LedgerLive derivation path
139144 for i in 0 ..max {
140- if let Ok ( address) =
141- ledger. get_address_with_path ( & LedgerHDPath :: LedgerLive ( i) ) . await
142- {
143- senders. push ( address) ;
145+ match ledger. get_address_with_path ( & LedgerHDPath :: LedgerLive ( i) ) . await {
146+ Ok ( address) => {
147+ senders. insert ( address) ;
148+ }
149+ Err ( e) => {
150+ warn ! ( "Failed to get Ledger address at index {i} (LedgerLive): {e}" ) ;
151+ }
144152 }
145153 }
154+ // Try Legacy derivation path
146155 for i in 0 ..max {
147- if let Ok ( address) =
148- ledger. get_address_with_path ( & LedgerHDPath :: Legacy ( i) ) . await
149- {
150- senders. push ( address) ;
156+ match ledger. get_address_with_path ( & LedgerHDPath :: Legacy ( i) ) . await {
157+ Ok ( address) => {
158+ senders. insert ( address) ;
159+ }
160+ Err ( e) => {
161+ warn ! ( "Failed to get Ledger address at index {i} (Legacy): {e}" ) ;
162+ }
151163 }
152164 }
153165 }
154166 Self :: Trezor ( trezor) => {
155167 for i in 0 ..max {
156- if let Ok ( address) =
157- trezor. get_address_with_path ( & TrezorHDPath :: TrezorLive ( i) ) . await
158- {
159- senders. push ( address) ;
168+ match trezor. get_address_with_path ( & TrezorHDPath :: TrezorLive ( i) ) . await {
169+ Ok ( address) => {
170+ senders. insert ( address) ;
171+ }
172+ Err ( e) => {
173+ warn ! ( "Failed to get Trezor address at index {i} (TrezorLive): {e}" , ) ;
174+ }
160175 }
161176 }
162177 }
163178 #[ cfg( feature = "aws-kms" ) ]
164179 Self :: Aws ( aws) => {
165- senders. push ( alloy_signer:: Signer :: address ( aws) ) ;
180+ senders. insert ( alloy_signer:: Signer :: address ( aws) ) ;
166181 }
167182 #[ cfg( feature = "gcp-kms" ) ]
168183 Self :: Gcp ( gcp) => {
169- senders. push ( alloy_signer:: Signer :: address ( gcp) ) ;
184+ senders. insert ( alloy_signer:: Signer :: address ( gcp) ) ;
170185 }
171186 }
172- Ok ( senders)
187+ Ok ( senders. into_iter ( ) . collect ( ) )
173188 }
174189
175190 pub fn from_mnemonic (
0 commit comments