Skip to content

key-wallet: get_next_address_index returns None for exhausted single-pool accounts #730

@QuantumExplorer

Description

@QuantumExplorer

Context

Surfaced by CodeRabbit during review of #711. Pre-existing behavior — the method moved from an inherent impl on ManagedCoreAccount to a trait default in ManagedAccountTrait (#728), with the same logic.

Problem

For Standard accounts, ManagedAccountTrait::get_next_receive_address_index returns Some(highest_generated + 1) when every generated address has been used. For single-pool account variants (CoinJoin, Identity*, AssetLock*, Provider*, DashPay*, PlatformPayment), get_next_address_index returns `None` in the same exhausted-pool case:

addresses.unused_addresses().first().and_then(|addr| addresses.address_index(addr))

That's inconsistent — same predicate ("what's the next index I can derive") returns different shapes depending on the account variant.

Suggested fix

Mirror the Standard-account behavior:

if let Some(addr) = addresses.unused_addresses().first() {
    addresses.address_index(addr)
} else {
    let stats = addresses.stats();
    Some(stats.highest_generated.map(|h| h + 1).unwrap_or(0))
}

Files

  • key-wallet/src/managed_account/managed_account_trait.rs (the get_next_address_index default impl)

Original review thread: #711 (review comment 3187368612)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions