Skip to content

Update address types dynamically#48

Open
ben-kaufman wants to merge 2 commits intomainfrom
feat/dynamic-address-types
Open

Update address types dynamically#48
ben-kaufman wants to merge 2 commits intomainfrom
feat/dynamic-address-types

Conversation

@ben-kaufman
Copy link

Summary

Adds runtime APIs to add/remove monitored address types and to change the primary address type without rebuilding the node. Previously, address_type and address_types_to_monitor were fixed at build time via Config.

Changes

Node API

  • add_address_type_to_monitor(address_type, seed_bytes) / add_address_type_to_monitor_with_mnemonic(...) — Add an address type to the monitored set. The wallet is created from the given seed (or loaded from kv-store if previously monitored) and included in subsequent sync cycles. Fails with AddressTypeAlreadyMonitored or AddressTypeIsPrimary when invalid.
  • remove_address_type_from_monitor(address_type) — Remove an address type from monitoring and unload its wallet. Persisted state remains in the kv-store; re-adding the type recovers funds on the next sync. Fails with AddressTypeNotMonitored or AddressTypeIsPrimary when invalid.
  • set_primary_address_type(address_type, seed_bytes) / set_primary_address_type_with_mnemonic(...) — Change the primary address type used for new addresses and change outputs. The previous primary is demoted to the monitored set. If the new primary has never been synced, the next sync performs a full scan.

Implementation

  • AddressTypeRuntimeConfig — New runtime struct (primary + monitored list) initialized from Config and updated by the new APIs. Esplora and Electrum chain sources now take and use this for collect_additional_sync_requests, so sync reflects the current set of address types.
  • Wallet — New operation_lock to serialize add/remove/set_primary; holds kv_store, address_type_runtime_config, and node_metrics. Shared helper create_wallet_for_address_type builds a wallet from seed and attaches it at the current best block.
  • bdk-wallet-aggregate — New methods: add_wallet, set_primary, remove_wallet; new errors: WalletAlreadyExists, CannotRemovePrimary (and existing WalletNotFound).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant