diff --git a/side-node/src/bitcoin/clients/esplora.rs b/side-node/src/bitcoin/clients/esplora.rs index d4ac00f..81b2d79 100644 --- a/side-node/src/bitcoin/clients/esplora.rs +++ b/side-node/src/bitcoin/clients/esplora.rs @@ -27,14 +27,19 @@ pub struct 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( &mut self, - faucet_address: Address, + recipient: Address, amount: Amount, ) -> Result { let mut tx_builder = self.wallet.build_tx(); tx_builder - .add_recipient(faucet_address.script_pubkey(), amount) + .add_recipient(recipient.script_pubkey(), amount) .enable_rbf(); let mut psbt = tx_builder.finish()?; let finalized = self.wallet.sign(&mut psbt, SignOptions::default())?; @@ -43,6 +48,7 @@ impl EsploraWallet { Ok(tx) } + /// Syncs the wallet with the latest state of the Bitcoin blockchain pub(crate) async fn sync(&mut self) -> Result<(), anyhow::Error> { print!("Syncing..."); @@ -94,6 +100,7 @@ impl EsploraWallet { Ok(()) } + /// Gets the next unused address from the wallet. pub(crate) fn next_unused_address(&mut self) -> Result { let address = self.wallet.next_unused_address(KeychainKind::External); if let Some(changeset) = self.wallet.take_staged() { @@ -103,10 +110,12 @@ impl EsploraWallet { Ok(address) } + /// Returns the balance of the wallet. pub(crate) fn balance(&self) -> bdk_wallet::wallet::Balance { self.wallet.balance() } + /// Broadcasts a signed transaction to the network. pub(crate) async fn broadcast( &self, 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 { let keys_dir = utils::home(name);