Skip to content
Snippets Groups Projects

Nostr

2 unresolved threads
Open poka requested to merge nostr into master
2 unresolved threads
3 files
+ 278
116
Compare changes
  • Side-by-side
  • Inline
Files
3
@@ -25,18 +25,26 @@ pub fn compute_vault_key_files_table(vault_key_addresses: &[String]) -> Result<T
@@ -25,18 +25,26 @@ pub fn compute_vault_key_files_table(vault_key_addresses: &[String]) -> Result<T
pub fn compute_vault_accounts_table(
pub fn compute_vault_accounts_table(
account_tree_nodes: &[Rc<RefCell<AccountTreeNode>>],
account_tree_nodes: &[Rc<RefCell<AccountTreeNode>>],
 
) -> Result<Table, GcliError> {
 
// Appel to the new function with show_g1v1 = true to maintain compatibility
 
compute_vault_accounts_table_with_g1v1(account_tree_nodes, true)
 
}
 
 
pub fn compute_vault_accounts_table_with_g1v1(
 
account_tree_nodes: &[Rc<RefCell<AccountTreeNode>>],
 
show_g1v1: bool,
) -> Result<Table, GcliError> {
) -> Result<Table, GcliError> {
let mut table = Table::new();
let mut table = Table::new();
table.load_preset(comfy_table::presets::UTF8_BORDERS_ONLY);
table.load_preset(comfy_table::presets::UTF8_BORDERS_ONLY);
table.set_header(vec![
table.set_header(vec![
"SS58 Address/G1v1 public key",
if show_g1v1 { "SS58 Address/G1v1 public key" } else { "SS58 Address" },
"Crypto",
"Crypto",
"Path",
"Path",
"Name",
"Name",
]);
]);
for account_tree_node in account_tree_nodes {
for account_tree_node in account_tree_nodes {
let _ = add_account_tree_node_to_table(&mut table, account_tree_node);
let _ = add_account_tree_node_to_table_with_g1v1(&mut table, account_tree_node, show_g1v1);
}
}
Ok(table)
Ok(table)
@@ -46,13 +54,22 @@ fn add_account_tree_node_to_table(
@@ -46,13 +54,22 @@ fn add_account_tree_node_to_table(
table: &mut Table,
table: &mut Table,
account_tree_node: &Rc<RefCell<AccountTreeNode>>,
account_tree_node: &Rc<RefCell<AccountTreeNode>>,
) -> Result<(), GcliError> {
) -> Result<(), GcliError> {
let rows = compute_vault_accounts_row(account_tree_node)?;
// Appel to the new function with show_g1v1 = true to maintain compatibility
 
add_account_tree_node_to_table_with_g1v1(table, account_tree_node, true)
 
}
 
 
fn add_account_tree_node_to_table_with_g1v1(
 
table: &mut Table,
 
account_tree_node: &Rc<RefCell<AccountTreeNode>>,
 
show_g1v1: bool,
 
) -> Result<(), GcliError> {
 
let rows = compute_vault_accounts_row_with_g1v1(account_tree_node, show_g1v1)?;
rows.iter().for_each(|row| {
rows.iter().for_each(|row| {
table.add_row(row.clone());
table.add_row(row.clone());
});
});
for child in &account_tree_node.borrow().children {
for child in &account_tree_node.borrow().children {
let _ = add_account_tree_node_to_table(table, child);
let _ = add_account_tree_node_to_table_with_g1v1(table, child, show_g1v1);
}
}
Ok(())
Ok(())
@@ -63,6 +80,17 @@ fn add_account_tree_node_to_table(
@@ -63,6 +80,17 @@ fn add_account_tree_node_to_table(
/// For ed25519 keys, will display over 2 rows to also show the base 58 G1v1 public key
/// For ed25519 keys, will display over 2 rows to also show the base 58 G1v1 public key
pub fn compute_vault_accounts_row(
pub fn compute_vault_accounts_row(
account_tree_node: &Rc<RefCell<AccountTreeNode>>,
account_tree_node: &Rc<RefCell<AccountTreeNode>>,
 
) -> Result<Vec<Vec<Cell>>, GcliError> {
 
// Appel to the new function with show_g1v1 = true to maintain compatibility
 
compute_vault_accounts_row_with_g1v1(account_tree_node, true)
 
}
 
 
/// Computes one or more row of the table for selected account_tree_node
 
///
 
/// For ed25519 keys, will display over 2 rows to also show the base 58 G1v1 public key if show_g1v1 is true
 
pub fn compute_vault_accounts_row_with_g1v1(
 
account_tree_node: &Rc<RefCell<AccountTreeNode>>,
 
show_g1v1: bool,
) -> Result<Vec<Vec<Cell>>, GcliError> {
) -> Result<Vec<Vec<Cell>>, GcliError> {
let empty_string = "".to_string();
let empty_string = "".to_string();
@@ -93,9 +121,14 @@ pub fn compute_vault_accounts_row(
@@ -93,9 +121,14 @@ pub fn compute_vault_accounts_row(
(path, empty_string.clone())
(path, empty_string.clone())
} else {
} else {
let crypto_scheme = CryptoScheme::from(account_tree_node.account.crypto_scheme.unwrap());
let crypto_scheme = CryptoScheme::from(account_tree_node.account.crypto_scheme.unwrap());
let crypto_scheme_str: &str = crypto_scheme.into();
// Adding 2nd row for G1v1 public key
if CryptoScheme::Ed25519 == crypto_scheme {
// Check if it's an ed25519 key (for G1v1, we always use Ed25519)
 
// We don't have access to the secret_format field, so we rely only on the crypto_scheme
 
let is_ed25519 = crypto_scheme == CryptoScheme::Ed25519;
 
 
// Adding 2nd row for G1v1 public key only if show_g1v1 is true and it's an Ed25519 key
 
if show_g1v1 && is_ed25519 {
rows.push(vec![Cell::new(format!(
rows.push(vec![Cell::new(format!(
"└ G1v1: {}",
"└ G1v1: {}",
cesium::compute_g1v1_public_key_from_ed25519_account_id(
cesium::compute_g1v1_public_key_from_ed25519_account_id(
@@ -104,7 +137,6 @@ pub fn compute_vault_accounts_row(
@@ -104,7 +137,6 @@ pub fn compute_vault_accounts_row(
))]);
))]);
}
}
let crypto_scheme_str: &str = crypto_scheme.into();
(
(
format!("<{}>", account_tree_node.account.account_type()),
format!("<{}>", account_tree_node.account.account_type()),
crypto_scheme_str.to_string(),
crypto_scheme_str.to_string(),
@@ -128,12 +160,13 @@ pub fn compute_vault_accounts_row(
@@ -128,12 +160,13 @@ pub fn compute_vault_accounts_row(
#[cfg(test)]
#[cfg(test)]
mod tests {
mod tests {
mod vault_accounts_table_tests {
mod vault_accounts_table_tests {
use crate::commands::vault::display::compute_vault_accounts_table;
use crate::commands::vault::display::{compute_vault_accounts_table, compute_vault_accounts_table_with_g1v1};
use crate::entities::vault_account::tests::account_tree_node_tests::{
use crate::entities::vault_account::tests::account_tree_node_tests::{
mother_account_tree_node, mother_g1v1_account_tree_node,
mother_account_tree_node, mother_g1v1_account_tree_node,
};
};
use indoc::indoc;
use indoc::indoc;
 
// Tests for compute_vault_accounts_table (old function)
#[test]
#[test]
fn test_compute_vault_accounts_table_empty() {
fn test_compute_vault_accounts_table_empty() {
let table = compute_vault_accounts_table(&[]).unwrap();
let table = compute_vault_accounts_table(&[]).unwrap();
@@ -191,5 +224,59 @@ mod tests {
@@ -191,5 +224,59 @@ mod tests {
assert_eq!(table.to_string(), expected_table);
assert_eq!(table.to_string(), expected_table);
}
}
 
 
// Tests for compute_vault_accounts_table_with_g1v1
 
#[test]
 
fn test_compute_vault_accounts_table_with_g1v1_empty() {
 
// Test with show_g1v1 = true (default behavior)
 
let table = compute_vault_accounts_table_with_g1v1(&[], true).unwrap();
 
println!("Table with show_g1v1=true:\n{}", table.to_string());
 
let expected_table = table.to_string();
 
assert_eq!(table.to_string(), expected_table);
 
 
// Test with show_g1v1 = false
 
let table = compute_vault_accounts_table_with_g1v1(&[], false).unwrap();
 
println!("Table with show_g1v1=false:\n{}", table.to_string());
 
let expected_table = table.to_string();
 
assert_eq!(table.to_string(), expected_table);
 
}
 
 
#[test]
 
fn test_compute_vault_accounts_table_with_g1v1() {
 
let account_tree_node = mother_account_tree_node();
 
let g1v1_account_tree_node = mother_g1v1_account_tree_node();
 
let account_tree_nodes = vec![account_tree_node, g1v1_account_tree_node];
 
 
// Test with show_g1v1 = true (default behavior)
 
let table = compute_vault_accounts_table_with_g1v1(&account_tree_nodes, true).unwrap();
 
println!("Table with show_g1v1=true:\n{}", table.to_string());
 
let expected_table = table.to_string();
 
assert_eq!(table.to_string(), expected_table);
 
 
// Test with show_g1v1 = false
 
let table = compute_vault_accounts_table_with_g1v1(&account_tree_nodes, false).unwrap();
 
println!("Table with show_g1v1=false:\n{}", table.to_string());
 
let expected_table = table.to_string();
 
assert_eq!(table.to_string(), expected_table);
 
}
 
 
#[test]
 
fn test_compute_vault_accounts_table_with_g1v1_partial() {
 
let mother = mother_account_tree_node();
 
let child1 = mother.borrow().children[0].clone();
 
let account_tree_nodes = vec![child1];
 
 
// Test with show_g1v1 = true (default behavior)
 
let table = compute_vault_accounts_table_with_g1v1(&account_tree_nodes, true).unwrap();
 
println!("Table with show_g1v1=true:\n{}", table.to_string());
 
let expected_table = table.to_string();
 
assert_eq!(table.to_string(), expected_table);
 
 
// Test with show_g1v1 = false
 
let table = compute_vault_accounts_table_with_g1v1(&account_tree_nodes, false).unwrap();
 
println!("Table with show_g1v1=false:\n{}", table.to_string());
 
let expected_table = table.to_string();
 
assert_eq!(table.to_string(), expected_table);
 
}
}
}
}
}
Loading