smplx-sdk 0.0.3

Simplex sdk to simplify the development with simplicity
Documentation
use std::collections::HashMap;

use electrsd::bitcoind::bitcoincore_rpc::Auth;

use simplicityhl::elements::{Address, Script, Transaction, Txid};

use crate::provider::SimplicityNetwork;
use crate::transaction::UTXO;

use super::core::ProviderTrait;
use super::error::ProviderError;
use super::{ElementsRpc, EsploraProvider};

pub struct SimplexProvider {
    pub esplora: EsploraProvider,
    pub elements: ElementsRpc,
}

impl SimplexProvider {
    pub fn new(esplora_url: String, elements_url: String, auth: Auth, network: SimplicityNetwork) -> Self {
        Self {
            esplora: EsploraProvider::new(esplora_url, network),
            elements: ElementsRpc::new(elements_url, auth).unwrap(),
        }
    }
}

impl ProviderTrait for SimplexProvider {
    fn get_network(&self) -> &SimplicityNetwork {
        self.esplora.get_network()
    }

    fn broadcast_transaction(&self, tx: &Transaction) -> Result<Txid, ProviderError> {
        let txid = self.esplora.broadcast_transaction(tx)?;

        self.elements.generate_blocks(1)?;

        Ok(txid)
    }

    fn wait(&self, txid: &Txid) -> Result<(), ProviderError> {
        self.esplora.wait(txid)
    }

    fn fetch_tip_height(&self) -> Result<u32, ProviderError> {
        self.esplora.fetch_tip_height()
    }

    fn fetch_tip_timestamp(&self) -> Result<u64, ProviderError> {
        self.esplora.fetch_tip_timestamp()
    }

    fn fetch_transaction(&self, txid: &Txid) -> Result<Transaction, ProviderError> {
        self.esplora.fetch_transaction(txid)
    }

    fn fetch_address_utxos(&self, address: &Address) -> Result<Vec<UTXO>, ProviderError> {
        self.esplora.fetch_address_utxos(address)
    }

    fn fetch_scripthash_utxos(&self, script: &Script) -> Result<Vec<UTXO>, ProviderError> {
        self.esplora.fetch_scripthash_utxos(script)
    }

    fn fetch_fee_estimates(&self) -> Result<HashMap<String, f64>, ProviderError> {
        self.esplora.fetch_fee_estimates()
    }
}