-
Notifications
You must be signed in to change notification settings - Fork 8
fix: correct confirmations for UTXOs in wallet FFI #306
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: v0.42-dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -234,7 +234,7 @@ mod utxo_tests { | |
| managed_info.accounts.insert(bip44_account); | ||
|
|
||
| let ffi_managed_info = Box::into_raw(Box::new(FFIManagedWalletInfo::new(managed_info))); | ||
|
|
||
| unsafe { (*ffi_managed_info).inner_mut() }.update_synced_height(300); | ||
| let result = unsafe { | ||
| managed_wallet_get_utxos(&*ffi_managed_info, &mut utxos_out, &mut count_out, error) | ||
| }; | ||
|
|
@@ -253,19 +253,21 @@ mod utxo_tests { | |
| assert_eq!(utxos[0].vout, 0); | ||
| assert_eq!(utxos[0].amount, 50000); | ||
| assert_eq!(utxos[0].height, 100); | ||
| assert_eq!(utxos[0].confirmations, 1); | ||
| assert_eq!(utxos[0].confirmations, 201); | ||
|
|
||
| // Check second UTXO | ||
| assert_eq!(utxos[1].txid[0], 1); | ||
| assert_eq!(utxos[1].vout, 1); | ||
| assert_eq!(utxos[1].amount, 100000); | ||
| assert_eq!(utxos[1].height, 101); | ||
| assert_eq!(utxos[1].confirmations, 200); | ||
|
|
||
| // Check third UTXO | ||
| assert_eq!(utxos[2].txid[0], 2); | ||
| assert_eq!(utxos[2].vout, 2); | ||
| assert_eq!(utxos[2].amount, 150000); | ||
| assert_eq!(utxos[2].height, 102); | ||
| assert_eq!(utxos[2].confirmations, 199); | ||
|
Comment on lines
+256
to
+270
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion | 🟠 Major Add test coverage for edge cases in confirmation calculation. The updated confirmation values (201, 200, 199) correctly reflect the calculation based on
Based on coding guidelines, consider adding property-based tests for confirmation invariants and covering mainnet/testnet configurations. 🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
| // Clean up | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Critical bug: Incorrect confirmation count when
current_height < utxo.height.The calculation
current_height.saturating_sub(utxo.height) + 1returns 1 confirmation whencurrent_height < utxo.height, which is incorrect. When the synced height hasn't caught up to the UTXO's block height (e.g., during initial sync or reorg), the code should return 0 confirmations, not 1.The existing pattern in
immature_transaction.rs:120-126correctly checkscurrent_height >= self.heightbefore adding 1.🔎 Proposed fix to match the established pattern
📝 Committable suggestion
🤖 Prompt for AI Agents