diff --git a/ledger/src/transports/hid.rs b/ledger/src/transports/hid.rs index 7d61cdd5..c3cd20be 100644 --- a/ledger/src/transports/hid.rs +++ b/ledger/src/transports/hid.rs @@ -78,7 +78,7 @@ struct HidApiWrapper { /// Instantiate with [`new`][TransportNativeHID::new]. pub struct TransportNativeHID { api_mutex: Arc>, - device: HidDevice, + device: Arc>, guard: Mutex, } @@ -172,7 +172,7 @@ impl TransportNativeHID { }; let ledger = TransportNativeHID { - device, + device: Arc::new(Mutex::new(device)), guard: Mutex::new(0), api_mutex: api_mutex.clone(), }; @@ -200,7 +200,8 @@ impl TransportNativeHID { buffer[4] = (sequence_idx & 0xFF) as u8; // sequence_idx big endian buffer[5..5 + chunk.len()].copy_from_slice(chunk); - let result = self.device.write(&buffer); + let device = self.device.lock().unwrap(); + let result = device.write(&buffer); match result { Ok(size) => { @@ -236,9 +237,8 @@ impl TransportNativeHID { let mut answer_buf = vec![]; loop { - let res = self - .device - .read_timeout(&mut response_buffer, LEDGER_TIMEOUT)?; + let device = self.device.lock().unwrap(); + let res = device.read_timeout(&mut response_buffer, LEDGER_TIMEOUT)?; if (sequence_idx == 0 && res < 7) || res < 5 { return Err(NativeTransportError::Comm("Read error. Incomplete header")); diff --git a/ledger/src/transports/mod.rs b/ledger/src/transports/mod.rs index a695a363..c3a547c2 100644 --- a/ledger/src/transports/mod.rs +++ b/ledger/src/transports/mod.rs @@ -31,7 +31,7 @@ cfg_if::cfg_if! { /// transport library. pub struct Ledger(DefaultTransport); -#[async_trait(?Send)] +#[async_trait] /// An asynchronous interface to the Ledger device. It is critical that the device have only one /// connection active, so the `init` function acquires a lock on the device. pub trait LedgerAsync: Sized { @@ -48,7 +48,7 @@ pub trait LedgerAsync: Sized { fn close(self) {} } -#[async_trait(?Send)] +#[async_trait] impl LedgerAsync for Ledger { #[cfg(not(target_arch = "wasm32"))] async fn init() -> Result {