breez_sdk_spark/chain/
mod.rs1use serde::{Deserialize, Serialize};
2use thiserror::Error;
3
4pub mod rest_client;
5
6#[derive(Debug, Error, Clone)]
7#[cfg_attr(feature = "uniffi", derive(uniffi::Error))]
8pub enum ChainServiceError {
9 #[error("Invalid address: {0}")]
10 InvalidAddress(String),
11 #[error("Service connectivity: {0}")]
12 ServiceConnectivity(String),
13 #[error("Generic: {0}")]
14 Generic(String),
15}
16
17impl From<breez_sdk_common::error::ServiceConnectivityError> for ChainServiceError {
18 fn from(value: breez_sdk_common::error::ServiceConnectivityError) -> Self {
19 ChainServiceError::ServiceConnectivity(value.to_string())
20 }
21}
22
23impl From<bitcoin::address::ParseError> for ChainServiceError {
24 fn from(value: bitcoin::address::ParseError) -> Self {
25 ChainServiceError::InvalidAddress(value.to_string())
26 }
27}
28
29#[cfg_attr(feature = "uniffi", uniffi::export(with_foreign))]
30#[macros::async_trait]
31pub trait BitcoinChainService: Send + Sync {
32 async fn get_address_utxos(&self, address: String) -> Result<Vec<Utxo>, ChainServiceError>;
33 async fn get_transaction_status(&self, txid: String) -> Result<TxStatus, ChainServiceError>;
34 async fn get_transaction_hex(&self, txid: String) -> Result<String, ChainServiceError>;
35 async fn broadcast_transaction(&self, tx: String) -> Result<(), ChainServiceError>;
36}
37
38#[derive(Deserialize, Serialize, Clone, Debug, PartialEq, Eq)]
39#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
40pub struct TxStatus {
41 pub confirmed: bool,
42 pub block_height: Option<u32>,
43 pub block_time: Option<u64>,
44}
45
46#[derive(Deserialize, Serialize, Clone, Debug, PartialEq, Eq)]
47#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
48pub struct Utxo {
49 pub txid: String,
50 pub vout: u32,
51 pub value: u64,
52 pub status: TxStatus,
53}