Skip to content
Snippets Groups Projects
Commit f132287f authored by Nicolas80's avatar Nicolas80
Browse files

Small refactorings from MR comments

parent a5069df9
No related branches found
No related tags found
1 merge request!41Adding db persistence for all SecretFormat of vault keys as well as supporting derivations
...@@ -11,7 +11,7 @@ use sea_orm::{ConnectionTrait, TransactionTrait}; ...@@ -11,7 +11,7 @@ use sea_orm::{ConnectionTrait, TransactionTrait};
use std::io::{Read, Write}; use std::io::{Read, Write};
use std::path::PathBuf; use std::path::PathBuf;
/// define universal dividends subcommands /// vault subcommands
#[derive(Clone, Debug, clap::Parser)] #[derive(Clone, Debug, clap::Parser)]
pub enum Subcommand { pub enum Subcommand {
/// List available SS58 Addresses in the vault /// List available SS58 Addresses in the vault
...@@ -115,7 +115,7 @@ fn decrypt(input: &[u8], passphrase: String) -> Result<Vec<u8>, age::DecryptErro ...@@ -115,7 +115,7 @@ fn decrypt(input: &[u8], passphrase: String) -> Result<Vec<u8>, age::DecryptErro
Ok(decrypted) Ok(decrypted)
} }
/// handle ud commands /// handle vault commands
pub async fn handle_command(data: Data, command: Subcommand) -> Result<(), GcliError> { pub async fn handle_command(data: Data, command: Subcommand) -> Result<(), GcliError> {
// match subcommand // match subcommand
match command { match command {
......
...@@ -112,8 +112,10 @@ pub async fn fetch_vault_derivation<C>(db: &C, address: &str) -> Result<Option<M ...@@ -112,8 +112,10 @@ pub async fn fetch_vault_derivation<C>(db: &C, address: &str) -> Result<Option<M
where where
C: ConnectionTrait, C: ConnectionTrait,
{ {
let derivation = Entity::find_by_id(address.to_owned()).one(db).await?; Entity::find_by_id(address.to_owned())
Ok(derivation) .one(db)
.await
.map_err(GcliError::from)
} }
pub async fn fetch_all_linked_derivations_in_order<C>( pub async fn fetch_all_linked_derivations_in_order<C>(
...@@ -123,36 +125,34 @@ pub async fn fetch_all_linked_derivations_in_order<C>( ...@@ -123,36 +125,34 @@ pub async fn fetch_all_linked_derivations_in_order<C>(
where where
C: ConnectionTrait, C: ConnectionTrait,
{ {
let linked_derivations = Entity::find() Entity::find()
.filter(Column::RootAddress.eq(root_address.to_owned())) .filter(Column::RootAddress.eq(root_address.to_owned()))
.order_by_with_nulls(Column::Path, Order::Asc, NullOrdering::First) .order_by_with_nulls(Column::Path, Order::Asc, NullOrdering::First)
.all(db) .all(db)
.await?; .await
Ok(linked_derivations) .map_err(GcliError::from)
} }
pub async fn list_all_derivations_in_order<C>(db: &C) -> Result<Vec<Model>, GcliError> pub async fn list_all_derivations_in_order<C>(db: &C) -> Result<Vec<Model>, GcliError>
where where
C: ConnectionTrait, C: ConnectionTrait,
{ {
let derivations = Entity::find() Entity::find()
.order_by_asc(Column::RootAddress) .order_by_asc(Column::RootAddress)
.order_by_with_nulls(Column::Path, Order::Asc, NullOrdering::First) .order_by_with_nulls(Column::Path, Order::Asc, NullOrdering::First)
.all(db) .all(db)
.await?; .await
.map_err(GcliError::from)
Ok(derivations)
} }
pub async fn list_all_root_derivations_in_order<C>(db: &C) -> Result<Vec<Model>, GcliError> pub async fn list_all_root_derivations_in_order<C>(db: &C) -> Result<Vec<Model>, GcliError>
where where
C: ConnectionTrait, C: ConnectionTrait,
{ {
let derivations = Entity::find() Entity::find()
.filter(Column::Path.is_null()) .filter(Column::Path.is_null())
.order_by_asc(Column::RootAddress) .order_by_asc(Column::RootAddress)
.all(db) .all(db)
.await?; .await
.map_err(GcliError::from)
Ok(derivations)
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment