Skip to content

Commit

Permalink
style: Fix formatting and code organization in key_pair.rs and vault.…
Browse files Browse the repository at this point in the history
…rs files
  • Loading branch information
S0c5 committed Apr 30, 2024
1 parent 83e8a59 commit 7e91621
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
5 changes: 3 additions & 2 deletions libwallet/src/key_pair.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use core::{convert::TryInto, fmt::Debug};
use core::{convert::{TryFrom, TryInto}, fmt::Debug};

pub use derive::Derive;

use self::any::AnySignature;
Expand All @@ -21,7 +22,7 @@ impl<const N: usize> Public for Bytes<N> {}

pub trait Signature: AsRef<[u8]> + Debug + PartialEq {
fn as_bytes<const N: usize>(&self) -> Bytes<N> {
self.as_ref().try_into().expect("error")
self.as_ref().try_into().expect("error getting the bytes")
}
}
impl<const N: usize> Signature for Bytes<N> {}
Expand Down
22 changes: 15 additions & 7 deletions libwallet/src/vault.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ mod utils {
const MAX_PATH_LEN: usize = 16;
use arrayvec::ArrayString;

use crate::{account::Account, any::AnySignature, any, Derive, Network, Pair, Public};

use crate::{account::Account, any, any::AnySignature, Derive, Network, Pair, Public};

/// The root account is a container of the key pairs stored in the vault and cannot be
/// used to sign messages directly, we always derive new key pairs from it to create
Expand Down Expand Up @@ -82,7 +81,7 @@ mod utils {
path: ArrayString<MAX_PATH_LEN>,
name: ArrayString<{ MAX_PATH_LEN - 2 }>,
}

impl Account for AccountSigner {
fn public(&self) -> impl Public {
self.pair.as_ref().expect("account unlocked").public()
Expand All @@ -91,13 +90,22 @@ mod utils {

impl AccountSigner {
pub(crate) fn new<'a>(name: impl Into<Option<&'a str>>) -> Self {
let n = name.into().unwrap_or_else(|| "default");
let mut path = ArrayString::from("//").unwrap();
path.push_str(&n);
let n = name.into().unwrap_or_else(|| "");
let mut path = ArrayString::new();

if n == "default" {
path.push_str(n);
}

if n != "default" && !n.is_empty() {
path.push_str("//");
path.push_str(n);
}

AccountSigner {
pair: None,
network: Network::default(),
name: ArrayString::from(&n).expect("short name"),
name: ArrayString::from(n).expect("short name"),
path,
}
}
Expand Down

0 comments on commit 7e91621

Please sign in to comment.