ord/subcommand/wallet/
create.rs1use {
2 super::*,
3 bitcoin::secp256k1::rand::{self, RngCore},
4};
5
6#[derive(Serialize, Deserialize)]
7pub struct Output {
8 pub mnemonic: Mnemonic,
9 pub passphrase: Option<String>,
10}
11
12#[derive(Debug, Parser)]
13pub(crate) struct Create {
14 #[arg(
15 long,
16 default_value = "",
17 help = "Use <PASSPHRASE> to derive wallet seed."
18 )]
19 pub(crate) passphrase: String,
20}
21
22impl Create {
23 pub(crate) fn run(self, name: String, settings: &Settings) -> SubcommandResult {
24 let mut entropy = [0; 16];
25 rand::thread_rng().fill_bytes(&mut entropy);
26
27 let mnemonic = Mnemonic::from_entropy(&entropy)?;
28
29 Wallet::initialize(name, settings, mnemonic.to_seed(&self.passphrase))?;
30
31 Ok(Some(Box::new(Output {
32 mnemonic,
33 passphrase: Some(self.passphrase),
34 })))
35 }
36}