#[cfg(feature = "onchain-bdk")]
mod bdk;
#[cfg(feature = "onchain-bdk")]
pub use bdk_wallet;
pub use bitcoin_ext::cpfp::{CpfpError, MakeCpfpFees};
#[cfg(feature = "onchain-bdk")]
pub use crate::onchain::bdk::{OnchainWallet, TxBuilderExt};
use std::sync::Arc;
use bitcoin::{
Address, Amount, FeeRate, OutPoint, Psbt, Script, SignedAmount, Transaction, Txid,
};
use ark::Vtxo;
use ark::vtxo::Full;
use bitcoin_ext::{BlockHeight, BlockRef};
use crate::chain::ChainSource;
#[derive(Debug, Clone)]
pub struct WalletTxInfo {
pub txid: Txid,
pub tx: Arc<Transaction>,
pub onchain_fees: Option<Amount>,
pub balance_change: SignedAmount,
pub confirmation: Option<BlockRef>,
pub is_cpfp: bool,
}
#[derive(Debug, Clone)]
pub enum Utxo {
Local(LocalUtxo),
Exit(SpendableExit),
}
#[derive(Debug, Clone)]
pub struct LocalUtxo {
pub outpoint: OutPoint,
pub amount: Amount,
pub confirmation_height: Option<BlockHeight>,
}
#[derive(Debug, Clone)]
pub struct SpendableExit {
pub vtxo: Vtxo<Full>,
pub height: BlockHeight,
}
#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
pub trait OnchainWalletTrait: std::any::Any + Send + Sync {
async fn balance(&self) -> Amount;
async fn address(&mut self) -> anyhow::Result<Address>;
async fn sync(&mut self, chain: &ChainSource) -> anyhow::Result<()>;
async fn is_mine(&self, spk: &Script) -> anyhow::Result<bool>;
async fn register_tx(&mut self, tx: &Transaction) -> anyhow::Result<()>;
async fn prepare_tx(
&mut self,
destinations: &[(Address, Amount)],
fee_rate: FeeRate,
) -> anyhow::Result<Psbt>;
async fn prepare_drain_tx(
&mut self,
destination: Address,
fee_rate: FeeRate,
) -> anyhow::Result<Psbt>;
async fn finish_psbt(&mut self, psbt: Psbt) -> anyhow::Result<Psbt>;
async fn make_signed_p2a_cpfp(
&mut self,
tx: &Transaction,
fees: MakeCpfpFees,
) -> Result<Transaction, CpfpError>;
async fn store_signed_p2a_cpfp(&mut self, tx: &Transaction) -> anyhow::Result<(), CpfpError>;
}