Skip to main content

bark_json/cli/
onchain.rs

1use bitcoin::{Amount, Txid};
2#[cfg(feature = "utoipa")]
3use utoipa::ToSchema;
4
5#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
6#[cfg_attr(feature = "utoipa", derive(ToSchema))]
7pub struct Send {
8	#[cfg_attr(feature = "utoipa", schema(value_type = String))]
9	pub txid: Txid,
10}
11
12#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
13#[cfg_attr(feature = "utoipa", derive(ToSchema))]
14pub struct Address {
15	#[cfg_attr(feature = "utoipa", schema(value_type = String))]
16	pub address: bitcoin::Address<bitcoin::address::NetworkUnchecked>,
17}
18
19#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
20#[cfg_attr(feature = "utoipa", derive(ToSchema))]
21pub struct OnchainBalance {
22	/// All of them combined.
23	#[serde(rename="total_sat", with="bitcoin::amount::serde::as_sat")]
24	#[cfg_attr(feature = "utoipa", schema(value_type = u64))]
25	pub total: Amount,
26	/// Get sum of trusted_pending and confirmed coins.
27	///
28	/// This is the balance you can spend right now that shouldn't get canceled via another party
29	/// double spending it.
30	#[serde(rename="trusted_spendable_sat", with="bitcoin::amount::serde::as_sat")]
31	#[cfg_attr(feature = "utoipa", schema(value_type = u64))]
32	pub trusted_spendable: Amount,
33	/// All coinbase outputs not yet matured
34	#[serde(rename="immature_sat", with="bitcoin::amount::serde::as_sat")]
35	#[cfg_attr(feature = "utoipa", schema(value_type = u64))]
36	pub immature: Amount,
37	/// Unconfirmed UTXOs generated by a wallet tx
38	#[serde(rename="trusted_pending_sat", with="bitcoin::amount::serde::as_sat")]
39	#[cfg_attr(feature = "utoipa", schema(value_type = u64))]
40	pub trusted_pending: Amount,
41	/// Unconfirmed UTXOs received from an external wallet
42	#[serde(rename="untrusted_pending_sat", with="bitcoin::amount::serde::as_sat")]
43	#[cfg_attr(feature = "utoipa", schema(value_type = u64))]
44	pub untrusted_pending: Amount,
45	/// Confirmed and immediately spendable balance
46	#[serde(rename="confirmed_sat", with="bitcoin::amount::serde::as_sat")]
47	#[cfg_attr(feature = "utoipa", schema(value_type = u64))]
48	pub confirmed: Amount,
49}
50
51impl From<bark::onchain::bdk_wallet::Balance> for OnchainBalance {
52	fn from(b: bark::onchain::bdk_wallet::Balance) -> Self {
53		OnchainBalance {
54			total: b.total(),
55			trusted_spendable: b.trusted_spendable(),
56			immature: b.immature,
57			trusted_pending: b.trusted_pending,
58			untrusted_pending: b.untrusted_pending,
59			confirmed: b.confirmed,
60		}
61	}
62}