Skip to content

Commit 4173c4f

Browse files
refactor(key-wallet): drop unused is_watch_only from ManagedCoreAccount
The mutable managed-account state carries an `is_watch_only` field that is just propagated from the immutable parent `Account` and never read for any decision in the workspace. Every "is watch-only? then deny" check (`key-wallet-ffi/src/keys.rs`, `account_derivation.rs`) reads it off the immutable `Account`, not the managed copy. The denormalized field has no Rust callers — only test assertions and a `#[no_mangle]` getter that nothing in this repo invokes. Drop the field, the `is_watch_only` parameter on `ManagedCoreAccount::new` and the `create_managed_account_from_*` helpers, the trait method on `ManagedAccountTrait`, and the FFI export `managed_core_account_get_is_watch_only`. Note: `ManagedPlatformAccount.is_watch_only` and the corresponding `managed_platform_account_get_is_watch_only` FFI export are unchanged. Breaking change for any out-of-tree consumer of the `managed_core_account_get_is_watch_only` C ABI; check the parent `Account.is_watch_only` (exposed via `account_get_is_watch_only`) or the wallet-level `wallet_is_watch_only` instead. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 5603fff commit 4173c4f

7 files changed

Lines changed: 7 additions & 60 deletions

File tree

key-wallet-ffi/src/managed_account.rs

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -584,23 +584,6 @@ pub unsafe extern "C" fn managed_core_account_get_account_type(
584584
}
585585
}
586586

587-
/// Check if a managed account is watch-only
588-
///
589-
/// # Safety
590-
///
591-
/// - `account` must be a valid pointer to an FFIManagedCoreAccount instance
592-
#[no_mangle]
593-
pub unsafe extern "C" fn managed_core_account_get_is_watch_only(
594-
account: *const FFIManagedCoreAccount,
595-
) -> bool {
596-
if account.is_null() {
597-
return false;
598-
}
599-
600-
let account = &*account;
601-
account.inner().is_watch_only
602-
}
603-
604587
/// Get the balance of a managed account
605588
///
606589
/// # Safety
@@ -1628,10 +1611,7 @@ mod tests {
16281611
assert_eq!(result.error_code, 0);
16291612
assert!(result.error_message.is_null());
16301613

1631-
// Verify the account was created successfully
1632-
let account = &*result.account;
16331614
// Account should exist and be valid
1634-
assert!(!account.inner().is_watch_only);
16351615

16361616
// Clean up
16371617
managed_core_account_free(result.account);
@@ -1829,10 +1809,6 @@ mod tests {
18291809
assert_eq!(account_type, FFIAccountKind::StandardBIP44);
18301810
assert_eq!(index_out, 0);
18311811

1832-
// Test get_is_watch_only
1833-
let is_watch_only = managed_core_account_get_is_watch_only(account);
1834-
assert!(!is_watch_only);
1835-
18361812
// Test get_balance
18371813
let mut balance_out = crate::types::FFIBalance {
18381814
confirmed: 999,
@@ -1880,9 +1856,6 @@ mod tests {
18801856
let account_type = managed_core_account_get_account_type(ptr::null(), &mut index_out);
18811857
assert_eq!(account_type, FFIAccountKind::StandardBIP44); // Default type
18821858

1883-
let is_watch_only = managed_core_account_get_is_watch_only(ptr::null());
1884-
assert!(!is_watch_only);
1885-
18861859
let tx_count = managed_core_account_get_transaction_count(ptr::null());
18871860
assert_eq!(tx_count, 0);
18881861

key-wallet-ffi/src/managed_wallet.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,6 @@ mod tests {
616616
internal_addresses: internal_pool,
617617
},
618618
network,
619-
false,
620619
);
621620

622621
managed_collection.standard_bip44_accounts.insert(0, managed_account.clone());

key-wallet-ffi/src/utxo_tests.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,6 @@ mod utxo_tests {
205205
.unwrap(),
206206
},
207207
Network::Testnet,
208-
false,
209208
);
210209

211210
// Add multiple UTXOs
@@ -308,7 +307,6 @@ mod utxo_tests {
308307
.unwrap(),
309308
},
310309
Network::Testnet,
311-
false,
312310
);
313311

314312
let utxos = Utxo::dummy_batch(0..2, 10000, 100, false, false);
@@ -334,7 +332,6 @@ mod utxo_tests {
334332
.unwrap(),
335333
},
336334
Network::Testnet,
337-
false,
338335
);
339336

340337
let utxos = Utxo::dummy_batch(10..11, 20000, 200, false, false);
@@ -353,7 +350,6 @@ mod utxo_tests {
353350
.unwrap(),
354351
},
355352
Network::Testnet,
356-
false,
357353
);
358354

359355
let utxos = Utxo::dummy_batch(20..22, 30000, 300, false, false);
@@ -412,7 +408,6 @@ mod utxo_tests {
412408
.unwrap(),
413409
},
414410
Network::Testnet,
415-
false,
416411
);
417412

418413
let utxos = Utxo::dummy_batch(1..2, 10000, 100, false, false);

key-wallet/src/managed_account/managed_account_collection.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,6 @@ impl ManagedAccountCollection {
513513
Self::create_managed_account_from_account_type(
514514
account.account_type,
515515
account.network,
516-
account.is_watch_only,
517516
&key_source,
518517
)
519518
}
@@ -527,7 +526,6 @@ impl ManagedAccountCollection {
527526
Self::create_managed_account_from_account_type(
528527
account.account_type,
529528
account.network,
530-
account.is_watch_only,
531529
&key_source,
532530
)
533531
}
@@ -546,16 +544,14 @@ impl ManagedAccountCollection {
546544
Self::create_managed_account_from_account_type(
547545
account.account_type,
548546
account.network,
549-
account.is_watch_only,
550547
&key_source,
551548
)
552549
}
553550

554-
/// Create a ManagedAccount from an Account type with network and watch-only status
551+
/// Create a ManagedAccount from an Account type with network
555552
fn create_managed_account_from_account_type(
556553
account_type: AccountType,
557554
network: Network,
558-
is_watch_only: bool,
559555
key_source: &KeySource,
560556
) -> Result<ManagedCoreAccount, crate::error::Error> {
561557
// Get the derivation path for this account type
@@ -785,7 +781,7 @@ impl ManagedAccountCollection {
785781
}
786782
};
787783

788-
Ok(ManagedCoreAccount::new(managed_type, network, is_watch_only))
784+
Ok(ManagedCoreAccount::new(managed_type, network))
789785
}
790786

791787
/// Create a ManagedPlatformAccount from an Account for Platform Payment accounts

key-wallet/src/managed_account/managed_account_trait.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ pub trait ManagedAccountTrait {
3030
/// Get mutable metadata
3131
fn metadata_mut(&mut self) -> &mut AccountMetadata;
3232

33-
/// Check if this is a watch-only account
34-
fn is_watch_only(&self) -> bool;
35-
3633
/// Get balance
3734
fn balance(&self) -> &WalletCoreBalance;
3835

key-wallet/src/managed_account/mod.rs

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ pub struct ManagedCoreAccount {
5656
pub network: Network,
5757
/// Account metadata
5858
pub metadata: AccountMetadata,
59-
/// Whether this is a watch-only account
60-
pub is_watch_only: bool,
6159
/// Account balance information
6260
pub balance: WalletCoreBalance,
6361
/// Transaction history for this account
@@ -76,16 +74,11 @@ pub struct ManagedCoreAccount {
7674

7775
impl ManagedCoreAccount {
7876
/// Create a new managed account
79-
pub fn new(
80-
managed_account_type: ManagedAccountType,
81-
network: Network,
82-
is_watch_only: bool,
83-
) -> Self {
77+
pub fn new(managed_account_type: ManagedAccountType, network: Network) -> Self {
8478
Self {
8579
managed_account_type,
8680
network,
8781
metadata: AccountMetadata::default(),
88-
is_watch_only,
8982
balance: WalletCoreBalance::default(),
9083
transactions: BTreeMap::new(),
9184
utxos: BTreeMap::new(),
@@ -129,7 +122,7 @@ impl ManagedCoreAccount {
129122
.expect("Should succeed with NoKeySource")
130123
});
131124

132-
Self::new(managed_type, account.network, account.is_watch_only)
125+
Self::new(managed_type, account.network)
133126
}
134127

135128
/// Create a ManagedAccount from a BLS Account
@@ -153,7 +146,7 @@ impl ManagedCoreAccount {
153146
.expect("Should succeed with NoKeySource")
154147
});
155148

156-
Self::new(managed_type, account.network, account.is_watch_only)
149+
Self::new(managed_type, account.network)
157150
}
158151

159152
/// Create a ManagedAccount from an EdDSA Account
@@ -168,7 +161,7 @@ impl ManagedCoreAccount {
168161
)
169162
.expect("Should succeed with NoKeySource");
170163

171-
Self::new(managed_type, account.network, account.is_watch_only)
164+
Self::new(managed_type, account.network)
172165
}
173166

174167
/// Get the account index
@@ -1310,10 +1303,6 @@ impl ManagedAccountTrait for ManagedCoreAccount {
13101303
&mut self.metadata
13111304
}
13121305

1313-
fn is_watch_only(&self) -> bool {
1314-
self.is_watch_only
1315-
}
1316-
13171306
fn balance(&self) -> &WalletCoreBalance {
13181307
&self.balance
13191308
}
@@ -1350,7 +1339,6 @@ impl<'de> Deserialize<'de> for ManagedCoreAccount {
13501339
managed_account_type: ManagedAccountType,
13511340
network: Network,
13521341
metadata: AccountMetadata,
1353-
is_watch_only: bool,
13541342
balance: WalletCoreBalance,
13551343
transactions: BTreeMap<Txid, TransactionRecord>,
13561344
utxos: BTreeMap<OutPoint, Utxo>,
@@ -1369,7 +1357,6 @@ impl<'de> Deserialize<'de> for ManagedCoreAccount {
13691357
managed_account_type: helper.managed_account_type,
13701358
network: helper.network,
13711359
metadata: helper.metadata,
1372-
is_watch_only: helper.is_watch_only,
13731360
balance: helper.balance,
13741361
transactions: helper.transactions,
13751362
utxos: helper.utxos,

key-wallet/src/test_utils/account.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ impl ManagedCoreAccount {
3434
internal_addresses: internal_pool,
3535
};
3636

37-
ManagedCoreAccount::new(account_type, Network::Regtest, false)
37+
ManagedCoreAccount::new(account_type, Network::Regtest)
3838
}
3939
}

0 commit comments

Comments
 (0)