smplx_sdk/provider/
simplex.rs1use std::collections::HashMap;
2
3use electrsd::bitcoind::bitcoincore_rpc::Auth;
4
5use simplicityhl::elements::{Address, Script, Transaction, Txid};
6
7use crate::provider::SimplicityNetwork;
8use crate::transaction::UTXO;
9
10use super::core::ProviderTrait;
11use super::error::ProviderError;
12use super::{ElementsRpc, EsploraProvider};
13
14pub struct SimplexProvider {
15 pub esplora: EsploraProvider,
16 pub elements: ElementsRpc,
17}
18
19impl SimplexProvider {
20 pub fn new(esplora_url: String, elements_url: String, auth: Auth, network: SimplicityNetwork) -> Self {
21 Self {
22 esplora: EsploraProvider::new(esplora_url, network),
23 elements: ElementsRpc::new(elements_url, auth).unwrap(),
24 }
25 }
26}
27
28impl ProviderTrait for SimplexProvider {
29 fn get_network(&self) -> &SimplicityNetwork {
30 self.esplora.get_network()
31 }
32
33 fn broadcast_transaction(&self, tx: &Transaction) -> Result<Txid, ProviderError> {
34 let txid = self.esplora.broadcast_transaction(tx)?;
35
36 self.elements.generate_blocks(1)?;
37
38 Ok(txid)
39 }
40
41 fn wait(&self, txid: &Txid) -> Result<(), ProviderError> {
42 self.esplora.wait(txid)
43 }
44
45 fn fetch_tip_height(&self) -> Result<u32, ProviderError> {
46 self.esplora.fetch_tip_height()
47 }
48
49 fn fetch_tip_timestamp(&self) -> Result<u64, ProviderError> {
50 self.esplora.fetch_tip_timestamp()
51 }
52
53 fn fetch_transaction(&self, txid: &Txid) -> Result<Transaction, ProviderError> {
54 self.esplora.fetch_transaction(txid)
55 }
56
57 fn fetch_address_utxos(&self, address: &Address) -> Result<Vec<UTXO>, ProviderError> {
58 self.esplora.fetch_address_utxos(address)
59 }
60
61 fn fetch_scripthash_utxos(&self, script: &Script) -> Result<Vec<UTXO>, ProviderError> {
62 self.esplora.fetch_scripthash_utxos(script)
63 }
64
65 fn fetch_fee_estimates(&self) -> Result<HashMap<String, f64>, ProviderError> {
66 self.esplora.fetch_fee_estimates()
67 }
68}