derivation_path.rs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. use {
  2. clap::{Arg, ArgMatches},
  3. solana_derivation_path::DerivationPath,
  4. std::error,
  5. };
  6. pub const DEFAULT_DERIVATION_PATH: &str = "m/44'/501'/0'/0'";
  7. pub fn derivation_path_arg<'a>() -> Arg<'a> {
  8. Arg::new("derivation_path")
  9. .long("derivation-path")
  10. .value_name("DERIVATION_PATH")
  11. .takes_value(true)
  12. .min_values(0)
  13. .max_values(1)
  14. .help(
  15. "Derivation path. All indexes will be promoted to hardened. If arg is not presented \
  16. then derivation path will not be used. If arg is presented with empty \
  17. DERIVATION_PATH value then m/44'/501'/0'/0' will be used.",
  18. )
  19. }
  20. pub fn acquire_derivation_path(
  21. matches: &ArgMatches,
  22. ) -> Result<Option<DerivationPath>, Box<dyn error::Error>> {
  23. if matches.try_contains_id("derivation_path")? {
  24. Ok(Some(DerivationPath::from_absolute_path_str(
  25. matches
  26. .try_get_one::<String>("derivation_path")?
  27. .map(|path| path.as_str())
  28. .unwrap_or(DEFAULT_DERIVATION_PATH),
  29. )?))
  30. } else {
  31. Ok(None)
  32. }
  33. }