use crate::{client::InteractionType, protos, transport::error::Error as TransportError};
pub type Result<T, E = Error> = std::result::Result<T, E>;
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("Trezor device not found")]
NoDeviceFound,
#[error("multiple Trezor devices found")]
DeviceNotUnique,
#[error("device returned invalid signature")]
MalformedSignature,
#[error("transport connect: {0}")]
TransportConnect(#[source] TransportError),
#[error("transport beginning session: {0}")]
TransportBeginSession(#[source] TransportError),
#[error("transport ending session: {0}")]
TransportEndSession(#[source] TransportError),
#[error("transport sending message: {0}")]
TransportSendMessage(#[source] TransportError),
#[error("transport receiving message: {0}")]
TransportReceiveMessage(#[source] TransportError),
#[error("received unexpected message type: {0:?}")]
UnexpectedMessageType(protos::MessageType), #[error(transparent)]
Protobuf(#[from] protobuf::Error),
#[error("failure received: code={:?} message=\"{}\"", .0.code(), .0.message())]
FailureResponse(protos::Failure),
#[error("unexpected interaction request: {0:?}")]
UnexpectedInteractionRequest(InteractionType),
#[error("given network is not supported")]
UnsupportedNetwork,
#[error("provided entropy is not 32 bytes")]
InvalidEntropy,
#[error("device referenced non-existing input or output index: {0}")]
TxRequestInvalidIndex(usize),
#[error("PSBT missing input tx: {0}")]
InvalidPsbt(String),
#[cfg(feature = "bitcoin")]
#[error(transparent)]
Base58(#[from] bitcoin::base58::Error),
#[cfg(feature = "bitcoin")]
#[error("device referenced unknown TXID: {0}")]
TxRequestUnknownTxid(bitcoin::hashes::sha256d::Hash),
#[cfg(feature = "bitcoin")]
#[error("PSBT missing input tx: {0}")]
PsbtMissingInputTx(bitcoin::hashes::sha256d::Hash),
#[cfg(feature = "bitcoin")]
#[error("malformed TxRequest: {0:?}")]
MalformedTxRequest(protos::TxRequest),
#[cfg(feature = "bitcoin")]
#[error(transparent)]
BitcoinEncode(#[from] bitcoin::consensus::encode::Error),
#[cfg(feature = "bitcoin")]
#[error(transparent)]
Secp256k1(#[from] bitcoin::secp256k1::Error),
#[cfg(feature = "bitcoin")]
#[error(transparent)]
Bip32(#[from] bitcoin::bip32::Error),
#[cfg(feature = "bitcoin")]
#[error(transparent)]
Address(#[from] bitcoin::address::ParseError),
}