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

Small refactorings from MR comments

parent a5069df9
Branches
Tags
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};
use std::io::{Read, Write};
use std::path::PathBuf;
/// define universal dividends subcommands
/// vault subcommands
#[derive(Clone, Debug, clap::Parser)]
pub enum Subcommand {
/// List available SS58 Addresses in the vault
......@@ -115,7 +115,7 @@ fn decrypt(input: &[u8], passphrase: String) -> Result<Vec<u8>, age::DecryptErro
Ok(decrypted)
}
/// handle ud commands
/// handle vault commands
pub async fn handle_command(data: Data, command: Subcommand) -> Result<(), GcliError> {
// match subcommand
match command {
......
......@@ -112,8 +112,10 @@ pub async fn fetch_vault_derivation<C>(db: &C, address: &str) -> Result<Option<M
where
C: ConnectionTrait,
{
let derivation = Entity::find_by_id(address.to_owned()).one(db).await?;
Ok(derivation)
Entity::find_by_id(address.to_owned())
.one(db)
.await
.map_err(GcliError::from)
}
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
C: ConnectionTrait,
{
let linked_derivations = Entity::find()
Entity::find()
.filter(Column::RootAddress.eq(root_address.to_owned()))
.order_by_with_nulls(Column::Path, Order::Asc, NullOrdering::First)
.all(db)
.await?;
Ok(linked_derivations)
.await
.map_err(GcliError::from)
}
pub async fn list_all_derivations_in_order<C>(db: &C) -> Result<Vec<Model>, GcliError>
where
C: ConnectionTrait,
{
let derivations = Entity::find()
Entity::find()
.order_by_asc(Column::RootAddress)
.order_by_with_nulls(Column::Path, Order::Asc, NullOrdering::First)
.all(db)
.await?;
Ok(derivations)
.await
.map_err(GcliError::from)
}
pub async fn list_all_root_derivations_in_order<C>(db: &C) -> Result<Vec<Model>, GcliError>
where
C: ConnectionTrait,
{
let derivations = Entity::find()
Entity::find()
.filter(Column::Path.is_null())
.order_by_asc(Column::RootAddress)
.all(db)
.await?;
Ok(derivations)
.await
.map_err(GcliError::from)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment