mirror of
https://github.com/logos-blockchain/lssa.git
synced 2026-08-25 14:51:14 +00:00
feat: add nursery clippy lints
This commit is contained in:
@@ -23,7 +23,7 @@ impl FromStr for ChainIndex {
|
||||
}
|
||||
|
||||
if s == "/" {
|
||||
return Ok(ChainIndex(vec![]));
|
||||
return Ok(Self(vec![]));
|
||||
}
|
||||
|
||||
let uprooted_substring = s.strip_prefix("/").unwrap();
|
||||
@@ -55,14 +55,14 @@ impl Display for ChainIndex {
|
||||
|
||||
impl Default for ChainIndex {
|
||||
fn default() -> Self {
|
||||
ChainIndex::from_str("/").expect("Root parsing failure")
|
||||
Self::from_str("/").expect("Root parsing failure")
|
||||
}
|
||||
}
|
||||
|
||||
impl ChainIndex {
|
||||
#[must_use]
|
||||
pub fn root() -> Self {
|
||||
ChainIndex::default()
|
||||
Self::default()
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
@@ -76,42 +76,42 @@ impl ChainIndex {
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn next_in_line(&self) -> Option<ChainIndex> {
|
||||
pub fn next_in_line(&self) -> Option<Self> {
|
||||
let mut chain = self.0.clone();
|
||||
// ToDo: Add overflow check
|
||||
if let Some(last_p) = chain.last_mut() {
|
||||
*last_p = last_p.checked_add(1)?;
|
||||
}
|
||||
|
||||
Some(ChainIndex(chain))
|
||||
Some(Self(chain))
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn previous_in_line(&self) -> Option<ChainIndex> {
|
||||
pub fn previous_in_line(&self) -> Option<Self> {
|
||||
let mut chain = self.0.clone();
|
||||
if let Some(last_p) = chain.last_mut() {
|
||||
*last_p = last_p.checked_sub(1)?;
|
||||
}
|
||||
|
||||
Some(ChainIndex(chain))
|
||||
Some(Self(chain))
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn parent(&self) -> Option<ChainIndex> {
|
||||
pub fn parent(&self) -> Option<Self> {
|
||||
if self.0.is_empty() {
|
||||
None
|
||||
} else {
|
||||
let last = self.0.len().checked_sub(1)?;
|
||||
Some(ChainIndex(self.0[..last].to_vec()))
|
||||
Some(Self(self.0[..last].to_vec()))
|
||||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn nth_child(&self, child_id: u32) -> ChainIndex {
|
||||
pub fn nth_child(&self, child_id: u32) -> Self {
|
||||
let mut chain = self.0.clone();
|
||||
chain.push(child_id);
|
||||
|
||||
ChainIndex(chain)
|
||||
Self(chain)
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
@@ -131,17 +131,17 @@ impl ChainIndex {
|
||||
Some(res)
|
||||
}
|
||||
|
||||
fn shuffle_iter(&self) -> impl Iterator<Item = ChainIndex> {
|
||||
fn shuffle_iter(&self) -> impl Iterator<Item = Self> {
|
||||
self.0
|
||||
.iter()
|
||||
.permutations(self.0.len())
|
||||
.unique()
|
||||
.map(|item| ChainIndex(item.into_iter().copied().collect()))
|
||||
.map(|item| Self(item.into_iter().copied().collect()))
|
||||
}
|
||||
|
||||
pub fn chain_ids_at_depth(depth: usize) -> impl Iterator<Item = ChainIndex> {
|
||||
let mut stack = vec![ChainIndex(vec![0; depth])];
|
||||
let mut cumulative_stack = vec![ChainIndex(vec![0; depth])];
|
||||
pub fn chain_ids_at_depth(depth: usize) -> impl Iterator<Item = Self> {
|
||||
let mut stack = vec![Self(vec![0; depth])];
|
||||
let mut cumulative_stack = vec![Self(vec![0; depth])];
|
||||
|
||||
while let Some(top_id) = stack.pop() {
|
||||
if let Some(collapsed_id) = top_id.collapse_back() {
|
||||
@@ -155,9 +155,9 @@ impl ChainIndex {
|
||||
cumulative_stack.into_iter().unique()
|
||||
}
|
||||
|
||||
pub fn chain_ids_at_depth_rev(depth: usize) -> impl Iterator<Item = ChainIndex> {
|
||||
let mut stack = vec![ChainIndex(vec![0; depth])];
|
||||
let mut cumulative_stack = vec![ChainIndex(vec![0; depth])];
|
||||
pub fn chain_ids_at_depth_rev(depth: usize) -> impl Iterator<Item = Self> {
|
||||
let mut stack = vec![Self(vec![0; depth])];
|
||||
let mut cumulative_stack = vec![Self(vec![0; depth])];
|
||||
|
||||
while let Some(top_id) = stack.pop() {
|
||||
if let Some(collapsed_id) = top_id.collapse_back() {
|
||||
|
||||
@@ -19,16 +19,13 @@ impl ChildKeysPublic {
|
||||
if 2_u32.pow(31) > cci {
|
||||
// Non-harden
|
||||
hash_input.extend_from_slice(self.cpk.value());
|
||||
hash_input.extend_from_slice(&cci.to_le_bytes());
|
||||
|
||||
hmac_sha512::HMAC::mac(hash_input, self.ccc)
|
||||
} else {
|
||||
// Harden
|
||||
hash_input.extend_from_slice(self.csk.value());
|
||||
hash_input.extend_from_slice(&(cci).to_le_bytes());
|
||||
|
||||
hmac_sha512::HMAC::mac(hash_input, self.ccc)
|
||||
}
|
||||
hash_input.extend_from_slice(&cci.to_le_bytes());
|
||||
|
||||
hmac_sha512::HMAC::mac(hash_input, self.ccc)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -104,17 +104,14 @@ impl NSSAUserData {
|
||||
}
|
||||
|
||||
/// Returns the signing key for public transaction signatures
|
||||
#[must_use]
|
||||
pub fn get_pub_account_signing_key(
|
||||
&self,
|
||||
account_id: nssa::AccountId,
|
||||
) -> Option<&nssa::PrivateKey> {
|
||||
// First seek in defaults
|
||||
if let Some(key) = self.default_pub_account_signing_keys.get(&account_id) {
|
||||
Some(key)
|
||||
// Then seek in tree
|
||||
} else {
|
||||
self.public_key_tree.get_node(account_id).map(Into::into)
|
||||
}
|
||||
self.default_pub_account_signing_keys
|
||||
.get(&account_id)
|
||||
.or_else(|| self.public_key_tree.get_node(account_id).map(Into::into))
|
||||
}
|
||||
|
||||
/// Generated new private key for privacy preserving transactions
|
||||
@@ -137,17 +134,14 @@ impl NSSAUserData {
|
||||
}
|
||||
|
||||
/// Returns the signing key for public transaction signatures
|
||||
#[must_use]
|
||||
pub fn get_private_account(
|
||||
&self,
|
||||
account_id: nssa::AccountId,
|
||||
) -> Option<&(KeyChain, nssa_core::account::Account)> {
|
||||
// First seek in defaults
|
||||
if let Some(key) = self.default_user_private_accounts.get(&account_id) {
|
||||
Some(key)
|
||||
// Then seek in tree
|
||||
} else {
|
||||
self.private_key_tree.get_node(account_id).map(Into::into)
|
||||
}
|
||||
self.default_user_private_accounts
|
||||
.get(&account_id)
|
||||
.or_else(|| self.private_key_tree.get_node(account_id).map(Into::into))
|
||||
}
|
||||
|
||||
/// Returns the signing key for public transaction signatures
|
||||
|
||||
Reference in New Issue
Block a user