Skip to content

Commit

Permalink
Convert TrezorError to string
Browse files Browse the repository at this point in the history
  • Loading branch information
OBorce committed Sep 11, 2024
1 parent a35f2c3 commit 2157893
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions wallet/src/signer/trezor_signer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ pub enum TrezorError {
#[error("No connected Trezor device found")]
NoDeviceFound,
#[error("Trezor device error: {0}")]
DeviceError(#[from] trezor_client::Error),
DeviceError(String),
}

pub struct TrezorSigner {
Expand Down Expand Up @@ -262,7 +262,7 @@ impl Signer for TrezorSigner {
.lock()
.expect("poisoned lock")
.mintlayer_sign_tx(inputs, outputs, utxos)
.map_err(TrezorError::DeviceError)?;
.map_err(|err| TrezorError::DeviceError(err.to_string()))?;

let inputs_utxo_refs: Vec<_> =
ptx.input_utxos().iter().map(|u| u.as_ref().map(|x| &x.utxo)).collect();
Expand Down Expand Up @@ -433,7 +433,7 @@ impl Signer for TrezorSigner {
.lock()
.expect("poisoned lock")
.mintlayer_sign_message(address_n, addr, message)
.map_err(TrezorError::DeviceError)?;
.map_err(|err| TrezorError::DeviceError(err.to_string()))?;
let mut signature = sig;
signature.insert(0, 0);
let signature = Signature::from_data(signature)?;
Expand Down Expand Up @@ -1007,7 +1007,8 @@ impl std::fmt::Debug for TrezorSignerProvider {

impl TrezorSignerProvider {
pub fn new() -> Result<Self, TrezorError> {
let client = find_trezor_device()?;
let client =
find_trezor_device().map_err(|err| TrezorError::DeviceError(err.to_string()))?;

Ok(Self {
client: Arc::new(Mutex::new(client)),
Expand Down Expand Up @@ -1042,7 +1043,7 @@ impl TrezorSignerProvider {
.lock()
.expect("poisoned lock")
.mintlayer_get_public_key(account_path)
.map_err(|e| SignerError::TrezorError(TrezorError::DeviceError(e)))?;
.map_err(|e| SignerError::TrezorError(TrezorError::DeviceError(e.to_string())))?;
let chain_code = ChainCode::from(xpub.chain_code.0);
let account_pubkey = Secp256k1ExtendedPublicKey::new(
derivation_path,
Expand Down Expand Up @@ -1081,7 +1082,7 @@ fn check_public_keys(
fn find_trezor_device() -> Result<Trezor, TrezorError> {
let mut devices = find_devices(false);
let device = devices.pop().ok_or(TrezorError::NoDeviceFound)?;
let client = device.connect()?;
let client = device.connect().map_err(|e| TrezorError::DeviceError(e.to_string()))?;
Ok(client)
}

Expand Down

0 comments on commit 2157893

Please sign in to comment.