Skip to content

fix(demo): use selected endpoint for transaction broadcast - #126

Open
j-kon wants to merge 4 commits into
bitcoindevkit:mainfrom
j-kon:fix/demo-selected-broadcast-endpoint
Open

j-kon wants to merge 4 commits into
bitcoindevkit:mainfrom
j-kon:fix/demo-selected-broadcast-endpoint

Conversation

@j-kon

@j-kon j-kon commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Summary

  • keep BlockchainClientFactory keyed by WalletNetwork
  • resolve the user's selected EndpointConfig inside blockchainClientFactoryProvider
  • create the broadcast client from that resolved endpoint
  • remove the unused backendForNetwork helper in a separate commit
  • cover the UI, provider, and service boundaries with focused offline tests

Why

Wallet sync and fee estimates already honor the server selected in the demo app, but transaction broadcast created a new client from defaultEndpoints. Switching away from an unavailable default server could therefore restore sync while sends still tried the unavailable server.

The send page now passes the active wallet network to the existing factory contract. The provider resolves the current endpoint selection for that network and creates the broadcast client from the resolved client type and URL.

Validation

  • dart format --output=none --set-exit-if-changed bdk_demo/lib bdk_demo/test
  • dart analyze --fatal-infos --fatal-warnings lib test example
  • flutter analyze
  • dart test
  • flutter test

Closes #123

@j-kon
j-kon marked this pull request as ready for review August 11, 2026 22:38
@j-kon

j-kon commented Aug 11, 2026

Copy link
Copy Markdown
Contributor Author

Hi @Johnosezele, this is ready for review when you have a chance. It implements the selected broadcast endpoint fix discussed in #123.

@Shamsudeen12

Copy link
Copy Markdown

Not blocking, just something I noticed while reading through: backendForNetwork still resolves from defaultEndpoints, so it answers "what backend does this network use by default" rather than "what backend is the user actually connected to." Right now, it doesn't matter since it's only called from tests, and every endpoint option within a network happens to be the same client type anyway. But if we ever add a mixed list for a network, say an Esplora option alongside the Electrum ones on testnet, it would quietly report the wrong backend for anyone without a default endpoint. Might be worth a follow-up to either route it through the resolved endpoint config like the rest of this PR does, or just remove it since nothing in the app uses it.

@Ugarba202

Copy link
Copy Markdown
Contributor

tACK f91ca62 on Linux. tested locally across send_page_test.dart and blockchain_service_test.dart everything is green and static analysis is clean. verified that broadcasting now resolves through endpointConfigProvider and passes the active EndpointConfig directly to the client factory.
Also agree with @Shamsudeen12 that backendForNetwork can be cleaned up or refactored to backendForEndpoint in a quick follow-up, but the core fix here for #123 is clean.

@Johnosezele Johnosezele left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@j-kon bug fix looks right, instead of resolving the endpoint in the SendPage UI and changing the factory to take EndpointConfig, resolve inside blockchainClientFactoryProvider and leave the typedef as was.

You can remove backendForNetwork in another commit here, kindly add a commit description for it and edit PR and corresponding issue

Keep the send UI and blockchain client factory keyed by wallet network while resolving the user's selected endpoint inside the provider. Add focused provider and UI coverage for the boundary.
Remove backendForNetwork because client creation now derives the backend directly from the resolved endpoint configuration. The helper only reflected defaults and had no remaining callers.
Remove the now-unused constants import and apply the repository formatter to the provider regression test.
@j-kon
j-kon force-pushed the fix/demo-selected-broadcast-endpoint branch from f91ca62 to 3910c97 Compare September 14, 2026 19:20
@j-kon

j-kon commented Sep 14, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the requested changes:

  • kept BlockchainClientFactory accepting WalletNetwork
  • moved selected endpoint resolution into blockchainClientFactoryProvider
  • kept SendPage responsible only for passing record.network
  • removed backendForNetwork in a separate documented commit
  • updated the PR and issue descriptions to match the implementation
  • rebased onto the latest main and added focused offline coverage

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.

bug(demo): broadcast transactions through the selected network endpoint

4 participants