-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dump and restore wallet from descriptors (#3048)
- Loading branch information
Showing
14 changed files
with
339 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
use super::*; | ||
|
||
pub(crate) fn run(wallet: Wallet) -> SubcommandResult { | ||
eprintln!( | ||
"========================================== | ||
= THIS STRING CONTAINS YOUR PRIVATE KEYS = | ||
= DO NOT SHARE WITH ANYONE = | ||
==========================================" | ||
); | ||
|
||
Ok(Some(Box::new( | ||
wallet.bitcoin_client()?.list_descriptors(Some(true))?, | ||
))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,61 @@ | ||
use super::*; | ||
|
||
#[derive(Debug, Parser)] | ||
#[clap(group( | ||
ArgGroup::new("source").required(true).args(&["descriptor", "mnemonic"])) | ||
)] | ||
pub(crate) struct Restore { | ||
#[arg(help = "Restore wallet from <MNEMONIC>")] | ||
mnemonic: Mnemonic, | ||
#[arg(long, help = "Restore wallet from <DESCRIPTOR> from stdin.")] | ||
descriptor: bool, | ||
#[arg(long, help = "Restore wallet from <MNEMONIC>.")] | ||
mnemonic: Option<Mnemonic>, | ||
#[arg( | ||
long, | ||
default_value = "", | ||
requires = "mnemonic", | ||
help = "Use <PASSPHRASE> when deriving wallet" | ||
)] | ||
pub(crate) passphrase: String, | ||
pub(crate) passphrase: Option<String>, | ||
} | ||
|
||
impl Restore { | ||
pub(crate) fn run(self, wallet: Wallet) -> SubcommandResult { | ||
wallet.initialize(self.mnemonic.to_seed(self.passphrase))?; | ||
ensure!(!wallet.exists()?, "wallet `{}` already exists", wallet.name); | ||
|
||
if self.descriptor { | ||
let mut buffer = Vec::new(); | ||
std::io::stdin().read_to_end(&mut buffer)?; | ||
|
||
let wallet_descriptors: ListDescriptorsResult = serde_json::from_slice(&buffer)?; | ||
|
||
wallet.initialize_from_descriptors(wallet_descriptors.descriptors)?; | ||
} else if let Some(mnemonic) = self.mnemonic { | ||
wallet.initialize(mnemonic.to_seed(self.passphrase.unwrap_or_default()))?; | ||
} else { | ||
unreachable!(); | ||
} | ||
|
||
Ok(None) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn descriptor_and_mnemonic_conflict() { | ||
assert_regex_match!( | ||
Arguments::try_parse_from([ | ||
"ord", | ||
"wallet", | ||
"restore", | ||
"--descriptor", | ||
"--mnemonic", | ||
"oil oil oil oil oil oil oil oil oil oil oil oil" | ||
]) | ||
.unwrap_err() | ||
.to_string(), | ||
".*--descriptor.*cannot be used with.*--mnemonic.*" | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.