Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,73 @@ pub unsafe extern "C" fn core_wallet_tx_builder_use_only_added_inputs(
PlatformWalletFFIResult::ok()
}

/// The balance a build funded by `account_type` could actually select from — the

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same capture here.

The doc block starting at line 629 ("Fund the build from the inputs core_wallet_tx_builder_add_inputs_from_outpoints supplied, and nothing else" … "fails with a too-many-inputs error") belongs to core_wallet_tx_builder_use_only_added_inputs, which now sits at line 674 with only the boilerplate # Safety note.

This one leaks further than the Rust-side twin: cbindgen emits these into the generated C header the Swift SDK imports, so the public header will describe a balance getter in terms of batched-drain funding, while use_only_added_inputs — new in the base PR, and whose entire rationale lived in that block — ships with no explanation at all.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. The stacking had wedged the balance getter between this doc block and the function it documents; it now sits below core_wallet_tx_builder_use_only_added_inputs, so the block belongs to that function again and the getter has its own.

The header point was the one that made this more than cosmetic — cbindgen emits these, so the public header the Swift SDK imports would have described a balance getter in terms of batched-drain funding while the function whose entire rationale lived in that block shipped bare. Resolved as part of the v4.2-dev merge after #4548 landed (c002d33), which is why it isn't in the later commit.

🤖 Generated with Claude Code

/// same accounts `core_wallet_tx_builder_finalize` would fund from, counting
/// only UTXOs coin selection accepts.
///
/// Gate amount entry on this rather than on `core_wallet_get_balance`, which
/// sums every funding account the wallet has — CoinJoin included — and so
/// reports money a build then refuses.
///
/// Reservations are not subtracted; see `CoreWallet::pooled_spendable_balance`.
///
/// # Safety
/// `out_balance` must be a valid, writable pointer.
#[no_mangle]
pub unsafe extern "C" fn core_wallet_pooled_spendable_balance(
wallet: Handle,
account_type: CoreAccountTypeFFI,
account_index: u32,
out_balance: *mut u64,
) -> PlatformWalletFFIResult {
check_ptr!(out_balance);
*out_balance = 0;

let wallet = unwrap_option_or_return!(PLATFORM_WALLET_STORAGE.with_item(wallet, |w| w.clone()));
let balance = unwrap_result_or_return!(runtime().block_on(
wallet
.core()
.pooled_spendable_balance(account_type.funding_sources(), account_index)
));

*out_balance = balance;
PlatformWalletFFIResult::ok()
}

/// The largest amount a build funded by `account_type` could actually pay out,
/// net of the fee spending it costs — what a "send max" control must use.
///
/// `core_wallet_pooled_spendable_balance` is the gross figure: entering it
/// verbatim as an amount fails, because a build needs `amount + fee`. This
/// prices the fee off the inputs that spending everything would take, at
/// `fee_rate_sat_per_kb` — pass 0 for the same default `TransactionBuilder`
/// starts from, or the rate the host sets on its builders.
///
/// # Safety
/// `out_max_sendable` must be a valid, writable pointer.
#[no_mangle]
pub unsafe extern "C" fn core_wallet_pooled_max_sendable(
wallet: Handle,
account_type: CoreAccountTypeFFI,
account_index: u32,
fee_rate_sat_per_kb: u64,
out_max_sendable: *mut u64,
) -> PlatformWalletFFIResult {
check_ptr!(out_max_sendable);
*out_max_sendable = 0;

let fee_rate = (fee_rate_sat_per_kb != 0).then(|| FeeRate::new(fee_rate_sat_per_kb));
let wallet = unwrap_option_or_return!(PLATFORM_WALLET_STORAGE.with_item(wallet, |w| w.clone()));
let max_sendable = unwrap_result_or_return!(runtime().block_on(
wallet
.core()
.pooled_max_sendable(account_type.funding_sources(), account_index, fee_rate)
));

*out_max_sendable = max_sendable;
PlatformWalletFFIResult::ok()
}

/// # Safety
/// `builder` must be a valid, non-destroyed pointer.
#[no_mangle]
Expand Down
Loading
Loading