Generating a new wallet with mnemonic works nicely
This commit is contained in:
38
side-node/src/clients/btc_other_rpc.rs
Normal file
38
side-node/src/clients/btc_other_rpc.rs
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
use bdk::{
|
||||||
|
bitcoin::Network,
|
||||||
|
database::MemoryDatabase,
|
||||||
|
keys::{
|
||||||
|
bip39::{Language, Mnemonic, WordCount},
|
||||||
|
DerivableKey, ExtendedKey, GeneratableKey, GeneratedKey,
|
||||||
|
},
|
||||||
|
miniscript,
|
||||||
|
template::Bip84,
|
||||||
|
KeychainKind, Wallet,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub async fn run() -> Result<(), anyhow::Error> {
|
||||||
|
// Generate a new mnemonic
|
||||||
|
let mnemonic: GeneratedKey<_, miniscript::Segwitv0> =
|
||||||
|
Mnemonic::generate((WordCount::Words12, Language::English)).unwrap();
|
||||||
|
let mnemonic_words = mnemonic.to_string();
|
||||||
|
let mnemonic = Mnemonic::parse(&mnemonic_words).unwrap();
|
||||||
|
|
||||||
|
// Generate the extended key
|
||||||
|
let xkey: ExtendedKey = mnemonic.into_extended_key()?;
|
||||||
|
|
||||||
|
// Get private key from the extended key
|
||||||
|
let xprv = xkey.into_xprv(Network::Signet).unwrap();
|
||||||
|
|
||||||
|
// Create a BDK wallet using BIP 84 descriptor ("m/84h/1h/0h/0" and "m/84h/1h/0h/1")
|
||||||
|
let wallet = Wallet::new(
|
||||||
|
Bip84(xprv, KeychainKind::External),
|
||||||
|
Some(Bip84(xprv, KeychainKind::Internal)),
|
||||||
|
Network::Signet,
|
||||||
|
MemoryDatabase::default(),
|
||||||
|
)?;
|
||||||
|
|
||||||
|
let address = wallet.get_address(bdk::wallet::AddressIndex::New)?;
|
||||||
|
println!("Generated Address: {:?}", address);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
@@ -1,2 +1,3 @@
|
|||||||
|
pub mod btc_other_rpc;
|
||||||
pub mod btc_rpc;
|
pub mod btc_rpc;
|
||||||
pub mod websocket;
|
pub mod websocket;
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ pub async fn run() {
|
|||||||
node.start().await;
|
node.start().await;
|
||||||
}
|
}
|
||||||
Some(Commands::Btc {}) => {
|
Some(Commands::Btc {}) => {
|
||||||
let _ = clients::btc_rpc::run().await;
|
let _ = clients::btc_other_rpc::run().await;
|
||||||
}
|
}
|
||||||
None => println!("No command provided. Exiting. See --help for more information."),
|
None => println!("No command provided. Exiting. See --help for more information."),
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user