Przeglądaj źródła

drk: simplyfied some naming schemes

skoupidi 2 lat temu
rodzic
commit
1cbddfdf93
3 zmienionych plików z 34 dodań i 38 usunięć
  1. 4 4
      bin/drk/src/cli_util.rs
  2. 19 23
      bin/drk/src/dao.rs
  3. 11 11
      bin/drk/src/main.rs

+ 4 - 4
bin/drk/src/cli_util.rs

@@ -262,16 +262,16 @@ pub fn generate_completions(shell: &str) -> Result<()> {
 
     let view = SubCommand::with_name("view").about("View DAO data from stdin");
 
-    let dao_name = Arg::with_name("dao-name").help("Named identifier for the DAO");
+    let name = Arg::with_name("name").help("Name identifier for the DAO");
 
     let import =
-        SubCommand::with_name("import").about("Import DAO data from stdin").args(&vec![dao_name]);
+        SubCommand::with_name("import").about("Import DAO data from stdin").args(&vec![name]);
 
-    let dao_alias = Arg::with_name("dao-alias").help("Numeric identifier for the DAO (optional)");
+    let name = Arg::with_name("dao-alias").help("Name identifier for the DAO (optional)");
 
     let list = SubCommand::with_name("list")
         .about("List imported DAOs (or info about a specific one)")
-        .args(&vec![dao_alias]);
+        .args(&vec![name]);
 
     let dao_alias = Arg::with_name("dao-alias").help("Name or numeric identifier for the DAO");
 

+ 19 - 23
bin/drk/src/dao.rs

@@ -1068,16 +1068,16 @@ impl Drk {
     }
 
     /// Import given DAO params into the wallet with a given name.
-    pub async fn import_dao(&self, dao_name: &str, dao_params: DaoParams) -> Result<()> {
+    pub async fn import_dao(&self, name: &str, params: DaoParams) -> Result<()> {
         // First let's check if we've imported this DAO with the given name before.
-        if let Ok(dao) = self.get_dao_by_alias(dao_name).await {
+        if let Ok(dao) = self.get_dao_by_name(name).await {
             return Err(Error::RusqliteError(format!(
                 "[import_dao] This DAO has already been imported with ID {}",
                 dao.id
             )))
         }
 
-        println!("Importing \"{dao_name}\" DAO into the wallet");
+        println!("Importing \"{name}\" DAO into the wallet");
 
         let query = format!(
             "INSERT INTO {} ({}, {}, {}, {}, {}, {}, {}, {}) VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8);",
@@ -1096,14 +1096,14 @@ impl Drk {
             .exec_sql(
                 &query,
                 rusqlite::params![
-                    dao_name,
-                    serialize_async(&dao_params.proposer_limit).await,
-                    serialize_async(&dao_params.quorum).await,
-                    dao_params.approval_ratio_base,
-                    dao_params.approval_ratio_quot,
-                    serialize_async(&dao_params.gov_token_id).await,
-                    serialize_async(&dao_params.secret_key).await,
-                    serialize_async(&dao_params.bulla_blind).await,
+                    name,
+                    serialize_async(&params.proposer_limit).await,
+                    serialize_async(&params.quorum).await,
+                    params.approval_ratio_base,
+                    params.approval_ratio_quot,
+                    serialize_async(&params.gov_token_id).await,
+                    serialize_async(&params.secret_key).await,
+                    serialize_async(&params.bulla_blind).await,
                 ],
             )
             .await
@@ -1165,21 +1165,17 @@ impl Drk {
         Ok(dao.clone())
     }
 
-    /// Fetch a DAO given its name alias.
-    pub async fn get_dao_by_alias(&self, alias_filter: &str) -> Result<Dao> {
+    /// Fetch a DAO given its name.
+    pub async fn get_dao_by_name(&self, name: &str) -> Result<Dao> {
         let row = match self
             .wallet
-            .query_single(
-                &DAO_DAOS_TABLE,
-                &[],
-                convert_named_params! {(DAO_DAOS_COL_NAME, alias_filter)},
-            )
+            .query_single(&DAO_DAOS_TABLE, &[], convert_named_params! {(DAO_DAOS_COL_NAME, name)})
             .await
         {
             Ok(r) => r,
             Err(e) => {
                 return Err(Error::RusqliteError(format!(
-                    "[get_dao_by_alias] DAO retrieval failed: {e:?}"
+                    "[get_dao_by_name] DAO retrieval failed: {e:?}"
                 )))
             }
         };
@@ -1187,11 +1183,11 @@ impl Drk {
         self.parse_dao_record(&row).await
     }
 
-    /// List DAO(s) imported in the wallet. If a name aliasis given, just print the
+    /// List DAO(s) imported in the wallet. If a name is given, just print the
     /// metadata for that specific one, if found.
-    pub async fn dao_list(&self, alias_filter: &Option<String>) -> Result<()> {
-        if let Some(alias) = alias_filter {
-            let dao = self.get_dao_by_alias(alias).await?;
+    pub async fn dao_list(&self, name: &Option<String>) -> Result<()> {
+        if let Some(name) = name {
+            let dao = self.get_dao_by_name(name).await?;
             println!("{dao}");
             return Ok(());
         }

+ 11 - 11
bin/drk/src/main.rs

@@ -323,14 +323,14 @@ enum DaoSubcmd {
 
     /// Import DAO data from stdin
     Import {
-        /// Named identifier for the DAO
-        dao_name: String,
+        /// Name identifier for the DAO
+        name: String,
     },
 
     /// List imported DAOs (or info about a specific one)
     List {
-        /// Numeric identifier for the DAO (optional)
-        dao_alias: Option<String>,
+        /// Name identifier for the DAO (optional)
+        name: Option<String>,
     },
 
     /// Show the balance of a DAO
@@ -1041,7 +1041,7 @@ async fn realmain(args: Args, ex: Arc<smol::Executor<'static>>) -> Result<()> {
                 let secret_key = SecretKey::random(&mut OsRng);
                 let bulla_blind = pallas::Base::random(&mut OsRng);
 
-                let dao_params = DaoParams {
+                let params = DaoParams {
                     proposer_limit,
                     quorum,
                     approval_ratio_base,
@@ -1051,7 +1051,7 @@ async fn realmain(args: Args, ex: Arc<smol::Executor<'static>>) -> Result<()> {
                     bulla_blind,
                 };
 
-                let encoded = bs58::encode(&serialize_async(&dao_params).await).into_string();
+                let encoded = bs58::encode(&serialize_async(&params).await).into_string();
                 println!("{encoded}");
 
                 Ok(())
@@ -1067,15 +1067,15 @@ async fn realmain(args: Args, ex: Arc<smol::Executor<'static>>) -> Result<()> {
                 Ok(())
             }
 
-            DaoSubcmd::Import { dao_name } => {
+            DaoSubcmd::Import { name } => {
                 let mut buf = String::new();
                 stdin().read_to_string(&mut buf)?;
                 let bytes = bs58::decode(&buf.trim()).into_vec()?;
-                let dao_params: DaoParams = deserialize_async(&bytes).await?;
+                let params: DaoParams = deserialize_async(&bytes).await?;
 
                 let drk = Drk::new(args.wallet_path, args.wallet_pass, None, ex).await?;
 
-                if let Err(e) = drk.import_dao(&dao_name, dao_params).await {
+                if let Err(e) = drk.import_dao(&name, params).await {
                     eprintln!("Failed to import DAO: {e:?}");
                     exit(2);
                 }
@@ -1083,9 +1083,9 @@ async fn realmain(args: Args, ex: Arc<smol::Executor<'static>>) -> Result<()> {
                 Ok(())
             }
 
-            DaoSubcmd::List { dao_alias } => {
+            DaoSubcmd::List { name } => {
                 let drk = Drk::new(args.wallet_path, args.wallet_pass, None, ex).await?;
-                if let Err(e) = drk.dao_list(&dao_alias).await {
+                if let Err(e) = drk.dao_list(&name).await {
                     eprintln!("Failed to list DAO: {e:?}");
                     exit(2);
                 }