Skip to main content

ord/subcommand/wallet/
create.rs

1use {
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(
30      name,
31      settings,
32      mnemonic.to_seed(&self.passphrase),
33      bitcoincore_rpc::json::Timestamp::Now,
34    )?;
35
36    Ok(Some(Box::new(Output {
37      mnemonic,
38      passphrase: Some(self.passphrase),
39    })))
40  }
41}