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