#[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, Transaction, Txid
};
use ark::Vtxo;
use ark::vtxo::Full;
use bitcoin_ext::{BlockHeight, BlockRef};
use crate::chain::ChainSource;
#[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 SignPsbt {
async fn finish_tx(&mut self, psbt: Psbt) -> anyhow::Result<Transaction>;
}
pub trait GetBalance {
fn get_balance(&self) -> Amount;
}
pub trait GetWalletTx {
fn get_wallet_tx(&self, txid: Txid) -> Option<Arc<Transaction>>;
fn get_wallet_tx_confirmed_block(&self, txid: Txid) -> anyhow::Result<Option<BlockRef>>;
}
pub trait PreparePsbt {
fn prepare_tx(
&mut self,
destinations: &[(Address, Amount)],
fee_rate: FeeRate,
) -> anyhow::Result<Psbt>;
fn prepare_drain_tx(
&mut self,
destination: Address,
fee_rate: FeeRate,
) -> anyhow::Result<Psbt>;
}
pub trait GetSpendingTx {
fn get_spending_tx(&self, outpoint: OutPoint) -> Option<Arc<Transaction>>;
}
#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
pub trait MakeCpfp {
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>;
}
pub trait Board: PreparePsbt + SignPsbt + GetWalletTx + Send + Sync {}
impl <W: PreparePsbt + SignPsbt + GetWalletTx + Send + Sync> Board for W {}
pub trait ExitUnilaterally:
GetBalance +
GetWalletTx +
MakeCpfp +
SignPsbt +
GetSpendingTx +
Send + Sync + {}
impl <W: GetBalance +
GetWalletTx +
MakeCpfp +
SignPsbt +
GetSpendingTx +
Send + Sync> ExitUnilaterally for W {}
#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
pub trait ChainSync {
async fn sync(&mut self, chain: &ChainSource) -> anyhow::Result<()>;
}
pub trait DaemonizableOnchainWallet: ExitUnilaterally + ChainSync {}
impl <W: ExitUnilaterally + ChainSync> DaemonizableOnchainWallet for W {}