Some docs on the bitcoin client

This commit is contained in:
Dave Hrycyszyn
2024-06-25 15:02:50 +01:00
parent cf116829f8
commit 7effe9455f

View File

@@ -27,14 +27,19 @@ pub struct EsploraWallet {
} }
impl EsploraWallet { impl EsploraWallet {
/// Builds and signs a send transaction to send coins between addresses.
///
/// Does NOT send it, you must call `broadcast` to do that.
///
/// We could split the creation and signing easily if needed.
pub(crate) fn build_send_tx( pub(crate) fn build_send_tx(
&mut self, &mut self,
faucet_address: Address, recipient: Address,
amount: Amount, amount: Amount,
) -> Result<bitcoin::Transaction, anyhow::Error> { ) -> Result<bitcoin::Transaction, anyhow::Error> {
let mut tx_builder = self.wallet.build_tx(); let mut tx_builder = self.wallet.build_tx();
tx_builder tx_builder
.add_recipient(faucet_address.script_pubkey(), amount) .add_recipient(recipient.script_pubkey(), amount)
.enable_rbf(); .enable_rbf();
let mut psbt = tx_builder.finish()?; let mut psbt = tx_builder.finish()?;
let finalized = self.wallet.sign(&mut psbt, SignOptions::default())?; let finalized = self.wallet.sign(&mut psbt, SignOptions::default())?;
@@ -43,6 +48,7 @@ impl EsploraWallet {
Ok(tx) Ok(tx)
} }
/// Syncs the wallet with the latest state of the Bitcoin blockchain
pub(crate) async fn sync(&mut self) -> Result<(), anyhow::Error> { pub(crate) async fn sync(&mut self) -> Result<(), anyhow::Error> {
print!("Syncing..."); print!("Syncing...");
@@ -94,6 +100,7 @@ impl EsploraWallet {
Ok(()) Ok(())
} }
/// Gets the next unused address from the wallet.
pub(crate) fn next_unused_address(&mut self) -> Result<AddressInfo, anyhow::Error> { pub(crate) fn next_unused_address(&mut self) -> Result<AddressInfo, anyhow::Error> {
let address = self.wallet.next_unused_address(KeychainKind::External); let address = self.wallet.next_unused_address(KeychainKind::External);
if let Some(changeset) = self.wallet.take_staged() { if let Some(changeset) = self.wallet.take_staged() {
@@ -103,10 +110,12 @@ impl EsploraWallet {
Ok(address) Ok(address)
} }
/// Returns the balance of the wallet.
pub(crate) fn balance(&self) -> bdk_wallet::wallet::Balance { pub(crate) fn balance(&self) -> bdk_wallet::wallet::Balance {
self.wallet.balance() self.wallet.balance()
} }
/// Broadcasts a signed transaction to the network.
pub(crate) async fn broadcast( pub(crate) async fn broadcast(
&self, &self,
tx: &bitcoin::Transaction, tx: &bitcoin::Transaction,
@@ -115,6 +124,7 @@ impl EsploraWallet {
} }
} }
/// Creates a Bitcoin Signet descriptor wallet with the mnemonic in the given user directory.
pub(crate) fn create_wallet(name: &str) -> anyhow::Result<EsploraWallet> { pub(crate) fn create_wallet(name: &str) -> anyhow::Result<EsploraWallet> {
let keys_dir = utils::home(name); let keys_dir = utils::home(name);