Skip to main content

ark_client/
wallet.rs

1use crate::error::Error;
2use ark_core::BoardingOutput;
3use ark_core::UtxoCoinSelection;
4use bitcoin::secp256k1::schnorr::Signature;
5use bitcoin::secp256k1::Message;
6use bitcoin::secp256k1::SecretKey;
7use bitcoin::Address;
8use bitcoin::Amount;
9use bitcoin::FeeRate;
10use bitcoin::Network;
11use bitcoin::Psbt;
12use bitcoin::XOnlyPublicKey;
13use std::future::Future;
14
15// TODO: I think we should get rid of `BoardingWallet` and `OnchainWallet` and just use
16// `KeyProvider` for everything! Also, IMO this client doesn't benefit from having an "on-chain
17// wallet" within it.
18
19pub trait BoardingWallet {
20    fn new_boarding_output(
21        &self,
22        server_pubkey: XOnlyPublicKey,
23        exit_delay: bitcoin::Sequence,
24        network: Network,
25    ) -> Result<BoardingOutput, Error>;
26
27    fn get_boarding_outputs(&self) -> Result<Vec<BoardingOutput>, Error>;
28
29    fn sign_for_pk(&self, pk: &XOnlyPublicKey, msg: &Message) -> Result<Signature, Error>;
30}
31
32pub trait OnchainWallet {
33    fn get_onchain_address(&self) -> Result<Address, Error>;
34
35    fn sync(&self) -> impl Future<Output = Result<(), Error>>;
36
37    fn balance(&self) -> Result<Balance, Error>;
38
39    fn prepare_send_to_address(
40        &self,
41        address: Address,
42        amount: Amount,
43        fee_rate: FeeRate,
44    ) -> Result<Psbt, Error>;
45
46    fn sign(&self, psbt: &mut Psbt) -> Result<bool, Error>;
47
48    fn select_coins(&self, target_amount: Amount) -> Result<UtxoCoinSelection, Error>;
49}
50
51pub trait Persistence {
52    fn save_boarding_output(
53        &self,
54        sk: SecretKey,
55        boarding_output: BoardingOutput,
56    ) -> Result<(), Error>;
57
58    fn load_boarding_outputs(&self) -> Result<Vec<BoardingOutput>, Error>;
59
60    fn sk_for_pk(&self, pk: &XOnlyPublicKey) -> Result<SecretKey, Error>;
61}
62
63#[derive(Debug, Clone, Copy)]
64pub struct Balance {
65    /// All coinbase outputs not yet matured
66    pub immature: Amount,
67    /// Unconfirmed UTXOs generated by a wallet tx
68    pub trusted_pending: Amount,
69    /// Unconfirmed UTXOs received from an external wallet
70    pub untrusted_pending: Amount,
71    /// Confirmed and immediately spendable balance
72    pub confirmed: Amount,
73}