+/// Details about the balance(s) available for spending once the channel appears on chain.
+///
+/// See [`ChannelMonitor::get_claimable_balances`] for more details on when these will or will not
+/// be provided.
+#[must_use]
+#[derive(Clone)]
+#[repr(C)]
+pub enum Balance {
+ /// The channel is not yet closed (or the commitment or closing transaction has not yet
+ /// appeared in a block). The given balance is claimable (less on-chain fees) if the channel is
+ /// force-closed now.
+ ClaimableOnChannelClose {
+ /// The amount available to claim, in satoshis, excluding the on-chain fees which will be
+ /// required to do so.
+ claimable_amount_satoshis: u64,
+ },
+ /// The channel has been closed, and the given balance is ours but awaiting confirmations until
+ /// we consider it spendable.
+ ClaimableAwaitingConfirmations {
+ /// The amount available to claim, in satoshis, possibly excluding the on-chain fees which
+ /// were spent in broadcasting the transaction.
+ claimable_amount_satoshis: u64,
+ /// The height at which an [`Event::SpendableOutputs`] event will be generated for this
+ /// amount.
+ confirmation_height: u32,
+ },
+ /// The channel has been closed, and the given balance should be ours but awaiting spending
+ /// transaction confirmation. If the spending transaction does not confirm in time, it is
+ /// possible our counterparty can take the funds by broadcasting an HTLC timeout on-chain.
+ ///
+ /// Once the spending transaction confirms, before it has reached enough confirmations to be
+ /// considered safe from chain reorganizations, the balance will instead be provided via
+ /// [`Balance::ClaimableAwaitingConfirmations`].
+ ContentiousClaimable {
+ /// The amount available to claim, in satoshis, excluding the on-chain fees which will be
+ /// required to do so.
+ claimable_amount_satoshis: u64,
+ /// The height at which the counterparty may be able to claim the balance if we have not
+ /// done so.
+ timeout_height: u32,
+ },
+ /// HTLCs which we sent to our counterparty which are claimable after a timeout (less on-chain
+ /// fees) if the counterparty does not know the preimage for the HTLCs. These are somewhat
+ /// likely to be claimed by our counterparty before we do.
+ MaybeClaimableHTLCAwaitingTimeout {
+ /// The amount available to claim, in satoshis, excluding the on-chain fees which will be
+ /// required to do so.
+ claimable_amount_satoshis: u64,
+ /// The height at which we will be able to claim the balance if our counterparty has not
+ /// done so.
+ claimable_height: u32,
+ },
+}
+use lightning::chain::channelmonitor::Balance as nativeBalance;
+impl Balance {
+ #[allow(unused)]
+ pub(crate) fn to_native(&self) -> nativeBalance {
+ match self {
+ Balance::ClaimableOnChannelClose {ref claimable_amount_satoshis, } => {
+ let mut claimable_amount_satoshis_nonref = (*claimable_amount_satoshis).clone();
+ nativeBalance::ClaimableOnChannelClose {
+ claimable_amount_satoshis: claimable_amount_satoshis_nonref,
+ }
+ },
+ Balance::ClaimableAwaitingConfirmations {ref claimable_amount_satoshis, ref confirmation_height, } => {
+ let mut claimable_amount_satoshis_nonref = (*claimable_amount_satoshis).clone();
+ let mut confirmation_height_nonref = (*confirmation_height).clone();
+ nativeBalance::ClaimableAwaitingConfirmations {
+ claimable_amount_satoshis: claimable_amount_satoshis_nonref,
+ confirmation_height: confirmation_height_nonref,
+ }
+ },
+ Balance::ContentiousClaimable {ref claimable_amount_satoshis, ref timeout_height, } => {
+ let mut claimable_amount_satoshis_nonref = (*claimable_amount_satoshis).clone();
+ let mut timeout_height_nonref = (*timeout_height).clone();
+ nativeBalance::ContentiousClaimable {
+ claimable_amount_satoshis: claimable_amount_satoshis_nonref,
+ timeout_height: timeout_height_nonref,
+ }
+ },
+ Balance::MaybeClaimableHTLCAwaitingTimeout {ref claimable_amount_satoshis, ref claimable_height, } => {
+ let mut claimable_amount_satoshis_nonref = (*claimable_amount_satoshis).clone();
+ let mut claimable_height_nonref = (*claimable_height).clone();
+ nativeBalance::MaybeClaimableHTLCAwaitingTimeout {
+ claimable_amount_satoshis: claimable_amount_satoshis_nonref,
+ claimable_height: claimable_height_nonref,
+ }
+ },
+ }
+ }
+ #[allow(unused)]
+ pub(crate) fn into_native(self) -> nativeBalance {
+ match self {
+ Balance::ClaimableOnChannelClose {mut claimable_amount_satoshis, } => {
+ nativeBalance::ClaimableOnChannelClose {
+ claimable_amount_satoshis: claimable_amount_satoshis,
+ }
+ },
+ Balance::ClaimableAwaitingConfirmations {mut claimable_amount_satoshis, mut confirmation_height, } => {
+ nativeBalance::ClaimableAwaitingConfirmations {
+ claimable_amount_satoshis: claimable_amount_satoshis,
+ confirmation_height: confirmation_height,
+ }
+ },
+ Balance::ContentiousClaimable {mut claimable_amount_satoshis, mut timeout_height, } => {
+ nativeBalance::ContentiousClaimable {
+ claimable_amount_satoshis: claimable_amount_satoshis,
+ timeout_height: timeout_height,
+ }
+ },
+ Balance::MaybeClaimableHTLCAwaitingTimeout {mut claimable_amount_satoshis, mut claimable_height, } => {
+ nativeBalance::MaybeClaimableHTLCAwaitingTimeout {
+ claimable_amount_satoshis: claimable_amount_satoshis,
+ claimable_height: claimable_height,
+ }
+ },
+ }
+ }
+ #[allow(unused)]
+ pub(crate) fn from_native(native: &nativeBalance) -> Self {
+ match native {
+ nativeBalance::ClaimableOnChannelClose {ref claimable_amount_satoshis, } => {
+ let mut claimable_amount_satoshis_nonref = (*claimable_amount_satoshis).clone();
+ Balance::ClaimableOnChannelClose {
+ claimable_amount_satoshis: claimable_amount_satoshis_nonref,
+ }
+ },
+ nativeBalance::ClaimableAwaitingConfirmations {ref claimable_amount_satoshis, ref confirmation_height, } => {
+ let mut claimable_amount_satoshis_nonref = (*claimable_amount_satoshis).clone();
+ let mut confirmation_height_nonref = (*confirmation_height).clone();
+ Balance::ClaimableAwaitingConfirmations {
+ claimable_amount_satoshis: claimable_amount_satoshis_nonref,
+ confirmation_height: confirmation_height_nonref,
+ }
+ },
+ nativeBalance::ContentiousClaimable {ref claimable_amount_satoshis, ref timeout_height, } => {
+ let mut claimable_amount_satoshis_nonref = (*claimable_amount_satoshis).clone();
+ let mut timeout_height_nonref = (*timeout_height).clone();
+ Balance::ContentiousClaimable {
+ claimable_amount_satoshis: claimable_amount_satoshis_nonref,
+ timeout_height: timeout_height_nonref,
+ }
+ },
+ nativeBalance::MaybeClaimableHTLCAwaitingTimeout {ref claimable_amount_satoshis, ref claimable_height, } => {
+ let mut claimable_amount_satoshis_nonref = (*claimable_amount_satoshis).clone();
+ let mut claimable_height_nonref = (*claimable_height).clone();
+ Balance::MaybeClaimableHTLCAwaitingTimeout {
+ claimable_amount_satoshis: claimable_amount_satoshis_nonref,
+ claimable_height: claimable_height_nonref,
+ }
+ },
+ }
+ }
+ #[allow(unused)]
+ pub(crate) fn native_into(native: nativeBalance) -> Self {
+ match native {
+ nativeBalance::ClaimableOnChannelClose {mut claimable_amount_satoshis, } => {
+ Balance::ClaimableOnChannelClose {
+ claimable_amount_satoshis: claimable_amount_satoshis,
+ }
+ },
+ nativeBalance::ClaimableAwaitingConfirmations {mut claimable_amount_satoshis, mut confirmation_height, } => {
+ Balance::ClaimableAwaitingConfirmations {
+ claimable_amount_satoshis: claimable_amount_satoshis,
+ confirmation_height: confirmation_height,
+ }
+ },
+ nativeBalance::ContentiousClaimable {mut claimable_amount_satoshis, mut timeout_height, } => {
+ Balance::ContentiousClaimable {
+ claimable_amount_satoshis: claimable_amount_satoshis,
+ timeout_height: timeout_height,
+ }
+ },
+ nativeBalance::MaybeClaimableHTLCAwaitingTimeout {mut claimable_amount_satoshis, mut claimable_height, } => {
+ Balance::MaybeClaimableHTLCAwaitingTimeout {
+ claimable_amount_satoshis: claimable_amount_satoshis,
+ claimable_height: claimable_height,
+ }
+ },
+ }
+ }
+}
+/// Frees any resources used by the Balance
+#[no_mangle]
+pub extern "C" fn Balance_free(this_ptr: Balance) { }
+/// Creates a copy of the Balance
+#[no_mangle]
+pub extern "C" fn Balance_clone(orig: &Balance) -> Balance {
+ orig.clone()
+}
+#[no_mangle]
+/// Utility method to constructs a new ClaimableOnChannelClose-variant Balance
+pub extern "C" fn Balance_claimable_on_channel_close(claimable_amount_satoshis: u64) -> Balance {
+ Balance::ClaimableOnChannelClose {
+ claimable_amount_satoshis,
+ }
+}
+#[no_mangle]
+/// Utility method to constructs a new ClaimableAwaitingConfirmations-variant Balance
+pub extern "C" fn Balance_claimable_awaiting_confirmations(claimable_amount_satoshis: u64, confirmation_height: u32) -> Balance {
+ Balance::ClaimableAwaitingConfirmations {
+ claimable_amount_satoshis,
+ confirmation_height,
+ }
+}
+#[no_mangle]
+/// Utility method to constructs a new ContentiousClaimable-variant Balance
+pub extern "C" fn Balance_contentious_claimable(claimable_amount_satoshis: u64, timeout_height: u32) -> Balance {
+ Balance::ContentiousClaimable {
+ claimable_amount_satoshis,
+ timeout_height,
+ }
+}
+#[no_mangle]
+/// Utility method to constructs a new MaybeClaimableHTLCAwaitingTimeout-variant Balance
+pub extern "C" fn Balance_maybe_claimable_htlcawaiting_timeout(claimable_amount_satoshis: u64, claimable_height: u32) -> Balance {
+ Balance::MaybeClaimableHTLCAwaitingTimeout {
+ claimable_amount_satoshis,
+ claimable_height,
+ }
+}
+/// Checks if two Balances contain equal inner contents.
+/// This ignores pointers and is_owned flags and looks at the values in fields.
+#[no_mangle]
+pub extern "C" fn Balance_eq(a: &Balance, b: &Balance) -> bool {
+ if &a.to_native() == &b.to_native() { true } else { false }
+}