use async_trait::async_trait;
use bsv::transaction::chain_tracker::ChainTracker;
use bsv::transaction::Beef;
use crate::error::WalletResult;
use crate::types::Chain;
use super::types::{
BlockHeader, BsvExchangeRate, FiatExchangeRates, GetMerklePathResult, GetRawTxResult,
GetScriptHashHistoryResult, GetStatusForTxidsResult, GetUtxoStatusOutputFormat,
GetUtxoStatusResult, NLockTimeInput, PostBeefResult, ServicesCallHistory,
};
#[async_trait]
pub trait WalletServices: Send + Sync {
fn chain(&self) -> Chain;
async fn get_chain_tracker(&self) -> WalletResult<Box<dyn ChainTracker>>;
async fn get_merkle_path(&self, txid: &str, use_next: bool) -> GetMerklePathResult;
async fn get_raw_tx(&self, txid: &str, use_next: bool) -> GetRawTxResult;
async fn post_beef(&self, beef: &[u8], txids: &[String]) -> Vec<PostBeefResult>;
async fn get_utxo_status(
&self,
output: &str,
output_format: Option<GetUtxoStatusOutputFormat>,
outpoint: Option<&str>,
use_next: bool,
) -> GetUtxoStatusResult;
async fn get_status_for_txids(
&self,
txids: &[String],
use_next: bool,
) -> GetStatusForTxidsResult;
async fn get_script_hash_history(
&self,
hash: &str,
use_next: bool,
) -> GetScriptHashHistoryResult;
async fn hash_to_header(&self, hash: &str) -> WalletResult<BlockHeader>;
async fn get_header_for_height(&self, height: u32) -> WalletResult<Vec<u8>>;
async fn get_height(&self) -> WalletResult<u32>;
async fn n_lock_time_is_final(&self, input: NLockTimeInput) -> WalletResult<bool>;
async fn get_bsv_exchange_rate(&self) -> WalletResult<BsvExchangeRate>;
async fn get_fiat_exchange_rate(&self, currency: &str, base: Option<&str>)
-> WalletResult<f64>;
async fn get_fiat_exchange_rates(
&self,
target_currencies: &[String],
) -> WalletResult<FiatExchangeRates>;
fn get_services_call_history(&self, reset: bool) -> ServicesCallHistory;
async fn get_beef_for_txid(&self, txid: &str) -> WalletResult<Beef>;
fn hash_output_script(&self, script: &[u8]) -> String;
async fn is_utxo(&self, locking_script: &[u8], txid: &str, vout: u32) -> WalletResult<bool>;
}
#[async_trait]
pub trait GetMerklePathProvider: Send + Sync {
fn name(&self) -> &str;
async fn get_merkle_path(
&self,
txid: &str,
services: &dyn WalletServices,
) -> GetMerklePathResult;
}
#[async_trait]
pub trait GetRawTxProvider: Send + Sync {
fn name(&self) -> &str;
async fn get_raw_tx(&self, txid: &str) -> GetRawTxResult;
}
#[async_trait]
pub trait PostBeefProvider: Send + Sync {
fn name(&self) -> &str;
async fn post_beef(&self, beef: &[u8], txids: &[String]) -> PostBeefResult;
}
#[async_trait]
pub trait GetUtxoStatusProvider: Send + Sync {
fn name(&self) -> &str;
async fn get_utxo_status(
&self,
output: &str,
output_format: Option<GetUtxoStatusOutputFormat>,
outpoint: Option<&str>,
) -> GetUtxoStatusResult;
}
#[async_trait]
pub trait GetStatusForTxidsProvider: Send + Sync {
fn name(&self) -> &str;
async fn get_status_for_txids(&self, txids: &[String]) -> GetStatusForTxidsResult;
}
#[async_trait]
pub trait GetScriptHashHistoryProvider: Send + Sync {
fn name(&self) -> &str;
async fn get_script_hash_history(&self, hash: &str) -> GetScriptHashHistoryResult;
}