Using the keys::load_from_file function

This commit is contained in:
Dave Hrycyszyn
2024-07-29 10:11:15 +01:00
parent e4eedbd206
commit e1e2f49957
3 changed files with 5 additions and 15 deletions

View File

@@ -1,16 +1,14 @@
use std::fs;
use bdk::{ use bdk::{
bitcoin::{psbt::PartiallySignedTransaction, secp256k1::PublicKey, Network, Transaction}, bitcoin::{psbt::PartiallySignedTransaction, secp256k1::PublicKey, Network, Transaction},
blockchain::EsploraBlockchain, blockchain::EsploraBlockchain,
database::MemoryDatabase, database::MemoryDatabase,
keys::{bip39::Mnemonic, DerivableKey, ExtendedKey}, keys::ExtendedKey,
template::Bip84, template::Bip84,
wallet::AddressInfo, wallet::AddressInfo,
KeychainKind, SignOptions, SyncOptions, Wallet, KeychainKind, SignOptions, SyncOptions, Wallet,
}; };
use crate::utils; use crate::{bitcoin::keys, utils};
/// A client that uses Esplora to interact with the Bitcoin network. /// A client that uses Esplora to interact with the Bitcoin network.
pub struct BitcoinClient { pub struct BitcoinClient {
@@ -79,14 +77,10 @@ impl BitcoinClient {
pub(crate) fn create(name: &str, network: Network) -> anyhow::Result<BitcoinClient> { pub(crate) fn create(name: &str, network: Network) -> anyhow::Result<BitcoinClient> {
let keys_dir = utils::home(name); let keys_dir = utils::home(name);
let mnemonic_path = crate::utils::side_paths(keys_dir).1; // TODO: this tuple stinks // let mnemonic_path = crate::utils::side_paths(keys_dir).1; // TODO: this tuple stinks
let words = fs::read_to_string(mnemonic_path).expect("couldn't read bitcoin key file"); // let words = fs::read_to_string(mnemonic_path).expect("couldn't read bitcoin key file");
tracing::info!("Creating {name}'s wallet from mnemonic: {words}"); let xkey: ExtendedKey = keys::load_from_file(&keys_dir)?;
let xkey: ExtendedKey = Mnemonic::parse(words)
.expect("couldn't parse mnemonic words")
.into_extended_key()
.expect("couldn't turn mnemonic into extended key");
let xprv = xkey let xprv = xkey
.into_xprv(Network::Signet) .into_xprv(Network::Signet)

View File

@@ -18,7 +18,6 @@ pub(crate) async fn run() -> anyhow::Result<()> {
// Feed it 500 sats, a redeem identity, a hashlock, a refund timelock, and a refund identity // Feed it 500 sats, a redeem identity, a hashlock, a refund timelock, and a refund identity
// //
let htlc = bitcoin::htlc::Htlc::new( let htlc = bitcoin::htlc::Htlc::new(
amount,
dave.external_public_key, dave.external_public_key,
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff".to_string(), "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff".to_string(),
100, 100,

View File

@@ -11,7 +11,6 @@ use bdk::{
/// ///
/// Alternately, if the refund timelock expires, the value can be refunded to the refund_identity. /// Alternately, if the refund timelock expires, the value can be refunded to the refund_identity.
pub(crate) struct Htlc { pub(crate) struct Htlc {
value: u64,
redeem_identity: PublicKey, redeem_identity: PublicKey,
hashlock: String, hashlock: String,
refund_timelock: u64, refund_timelock: u64,
@@ -21,14 +20,12 @@ pub(crate) struct Htlc {
impl Htlc { impl Htlc {
/// Create a new HTLC. /// Create a new HTLC.
pub(crate) fn new( pub(crate) fn new(
value: u64,
redeem_identity: PublicKey, redeem_identity: PublicKey,
hashlock: String, hashlock: String,
refund_timelock: u64, refund_timelock: u64,
refund_indentiy: PublicKey, refund_indentiy: PublicKey,
) -> Self { ) -> Self {
Self { Self {
value,
redeem_identity, redeem_identity,
hashlock, hashlock,
refund_timelock, refund_timelock,