breez_sdk_liquid/chain/bitcoin/
mod.rs

1pub(crate) mod electrum;
2pub(crate) mod esplora;
3
4use anyhow::Result;
5use bitcoin::{Address, Script, Transaction, Txid};
6use maybe_sync::{MaybeSend, MaybeSync};
7
8use crate::{
9    bitcoin,
10    model::{BtcHistory, BtcScriptBalance, RecommendedFees, Utxo},
11};
12
13pub(crate) type History = BtcHistory;
14
15/// Trait implemented by types that can fetch data from a blockchain data source.
16#[sdk_macros::async_trait]
17pub trait BitcoinChainService: MaybeSend + MaybeSync {
18    /// Get the blockchain latest block
19    async fn tip(&self) -> Result<u32>;
20
21    /// Broadcast a transaction
22    async fn broadcast(&self, tx: &Transaction) -> Result<Txid>;
23
24    /// Get a list of transactions
25    async fn get_transactions(&self, txids: &[Txid]) -> Result<Vec<Transaction>>;
26
27    /// Get the transactions involved for a script
28    async fn get_script_history(&self, script: &Script) -> Result<Vec<History>>;
29
30    /// Get the transactions involved in a list of scripts.
31    async fn get_scripts_history(&self, scripts: &[&Script]) -> Result<Vec<Vec<History>>>;
32
33    /// Get the transactions involved for a script
34    async fn get_script_history_with_retry(
35        &self,
36        script: &Script,
37        retries: u64,
38    ) -> Result<Vec<History>>;
39
40    /// Get the utxos associated with a script pubkey
41    async fn get_script_utxos(&self, script: &Script) -> Result<Vec<Utxo>>;
42
43    /// Get the utxos associated with a list of scripts
44    async fn get_scripts_utxos(&self, scripts: &[&Script]) -> Result<Vec<Vec<Utxo>>>;
45
46    /// Return the confirmed and unconfirmed balances of a script hash
47    async fn script_get_balance(&self, script: &Script) -> Result<BtcScriptBalance>;
48
49    /// Return the confirmed and unconfirmed balances of a list of script hashes
50    async fn scripts_get_balance(&self, scripts: &[&Script]) -> Result<Vec<BtcScriptBalance>>;
51
52    /// Return the confirmed and unconfirmed balances of a script hash
53    async fn script_get_balance_with_retry(
54        &self,
55        script: &Script,
56        retries: u64,
57    ) -> Result<BtcScriptBalance>;
58
59    /// Verify that a transaction appears in the address script history
60    async fn verify_tx(
61        &self,
62        address: &Address,
63        tx_id: &str,
64        tx_hex: &str,
65        verify_confirmation: bool,
66    ) -> Result<Transaction>;
67
68    /// Get the recommended fees, in sat/vbyte
69    async fn recommended_fees(&self) -> Result<RecommendedFees>;
70}