Skip to content

Commit 8da22a8

Browse files
authored
refactor(key-wallet): rename ManagedCoreAccount.account_type (#704)
Rename `ManagedCoreAccount.account_type` (typed `ManagedAccountType`) to `managed_account_type` so call sites no longer read like `account_type.to_account_type()`, and to make clear it's the stateful variant rather than the bare `AccountType`.
1 parent 66d63c1 commit 8da22a8

12 files changed

Lines changed: 91 additions & 83 deletions

File tree

dash-spv/tests/dashd_sync/setup.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ impl TestContext {
146146
let ManagedAccountType::Standard {
147147
external_addresses,
148148
..
149-
} = &account.account_type
149+
} = &account.managed_account_type
150150
else {
151151
panic!("Account 0 is not a Standard account type");
152152
};

key-wallet-ffi/src/address_pool.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ pub unsafe extern "C" fn managed_wallet_get_address_pool_info(
310310
if let key_wallet::managed_account::managed_account_type::ManagedAccountType::Standard {
311311
external_addresses,
312312
..
313-
} = &managed_account.account_type {
313+
} = &managed_account.managed_account_type {
314314
external_addresses
315315
} else {
316316
(*error).set(FFIErrorCode::InvalidInput, "Account type does not have external address pool");
@@ -322,7 +322,7 @@ pub unsafe extern "C" fn managed_wallet_get_address_pool_info(
322322
if let key_wallet::managed_account::managed_account_type::ManagedAccountType::Standard {
323323
internal_addresses,
324324
..
325-
} = &managed_account.account_type {
325+
} = &managed_account.managed_account_type {
326326
internal_addresses
327327
} else {
328328
(*error).set(FFIErrorCode::InvalidInput, "Account type does not have internal address pool");
@@ -331,7 +331,7 @@ pub unsafe extern "C" fn managed_wallet_get_address_pool_info(
331331
}
332332
FFIAddressPoolType::Single => {
333333
// Get the first (and only) address pool for non-standard accounts
334-
let pools = managed_account.account_type.address_pools();
334+
let pools = managed_account.managed_account_type.address_pools();
335335
if pools.is_empty() {
336336
(*error).set(FFIErrorCode::InvalidInput, "Account has no address pools");
337337
return false;
@@ -395,7 +395,7 @@ pub unsafe extern "C" fn managed_wallet_set_gap_limit(
395395
if let key_wallet::managed_account::managed_account_type::ManagedAccountType::Standard {
396396
external_addresses,
397397
..
398-
} = &mut managed_account.account_type {
398+
} = &mut managed_account.managed_account_type {
399399
external_addresses
400400
} else {
401401
(*error).set(FFIErrorCode::InvalidInput, "Account type does not have external address pool");
@@ -407,7 +407,7 @@ pub unsafe extern "C" fn managed_wallet_set_gap_limit(
407407
if let key_wallet::managed_account::managed_account_type::ManagedAccountType::Standard {
408408
internal_addresses,
409409
..
410-
} = &mut managed_account.account_type {
410+
} = &mut managed_account.managed_account_type {
411411
internal_addresses
412412
} else {
413413
(*error).set(FFIErrorCode::InvalidInput, "Account type does not have internal address pool");
@@ -416,7 +416,7 @@ pub unsafe extern "C" fn managed_wallet_set_gap_limit(
416416
}
417417
FFIAddressPoolType::Single => {
418418
// Get the first (and only) address pool for non-standard accounts
419-
let pools = managed_account.account_type.address_pools_mut();
419+
let pools = managed_account.managed_account_type.address_pools_mut();
420420
if pools.is_empty() {
421421
(*error).set(FFIErrorCode::InvalidInput, "Account has no address pools");
422422
return false;
@@ -482,7 +482,7 @@ pub unsafe extern "C" fn managed_wallet_generate_addresses_to_index(
482482
if let key_wallet::managed_account::managed_account_type::ManagedAccountType::Standard {
483483
external_addresses,
484484
..
485-
} = &mut managed_account.account_type {
485+
} = &mut managed_account.managed_account_type {
486486
{
487487
let current = external_addresses.highest_generated.unwrap_or(0);
488488
if target_index > current {
@@ -502,7 +502,7 @@ pub unsafe extern "C" fn managed_wallet_generate_addresses_to_index(
502502
if let key_wallet::managed_account::managed_account_type::ManagedAccountType::Standard {
503503
internal_addresses,
504504
..
505-
} = &mut managed_account.account_type {
505+
} = &mut managed_account.managed_account_type {
506506
{
507507
let current = internal_addresses.highest_generated.unwrap_or(0);
508508
if target_index > current {
@@ -519,7 +519,7 @@ pub unsafe extern "C" fn managed_wallet_generate_addresses_to_index(
519519
}
520520
FFIAddressPoolType::Single => {
521521
// Get the first (and only) address pool for non-standard accounts
522-
let mut pools = managed_account.account_type.address_pools_mut();
522+
let mut pools = managed_account.managed_account_type.address_pools_mut();
523523
if pools.is_empty() {
524524
(*error).set(FFIErrorCode::InvalidInput, "Account has no address pools");
525525
return false;

key-wallet-ffi/src/managed_account.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ pub unsafe extern "C" fn managed_core_account_get_account_type(
536536

537537
let account = &*account;
538538
let managed_account = account.inner();
539-
let account_type_rust = managed_account.account_type.to_account_type();
539+
let account_type_rust = managed_account.managed_account_type.to_account_type();
540540

541541
// Set the index if output pointer is provided
542542
if !index_out.is_null() {
@@ -1078,7 +1078,7 @@ pub unsafe extern "C" fn managed_core_account_get_index(
10781078
}
10791079

10801080
let account = &*account;
1081-
account.inner().account_type.index_or_default()
1081+
account.inner().managed_account_type.index_or_default()
10821082
}
10831083

10841084
/// Get the external address pool from a managed account
@@ -1102,7 +1102,7 @@ pub unsafe extern "C" fn managed_core_account_get_external_address_pool(
11021102
let managed_account = account.inner();
11031103

11041104
// Get external address pool if this is a standard account
1105-
match &managed_account.account_type {
1105+
match &managed_account.managed_account_type {
11061106
key_wallet::managed_account::managed_account_type::ManagedAccountType::Standard {
11071107
external_addresses,
11081108
..
@@ -1138,7 +1138,7 @@ pub unsafe extern "C" fn managed_core_account_get_internal_address_pool(
11381138
let managed_account = account.inner();
11391139

11401140
// Get internal address pool if this is a standard account
1141-
match &managed_account.account_type {
1141+
match &managed_account.managed_account_type {
11421142
key_wallet::managed_account::managed_account_type::ManagedAccountType::Standard {
11431143
internal_addresses,
11441144
..
@@ -1182,7 +1182,7 @@ pub unsafe extern "C" fn managed_core_account_get_address_pool(
11821182
match pool_type {
11831183
FFIAddressPoolType::External => {
11841184
// Only standard accounts have external pools
1185-
match &managed_account.account_type {
1185+
match &managed_account.managed_account_type {
11861186
ManagedAccountType::Standard {
11871187
external_addresses,
11881188
..
@@ -1198,7 +1198,7 @@ pub unsafe extern "C" fn managed_core_account_get_address_pool(
11981198
}
11991199
FFIAddressPoolType::Internal => {
12001200
// Only standard accounts have internal pools
1201-
match &managed_account.account_type {
1201+
match &managed_account.managed_account_type {
12021202
ManagedAccountType::Standard {
12031203
internal_addresses,
12041204
..
@@ -1214,7 +1214,7 @@ pub unsafe extern "C" fn managed_core_account_get_address_pool(
12141214
}
12151215
FFIAddressPoolType::Single => {
12161216
// Get the single address pool for non-standard accounts
1217-
let pool_ref = match &managed_account.account_type {
1217+
let pool_ref = match &managed_account.managed_account_type {
12181218
ManagedAccountType::Standard {
12191219
..
12201220
} => {

key-wallet-ffi/src/managed_wallet.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ pub unsafe extern "C" fn managed_wallet_get_bip_44_external_address_range(
170170
let addresses = if let key_wallet::account::ManagedAccountType::Standard {
171171
external_addresses,
172172
..
173-
} = &mut managed_account.account_type
173+
} = &mut managed_account.managed_account_type
174174
{
175175
unwrap_or_return!(
176176
external_addresses.address_range(start_index, end_index, &key_source),
@@ -250,7 +250,7 @@ pub unsafe extern "C" fn managed_wallet_get_bip_44_internal_address_range(
250250
let addresses = if let key_wallet::account::ManagedAccountType::Standard {
251251
internal_addresses,
252252
..
253-
} = &mut managed_account.account_type
253+
} = &mut managed_account.managed_account_type
254254
{
255255
unwrap_or_return!(
256256
internal_addresses.address_range(start_index, end_index, &key_source),

key-wallet-ffi/src/transaction.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ pub unsafe extern "C" fn wallet_build_and_sign_transaction(
194194
HashMap::new();
195195

196196
// Collect from all address pools (receive, change, etc.)
197-
for pool in managed_account.account_type.address_pools() {
197+
for pool in managed_account.managed_account_type.address_pools() {
198198
for addr_info in pool.addresses.values() {
199199
address_to_path.insert(addr_info.address.clone(), addr_info.path.clone());
200200
}

key-wallet/src/managed_account/managed_account_collection.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ macro_rules! get_by_account_type_match_impl {
7272
account_index,
7373
involved_addresses,
7474
} => $self.dashpay_receival_accounts.$values().find(|account| {
75-
match &account.account_type {
75+
match &account.managed_account_type {
7676
ManagedAccountType::DashpayReceivingFunds {
7777
index,
7878
addresses,
@@ -90,7 +90,7 @@ macro_rules! get_by_account_type_match_impl {
9090
account_index,
9191
involved_addresses,
9292
} => $self.dashpay_external_accounts.$values().find(|account| {
93-
match &account.account_type {
93+
match &account.managed_account_type {
9494
ManagedAccountType::DashpayExternalAccount {
9595
index,
9696
addresses,
@@ -269,7 +269,7 @@ impl ManagedAccountCollection {
269269
pub fn insert(&mut self, account: ManagedCoreAccount) -> Result<(), crate::error::Error> {
270270
use crate::account::StandardAccountType;
271271

272-
match &account.account_type {
272+
match &account.managed_account_type {
273273
ManagedAccountType::Standard {
274274
index,
275275
standard_account_type,

key-wallet/src/managed_account/managed_account_trait.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ use dashcore::Txid;
1515

1616
/// Common trait for all managed account types
1717
pub trait ManagedAccountTrait {
18-
/// Get the account type
19-
fn account_type(&self) -> &ManagedAccountType;
18+
/// Get the managed account type
19+
fn managed_account_type(&self) -> &ManagedAccountType;
2020

21-
/// Get mutable account type
22-
fn account_type_mut(&mut self) -> &mut ManagedAccountType;
21+
/// Get mutable managed account type
22+
fn managed_account_type_mut(&mut self) -> &mut ManagedAccountType;
2323

2424
/// Get the network
2525
fn network(&self) -> Network;
@@ -53,11 +53,11 @@ pub trait ManagedAccountTrait {
5353

5454
/// Get the account index
5555
fn index(&self) -> Option<u32> {
56-
self.account_type().index()
56+
self.managed_account_type().index()
5757
}
5858

5959
/// Get the account index or 0 if none exists
6060
fn index_or_default(&self) -> u32 {
61-
self.account_type().index_or_default()
61+
self.managed_account_type().index_or_default()
6262
}
6363
}

0 commit comments

Comments
 (0)