+/// 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.
+#[derive(Clone)]
+#[must_use]
+#[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.
+ MaybeTimeoutClaimableHTLC {
+ /// The amount potentially 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,
+ },
+ /// HTLCs which we received from our counterparty which are claimable with a preimage which we
+ /// do not currently have. This will only be claimable if we receive the preimage from the node
+ /// to which we forwarded this HTLC before the timeout.
+ MaybePreimageClaimableHTLC {
+ /// The amount potentially 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 our counterparty will be able to claim the balance if we have not
+ /// yet received the preimage and claimed it ourselves.
+ expiry_height: u32,
+ },
+ /// The channel has been closed, and our counterparty broadcasted a revoked commitment
+ /// transaction.
+ ///
+ /// Thus, we're able to claim all outputs in the commitment transaction, one of which has the
+ /// following amount.
+ CounterpartyRevokedOutputClaimable {
+ /// The amount, in satoshis, of the output which we can claim.
+ ///
+ /// Note that for outputs from HTLC balances this may be excluding some on-chain fees that
+ /// were already spent.
+ claimable_amount_satoshis: u64,
+ },
+}
+use lightning::chain::channelmonitor::Balance as BalanceImport;
+pub(crate) type nativeBalance = BalanceImport;
+
+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::MaybeTimeoutClaimableHTLC {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::MaybeTimeoutClaimableHTLC {
+ claimable_amount_satoshis: claimable_amount_satoshis_nonref,
+ claimable_height: claimable_height_nonref,
+ }
+ },
+ Balance::MaybePreimageClaimableHTLC {ref claimable_amount_satoshis, ref expiry_height, } => {
+ let mut claimable_amount_satoshis_nonref = (*claimable_amount_satoshis).clone();
+ let mut expiry_height_nonref = (*expiry_height).clone();
+ nativeBalance::MaybePreimageClaimableHTLC {
+ claimable_amount_satoshis: claimable_amount_satoshis_nonref,
+ expiry_height: expiry_height_nonref,
+ }
+ },
+ Balance::CounterpartyRevokedOutputClaimable {ref claimable_amount_satoshis, } => {
+ let mut claimable_amount_satoshis_nonref = (*claimable_amount_satoshis).clone();
+ nativeBalance::CounterpartyRevokedOutputClaimable {
+ claimable_amount_satoshis: claimable_amount_satoshis_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::MaybeTimeoutClaimableHTLC {mut claimable_amount_satoshis, mut claimable_height, } => {
+ nativeBalance::MaybeTimeoutClaimableHTLC {
+ claimable_amount_satoshis: claimable_amount_satoshis,
+ claimable_height: claimable_height,
+ }
+ },
+ Balance::MaybePreimageClaimableHTLC {mut claimable_amount_satoshis, mut expiry_height, } => {
+ nativeBalance::MaybePreimageClaimableHTLC {
+ claimable_amount_satoshis: claimable_amount_satoshis,
+ expiry_height: expiry_height,
+ }
+ },
+ Balance::CounterpartyRevokedOutputClaimable {mut claimable_amount_satoshis, } => {
+ nativeBalance::CounterpartyRevokedOutputClaimable {
+ claimable_amount_satoshis: claimable_amount_satoshis,
+ }
+ },
+ }
+ }
+ #[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::MaybeTimeoutClaimableHTLC {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::MaybeTimeoutClaimableHTLC {
+ claimable_amount_satoshis: claimable_amount_satoshis_nonref,
+ claimable_height: claimable_height_nonref,
+ }
+ },
+ nativeBalance::MaybePreimageClaimableHTLC {ref claimable_amount_satoshis, ref expiry_height, } => {
+ let mut claimable_amount_satoshis_nonref = (*claimable_amount_satoshis).clone();
+ let mut expiry_height_nonref = (*expiry_height).clone();
+ Balance::MaybePreimageClaimableHTLC {
+ claimable_amount_satoshis: claimable_amount_satoshis_nonref,
+ expiry_height: expiry_height_nonref,
+ }
+ },
+ nativeBalance::CounterpartyRevokedOutputClaimable {ref claimable_amount_satoshis, } => {
+ let mut claimable_amount_satoshis_nonref = (*claimable_amount_satoshis).clone();
+ Balance::CounterpartyRevokedOutputClaimable {
+ claimable_amount_satoshis: claimable_amount_satoshis_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::MaybeTimeoutClaimableHTLC {mut claimable_amount_satoshis, mut claimable_height, } => {
+ Balance::MaybeTimeoutClaimableHTLC {
+ claimable_amount_satoshis: claimable_amount_satoshis,
+ claimable_height: claimable_height,
+ }
+ },
+ nativeBalance::MaybePreimageClaimableHTLC {mut claimable_amount_satoshis, mut expiry_height, } => {
+ Balance::MaybePreimageClaimableHTLC {
+ claimable_amount_satoshis: claimable_amount_satoshis,
+ expiry_height: expiry_height,
+ }
+ },
+ nativeBalance::CounterpartyRevokedOutputClaimable {mut claimable_amount_satoshis, } => {
+ Balance::CounterpartyRevokedOutputClaimable {
+ claimable_amount_satoshis: claimable_amount_satoshis,
+ }
+ },
+ }
+ }
+}
+/// 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 MaybeTimeoutClaimableHTLC-variant Balance
+pub extern "C" fn Balance_maybe_timeout_claimable_htlc(claimable_amount_satoshis: u64, claimable_height: u32) -> Balance {
+ Balance::MaybeTimeoutClaimableHTLC {
+ claimable_amount_satoshis,
+ claimable_height,
+ }
+}
+#[no_mangle]
+/// Utility method to constructs a new MaybePreimageClaimableHTLC-variant Balance
+pub extern "C" fn Balance_maybe_preimage_claimable_htlc(claimable_amount_satoshis: u64, expiry_height: u32) -> Balance {
+ Balance::MaybePreimageClaimableHTLC {
+ claimable_amount_satoshis,
+ expiry_height,
+ }
+}
+#[no_mangle]
+/// Utility method to constructs a new CounterpartyRevokedOutputClaimable-variant Balance
+pub extern "C" fn Balance_counterparty_revoked_output_claimable(claimable_amount_satoshis: u64) -> Balance {
+ Balance::CounterpartyRevokedOutputClaimable {
+ claimable_amount_satoshis,
+ }
+}
+/// 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 }
+}