pub fn update_devices(&self) -> Result<usize, RemoteWalletError> {
        let mut usb = self.usb.lock();
        usb.refresh_devices()?;
        let devices = usb.device_list();
        let num_prev_devices = self.devices.read().len();

        let mut detected_devices = vec![];
        let mut errors = vec![];
        for device_info in devices.filter(|&device_info| {
            is_valid_hid_device(device_info.usage_page(), device_info.interface_number())
                && is_valid_ledger(device_info.vendor_id(), device_info.product_id())
        }) {
            match usb.open_path(device_info.path()) {
                Ok(device) => {
                    let mut ledger = LedgerWallet::new(device);
                    let result = ledger.read_device(device_info);
                    match result {
                        Ok(info) => {
                            ledger.pretty_path = info.get_pretty_path();
                            let path = device_info.path().to_str().unwrap().to_string();
                            trace!("Found device: {:?}", info);
                            detected_devices.push(Device {
                                path,
                                info,
                                wallet_type: RemoteWalletType::Ledger(Arc::new(ledger)),
                            })
                        }
                        Err(err) => {
                            error!("Error connecting to ledger device to read info: {}", err);
                            errors.push(err)
                        }
                    }
                }
                Err(err) => error!("Error connecting to ledger device to read info: {}", err),
            }
        }

        let num_curr_devices = detected_devices.len();
        *self.devices.write() = detected_devices;

        if num_curr_devices == 0 && !errors.is_empty() {
            return Err(errors[0].clone());
        }

        Ok(num_curr_devices - num_prev_devices)
    }
/// Repopulate device list
/// Note: this method iterates over and updates all devices
Repopulate device list
Note: this method iterates over and updates all devices
Repopulate device list Note : this method iterates over and updates all devices
pub fn update_devices(&self) -> Result<usize, RemoteWalletError> {
        let mut usb = self.usb.lock();
        usb.refresh_devices()?;
        let devices = usb.device_list();
        let num_prev_devices = self.devices.read().len();
        let mut detected_devices = vec![];
        let mut errors = vec![];
        for device_info in devices.filter(|&device_info| {
            is_valid_hid_device(device_info.usage_page(), device_info.interface_number())
                && is_valid_ledger(device_info.vendor_id(), device_info.product_id())
        }) {
            match usb.open_path(device_info.path()) {
                Ok(device) => {
                    let mut ledger = LedgerWallet::new(device);
                    let result = ledger.read_device(device_info);
                    match result {
                        Ok(info) => {
                            ledger.pretty_path = info.get_pretty_path();
                            let path = device_info.path().to_str().unwrap().to_string();
                            trace!("Found device: {:?}", info);
                            detected_devices.push(Device {
                                path,
                                info,
                                wallet_type: RemoteWalletType::Ledger(Arc::new(ledger)),
                            })
                        }
                        Err(err) => {
                            error!("Error connecting to ledger device to read info: {}", err);
                            errors.push(err)
                        }
                    }
                }
                Err(err) => error!("Error connecting to ledger device to read info: {}", err),
            }
        }
        let num_curr_devices = detected_devices.len();
        *self.devices.write() = detected_devices;
        if num_curr_devices == 0 && !errors.is_empty() {
            return Err(errors[0].clone());
        }
        Ok(num_curr_devices - num_prev_devices)
    }
pub fn update_devices ( & self ) -> Result < usize , RemoteWalletError > { let mut usb = self . usb . lock ( ) ; usb . refresh_devices ( ) ? ; let devices = usb . device_list ( ) ; let num_prev_devices = self . devices . read ( ) . len ( ) ; let mut detected_devices = vec ! [ ] ; let mut errors = vec ! [ ] ; for device_info in devices . filter ( | & device_info | { is_valid_hid_device ( device_info . usage_page ( ) , device_info . interface_number ( ) ) && is_valid_ledger ( device_info . vendor_id ( ) , device_info . product_id ( ) ) } ) { match usb . open_path ( device_info . path ( ) ) { Ok ( device ) => { let mut ledger = LedgerWallet :: new ( device ) ; let result = ledger . read_device ( device_info ) ; match result { Ok ( info ) => { ledger . pretty_path = info . get_pretty_path ( ) ; let path = device_info . path ( ) . to_str ( ) . unwrap ( ) . to_string ( ) ; trace ! ( " " info ) ; detected_devices . push ( Device { path , info , wallet_type : RemoteWalletType :: Ledger ( Arc :: new ( ledger ) ) , } ) } Err ( err ) => { error ! ( " " err ) ; errors . push ( err ) } } } Err ( err ) => error ! ( " " err ) , } } let num_curr_devices = detected_devices . len ( ) ; * self . devices . write ( ) = detected_devices ; if num_curr_devices == 0 && ! errors . is_empty ( ) { return Err ( errors [ 0 ] . clone ( ) ) ; } Ok ( num_curr_devices - num_prev_devices ) }
Repopulate device list
Note: this method iterates over and updates all devices
Repopulate device list Note : this method iterates over and updates all devices
&self