mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-25 16:25:41 +00:00
Migrate custom error trait impls to thiserror (#1856)
* Migrate to thiserror * missing bits * review comment * Apply suggestions from code review Co-authored-by: Niklas Adolfsson <niklasadolfsson1@gmail.com> * From<scale_decode::visitor::Error> to remove Into::intos * scale crates for core::error::Error * bump msrv 1.81 * make signer crate compile --------- Co-authored-by: Niklas Adolfsson <niklasadolfsson1@gmail.com> Co-authored-by: James Wilson <james.wilson@parity.io>
This commit is contained in:
+5
-17
@@ -6,11 +6,12 @@
|
||||
|
||||
use crate::ecdsa;
|
||||
use alloc::format;
|
||||
use core::fmt::{Display, Formatter};
|
||||
use core::str::FromStr;
|
||||
use keccak_hash::keccak;
|
||||
use secp256k1::Message;
|
||||
|
||||
use thiserror::Error as DeriveError;
|
||||
|
||||
const SECRET_KEY_LENGTH: usize = 32;
|
||||
|
||||
/// Bytes representing a private key.
|
||||
@@ -201,29 +202,16 @@ pub fn verify<M: AsRef<[u8]>>(sig: &Signature, message: M, pubkey: &PublicKey) -
|
||||
}
|
||||
|
||||
/// An error handed back if creating a keypair fails.
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[derive(Debug, PartialEq, DeriveError)]
|
||||
pub enum Error {
|
||||
/// Invalid seed.
|
||||
#[error("Invalid seed (was it the wrong length?)")]
|
||||
InvalidSeed,
|
||||
/// Invalid derivation path.
|
||||
#[error("Could not derive from path; some values in the path may have been >= 2^31?")]
|
||||
DeriveFromPath,
|
||||
}
|
||||
|
||||
impl Display for Error {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
|
||||
match self {
|
||||
Error::InvalidSeed => write!(f, "Invalid seed (was it the wrong length?)"),
|
||||
Error::DeriveFromPath => write!(
|
||||
f,
|
||||
"Could not derive from path; some values in the path may have been >= 2^31?"
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl std::error::Error for Error {}
|
||||
|
||||
/// Dev accounts, helpful for testing but not to be used in production,
|
||||
/// since the secret keys are known.
|
||||
pub mod dev {
|
||||
|
||||
Reference in New Issue
Block a user