bark-json 0.1.0-beta.6

JSON definitions for the bark APIs
Documentation
use bitcoin::{Amount, Txid};
#[cfg(feature = "utoipa")]
use utoipa::ToSchema;

#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
#[cfg_attr(feature = "utoipa", derive(ToSchema))]
pub struct Send {
	#[cfg_attr(feature = "utoipa", schema(value_type = String))]
	pub txid: Txid,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(ToSchema))]
pub struct Address {
	#[cfg_attr(feature = "utoipa", schema(value_type = String))]
	pub address: bitcoin::Address<bitcoin::address::NetworkUnchecked>,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(ToSchema))]
pub struct OnchainBalance {
	/// All of them combined.
	#[serde(rename="total_sat", with="bitcoin::amount::serde::as_sat")]
	#[cfg_attr(feature = "utoipa", schema(value_type = u64))]
	pub total: Amount,
	/// Get sum of trusted_pending and confirmed coins.
	///
	/// This is the balance you can spend right now that shouldn't get canceled via another party
	/// double spending it.
	#[serde(rename="trusted_spendable_sat", with="bitcoin::amount::serde::as_sat")]
	#[cfg_attr(feature = "utoipa", schema(value_type = u64))]
	pub trusted_spendable: Amount,
	/// All coinbase outputs not yet matured
	#[serde(rename="immature_sat", with="bitcoin::amount::serde::as_sat")]
	#[cfg_attr(feature = "utoipa", schema(value_type = u64))]
	pub immature: Amount,
	/// Unconfirmed UTXOs generated by a wallet tx
	#[serde(rename="trusted_pending_sat", with="bitcoin::amount::serde::as_sat")]
	#[cfg_attr(feature = "utoipa", schema(value_type = u64))]
	pub trusted_pending: Amount,
	/// Unconfirmed UTXOs received from an external wallet
	#[serde(rename="untrusted_pending_sat", with="bitcoin::amount::serde::as_sat")]
	#[cfg_attr(feature = "utoipa", schema(value_type = u64))]
	pub untrusted_pending: Amount,
	/// Confirmed and immediately spendable balance
	#[serde(rename="confirmed_sat", with="bitcoin::amount::serde::as_sat")]
	#[cfg_attr(feature = "utoipa", schema(value_type = u64))]
	pub confirmed: Amount,
}

impl From<bark::onchain::bdk_wallet::Balance> for OnchainBalance {
	fn from(b: bark::onchain::bdk_wallet::Balance) -> Self {
		OnchainBalance {
			total: b.total(),
			trusted_spendable: b.trusted_pending,
			immature: b.immature,
			trusted_pending: b.trusted_pending,
			untrusted_pending: b.untrusted_pending,
			confirmed: b.confirmed,
		}
	}
}