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(&self, txids: &[Txid]) -> Result<Vec<Transaction>>;
25
26    /// Get the transactions involved for a script
27    async fn get_script_history(&self, script: &Script) -> Result<Vec<History>>;
28
29    /// Get the transactions involved in a list of scripts.
30    async fn get_scripts_history(&self, scripts: &[&Script]) -> Result<Vec<Vec<History>>>;
31
32    /// Get the transactions involved for a script
33    async fn get_script_history_with_retry(
34        &self,
35        script: &Script,
36        retries: u64,
37    ) -> Result<Vec<History>>;
38
39    /// Get the utxos associated with a script pubkey
40    async fn get_script_utxos(&self, script: &Script) -> Result<Vec<Utxo>>;
41
42    /// Get the utxos associated with a list of scripts
43    async fn get_scripts_utxos(&self, scripts: &[&Script]) -> Result<Vec<Vec<Utxo>>>;
44
45    /// Return the confirmed and unconfirmed balances of a script hash
46    async fn script_get_balance(&self, script: &Script) -> Result<BtcScriptBalance>;
47
48    /// Return the confirmed and unconfirmed balances of a list of script hashes
49    async fn scripts_get_balance(&self, scripts: &[&Script]) -> Result<Vec<BtcScriptBalance>>;
50
51    /// Return the confirmed and unconfirmed balances of a script hash
52    async fn script_get_balance_with_retry(
53        &self,
54        script: &Script,
55        retries: u64,
56    ) -> Result<BtcScriptBalance>;
57
58    /// Verify that a transaction appears in the address script history
59    async fn verify_tx(
60        &self,
61        address: &Address,
62        tx_id: &str,
63        tx_hex: &str,
64        verify_confirmation: bool,
65    ) -> Result<Transaction>;
66
67    /// Get the recommended fees, in sat/vbyte
68    async fn recommended_fees(&self) -> Result<RecommendedFees>;
69}