main.rs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. use clap::{IntoApp, Parser, Subcommand};
  2. use url::Url;
  3. use darkfi::{rpc::client::RpcClient, Result};
  4. mod rpc;
  5. #[derive(Subcommand)]
  6. pub enum CliDaoSubCommands {
  7. /// Create DAO
  8. Create {},
  9. /// Airdrop tokens
  10. Airdrop {},
  11. /// Propose
  12. Propose {},
  13. /// Vote
  14. Vote {},
  15. /// Execute
  16. Exec {},
  17. }
  18. /// DAO cli
  19. #[derive(Parser)]
  20. #[clap(name = "dao")]
  21. #[clap(arg_required_else_help(true))]
  22. pub struct CliDao {
  23. /// Increase verbosity
  24. #[clap(short, parse(from_occurrences))]
  25. pub verbose: u8,
  26. #[clap(subcommand)]
  27. pub command: Option<CliDaoSubCommands>,
  28. }
  29. pub struct Rpc {
  30. client: RpcClient,
  31. }
  32. async fn start(options: CliDao) -> Result<()> {
  33. let rpc_addr = "tcp://127.0.0.1:7777";
  34. let client = Rpc { client: RpcClient::new(Url::parse(rpc_addr)?).await? };
  35. match options.command {
  36. Some(CliDaoSubCommands::Create {}) => {
  37. let reply = client.create().await?;
  38. println!("Server replied: {}", &reply.to_string());
  39. return Ok(())
  40. }
  41. Some(CliDaoSubCommands::Airdrop {}) => {
  42. let reply = client.airdrop().await?;
  43. println!("Server replied: {}", &reply.to_string());
  44. return Ok(())
  45. }
  46. Some(CliDaoSubCommands::Propose {}) => {
  47. let reply = client.propose().await?;
  48. println!("Server replied: {}", &reply.to_string());
  49. return Ok(())
  50. }
  51. Some(CliDaoSubCommands::Vote {}) => {
  52. let reply = client.vote().await?;
  53. println!("Server replied: {}", &reply.to_string());
  54. return Ok(())
  55. }
  56. Some(CliDaoSubCommands::Exec {}) => {
  57. let reply = client.exec().await?;
  58. println!("Server replied: {}", &reply.to_string());
  59. return Ok(())
  60. }
  61. None => {}
  62. }
  63. Ok(())
  64. }
  65. #[async_std::main]
  66. async fn main() -> Result<()> {
  67. let args = CliDao::parse();
  68. let _matches = CliDao::command().get_matches();
  69. //let config_path = if args.config.is_some() {
  70. // expand_path(&args.config.clone().unwrap())?
  71. //} else {
  72. // join_config_path(&PathBuf::from("drk.toml"))?
  73. //};
  74. // Spawn config file if it's not in place already.
  75. //spawn_config(&config_path, CONFIG_FILE_CONTENTS)?;
  76. //let (lvl, conf) = log_config(matches)?;
  77. //TermLogger::init(lvl, conf, TerminalMode::Mixed, ColorChoice::Auto)?;
  78. //let config = Config::<DrkConfig>::load(config_path)?;
  79. start(args).await
  80. }