Skip to main content

ark_client/
wallet.rs

1use crate::error::Error;
2use ark_core::UtxoCoinSelection;
3use bitcoin::Address;
4use bitcoin::Amount;
5use bitcoin::FeeRate;
6use bitcoin::Psbt;
7use std::future::Future;
8
9// TODO: I think we should get rid of `OnchainWallet` and just use `KeyProvider` plus explicit
10// on-chain coin selection/signing dependencies.
11
12pub trait OnchainWallet {
13    fn get_onchain_address(&self) -> Result<Address, Error>;
14
15    fn sync(&self) -> impl Future<Output = Result<(), Error>>;
16
17    fn balance(&self) -> Result<Balance, Error>;
18
19    fn prepare_send_to_address(
20        &self,
21        address: Address,
22        amount: Amount,
23        fee_rate: FeeRate,
24    ) -> Result<Psbt, Error>;
25
26    fn sign(&self, psbt: &mut Psbt) -> Result<bool, Error>;
27
28    fn select_coins(&self, target_amount: Amount) -> Result<UtxoCoinSelection, Error>;
29}
30
31#[derive(Debug, Clone, Copy)]
32pub struct Balance {
33    /// All coinbase outputs not yet matured
34    pub immature: Amount,
35    /// Unconfirmed UTXOs generated by a wallet tx
36    pub trusted_pending: Amount,
37    /// Unconfirmed UTXOs received from an external wallet
38    pub untrusted_pending: Amount,
39    /// Confirmed and immediately spendable balance
40    pub confirmed: Amount,
41}