From e1e2f49957a510f40e661e80ec13f7961d6f9119 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Mon, 29 Jul 2024 10:11:15 +0100 Subject: [PATCH] Using the keys::load_from_file function --- side-node/src/bitcoin/client.rs | 16 +++++----------- side-node/src/bitcoin/driver/htlc.rs | 1 - side-node/src/bitcoin/htlc.rs | 3 --- 3 files changed, 5 insertions(+), 15 deletions(-) diff --git a/side-node/src/bitcoin/client.rs b/side-node/src/bitcoin/client.rs index b6a0ec1..7bc239a 100644 --- a/side-node/src/bitcoin/client.rs +++ b/side-node/src/bitcoin/client.rs @@ -1,16 +1,14 @@ -use std::fs; - use bdk::{ bitcoin::{psbt::PartiallySignedTransaction, secp256k1::PublicKey, Network, Transaction}, blockchain::EsploraBlockchain, database::MemoryDatabase, - keys::{bip39::Mnemonic, DerivableKey, ExtendedKey}, + keys::ExtendedKey, template::Bip84, wallet::AddressInfo, KeychainKind, SignOptions, SyncOptions, Wallet, }; -use crate::utils; +use crate::{bitcoin::keys, utils}; /// A client that uses Esplora to interact with the Bitcoin network. pub struct BitcoinClient { @@ -79,14 +77,10 @@ impl BitcoinClient { pub(crate) fn create(name: &str, network: Network) -> anyhow::Result { let keys_dir = utils::home(name); - 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 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"); - tracing::info!("Creating {name}'s wallet from mnemonic: {words}"); - let xkey: ExtendedKey = Mnemonic::parse(words) - .expect("couldn't parse mnemonic words") - .into_extended_key() - .expect("couldn't turn mnemonic into extended key"); + let xkey: ExtendedKey = keys::load_from_file(&keys_dir)?; let xprv = xkey .into_xprv(Network::Signet) diff --git a/side-node/src/bitcoin/driver/htlc.rs b/side-node/src/bitcoin/driver/htlc.rs index 848ebb1..5ccfe47 100644 --- a/side-node/src/bitcoin/driver/htlc.rs +++ b/side-node/src/bitcoin/driver/htlc.rs @@ -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 // let htlc = bitcoin::htlc::Htlc::new( - amount, dave.external_public_key, "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff".to_string(), 100, diff --git a/side-node/src/bitcoin/htlc.rs b/side-node/src/bitcoin/htlc.rs index 30dc9b5..1ca8573 100644 --- a/side-node/src/bitcoin/htlc.rs +++ b/side-node/src/bitcoin/htlc.rs @@ -11,7 +11,6 @@ use bdk::{ /// /// Alternately, if the refund timelock expires, the value can be refunded to the refund_identity. pub(crate) struct Htlc { - value: u64, redeem_identity: PublicKey, hashlock: String, refund_timelock: u64, @@ -21,14 +20,12 @@ pub(crate) struct Htlc { impl Htlc { /// Create a new HTLC. pub(crate) fn new( - value: u64, redeem_identity: PublicKey, hashlock: String, refund_timelock: u64, refund_indentiy: PublicKey, ) -> Self { Self { - value, redeem_identity, hashlock, refund_timelock,