mod http_adapter;
#[cfg(test)]
pub mod mock;
pub mod types;
pub use http_adapter::HttpRpcClient;
pub use types::ChainInfo;
use async_trait::async_trait;
use bitcoin::{OutPoint, Txid};
use crate::error::CoreError;
use crate::types::{TxNode, TxOutput};
#[async_trait]
pub trait BitcoinRpc: Send + Sync {
async fn get_transaction(&self, txid: &Txid) -> Result<TxNode, CoreError>;
async fn get_transactions(&self, txids: &[Txid]) -> Result<Vec<TxNode>, CoreError> {
let mut results = Vec::with_capacity(txids.len());
for txid in txids {
results.push(self.get_transaction(txid).await?);
}
Ok(results)
}
async fn get_tx_out(&self, txid: &Txid, vout: u32) -> Result<Option<TxOutput>, CoreError>;
async fn get_tx_outs(
&self,
outpoints: &[OutPoint],
) -> Result<Vec<Option<TxOutput>>, CoreError> {
let mut results = Vec::with_capacity(outpoints.len());
for outpoint in outpoints {
results.push(self.get_tx_out(&outpoint.txid, outpoint.vout).await?);
}
Ok(results)
}
async fn get_blockchain_info(&self) -> Result<ChainInfo, CoreError>;
}