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