Skip to content

wallet api: ev_assets_swap_offers_changed and ev_swap_offers_changed events - #2161

Open
profinch wants to merge 1 commit into
BeamMW:masterfrom
profinch:feat/api-swap-offers-events
Open

profinch wants to merge 1 commit into
BeamMW:masterfrom
profinch:feat/api-swap-offers-events

Conversation

@profinch

@profinch profinch commented Oct 8, 2026 •

Copy link
Copy Markdown

Author: Maxnflaxl (me@maxnflaxl.dev). His GitHub account is suspended, so he sent this patch by email and I'm opening the PR for him; the commit keeps him as the author.

Adds two ev_subunsub events to wallet-api, so clients get offer-board changes pushed instead of polling:

  • ev_assets_swap_offers_changed, fed by DexBoard::IObserver. Needs --enable_assets and API 7.2+, otherwise -32024.
  • ev_swap_offers_changed, fed by ISwapOffersObserver. Returns -32016 when atomic swaps are unavailable.

The payload matches the other ev_*_changed events (change, change_str, offers). Each offer has the same JSON as assets_swap_offers_list or swap_offers_board; the DEX list response and the event now share one serializer. A reset with the full board is sent right after subscribing. A failed request changes no subscription. Both events are blocked for DApps, as the list methods are.

The server already subscribed to both boards with empty callbacks (api_cli.cpp, api_cli_swap.h). This patch subscribes each V61Api instance lazily and unsubscribes in its destructor. ISwapsProvider::getSwapOffersBoard() now returns a non-const reference, because SwapOffersBoard::Subscribe is non-const.

Testing

From Maxnflaxl (macOS, Release, asset and atomic swaps on):

  • wallet_api_test and wallet_test pass.
  • An in-process harness (DexBoard with a loopback broadcast gateway, not included) covers added, updated (re-broadcast), removed (assets_swap_cancel), reset on subscribe and resubscribe, unsubscribe, the -32016/-32024/DApp errors, and that a destroyed API instance gets no more callbacks.
  • On mainnet over TCP: reset matches assets_swap_offers_list, the error cases behave as above, and dropping subscribed sockets then reconnecting does not crash the daemon. The mainnet DEX board was empty during the test, so no live add/remove was seen there.
  • wallet_api also builds with both swap options off. With asset swaps on and atomic swaps off, api_cli.cpp does not build, same as on master (BroadcastRouter is only included through api_cli_swap.h).

Re-checked here on top of master daf7191 (macOS, RelWithDebInfo, both swap options on): wallet-api, wallet_api_test and wallet_test build with no new warnings, and both tests pass.

Docs for API v7.4: BeamMW/docs-gitbook#27

…events

Push DEX and atomic swap offer-board changes to ev_subunsub subscribers
instead of requiring clients to poll assets_swap_offers_list or
swap_offers_board.

- Payload follows the other ev_*_changed events: change, change_str and
  an offers array in the format of assets_swap_offers_list and
  swap_offers_board respectively. A reset with the full board follows
  the subscription.
- ev_assets_swap_offers_changed needs --enable_assets and API v7.2+,
  otherwise -32024. ev_swap_offers_changed returns -32016 when atomic
  swaps are unavailable. A failed request changes no subscription.
- Both events are blocked for DApps, like the list methods.
- ISwapsProvider::getSwapOffersBoard() returns a non-const board so the
  API can subscribe to it.
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