xmr-btc-swap/src-gui
Mohan 07f935bfbc
feat(protocol): Early Bitcoin refund (#344)
* feat(protocol): Early Bitcoin refund

Alice can choose to let Bob refund his Bitcoin early (before TxCancel timelock expires)

* feat: Let Bob check for TxEarlyRefund

* fix: compile errors
feat(alice): if we cannot lock Monero within 2 minutes, early refund bitcoin

* satisfy clippy

* fix(gui): Emit tauri event when Bitcoin is early refunded

* tests progress

* rename AliceStates

* progress: working prototype!

* add unit tests for tx_early_refund construction (tx_early_refund_can_be_constructed_and_signed, tx_early weight check)

* fix compile error in swap/tests/alice_zero_xmr_early_refund.rs

* only make [`tx_early_refund_sig_bob`] optional in state machine, not message machine

* feat: working integration test alice_zero_xmr_early_refund.rs

* fix tests

* add changelog entry, add integration test with broken monero-wallet-rpc simulation

* amend

* amend changelog

* nitpick

* feat(gui): Bump MIN_ASB_VERSION to 2.0.0

* feat(bob): explicitly check for tx_early_rewfund

* refactor(bob): Assume tx_early_refund will not be published if timelock has expired

* add todo

* refactor

* refactor(swap): Differentiate between BtcRefundPublished, BtcEarlyRefundPublished, BtcEarlyRefunded and BtcRefunded

* refactor: move weight of tx_early into TX_EARLY_REFUND_WEIGHT const

* efactor(swap): Differentiate between BtcRefundPublished,BtcEarlyRefundPublished, BtcEarlyRefunded and BtcRefunded

* small refactors

* nitpciks

* dprint fmt

* add context to get_raw_transaction

* refactor: remove duplicated code in watch_for_redeem_btc, dprint fmt

* fix: parse -5 electrum transaction not found error correctly

* refactor: send btc_refund_finalized flag to tauri with BtcRefunded state

* remove uncessary .context

* dprint dfmt

* remove unused import

* refactor: explicitly mark state3.expired_timelocks(...) as transient error when locking Monero

* use .context instead of ok_or_else(...)

* fix: in get_raw_transaction also check for "missing transaction"

* add 4 different types of tauri events for different refund states

* display BobStateName.BtcEarlyRefunded as done state

* add global bottom to DialogContentText

* fix(gui): Add missing padding in SwapDialog

* proof of concept: electrum load balancer

* load balancer progress

* wrap Mutex<Vec<Arc<BdkElectrumClient<Client>>>> in electrum_balancer in another Arc, free locks as fast as possible

* refactor

* refactor(electrum balancer): use OnceCell to do lazy initilization

* tests

* refactor(electrum): enhance error handling with MultiError for comprehensive failure analysis

This commit introduces a robust MultiError system for the Electrum balancer that collects
and exposes all individual node failures, enabling better error analysis and decision making.

Key improvements:
- Add MultiError struct with methods for inspecting all collected errors from failed nodes
- Modify electrum_balancer::call() to return MultiError instead of single Error
- Enhance Client::get_tx() to properly detect transaction-not-found across multiple nodes
- Add call_async_with_multi_error() method for detailed async error analysis
- Improve error tracing and logging throughout the Bitcoin wallet operations
- Add comprehensive test coverage for MultiError functionality and edge cases
- Remove obsolete should_retry_on_error() logic in favor of MultiError inspection

The MultiError type maintains backward compatibility through automatic conversion to Error
while providing rich error analysis capabilities for callers that need detailed failure
information. This particularly improves handling of transaction-not-found scenarios where
different nodes may return different error formats.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* add changelog entry for electrum node balancing

* refactors of electrum balancer

* only warn if .check_for_tx_early_refund fails

* clippy

* remove verbose message

* use AtomicUsize

* final touches

* log libp2p crates

* merge master

* display LinearProgressWithSubtitle as indeterminate if progress=100%

* let broadcast return a MultiError, log all libp2p crates

* nitpick

* make clippy happy

* log "kind" for join_all load balancer

* add kind to join_all method, show warning alert if alice takes a long time to redeem Bitcoin

* parse multierrors correctly

* fmt

---------

Co-authored-by: Claude <noreply@anthropic.com>
2025-06-11 20:40:16 +02:00
..
public feat: cargo project at root 2024-08-08 00:49:04 +02:00
src feat(protocol): Early Bitcoin refund (#344) 2025-06-11 20:40:16 +02:00
.env.development feat(gui): Approve dialog before publishing Bitcoin lock transaction (#291) 2025-04-18 01:51:55 +02:00
.gitignore docs: generally improve docs and add maker page (#242) 2025-01-21 16:05:05 +01:00
eslint.config.js refactor(gui): Update MUI to v7 (#383) 2025-06-06 22:31:33 +02:00
index.html refactor(gui): Update MUI to v7 (#383) 2025-06-06 22:31:33 +02:00
package-lock.json refactor(gui): Update MUI to v7 (#383) 2025-06-06 22:31:33 +02:00
package.json refactor(gui): Update MUI to v7 (#383) 2025-06-06 22:31:33 +02:00
README.md refactor(gui): Update MUI to v7 (#383) 2025-06-06 22:31:33 +02:00
tsconfig.json wip: WithdrawDialog migrated to Tauri IPC 2024-08-09 19:46:58 +02:00
tsconfig.node.json feat: cargo project at root 2024-08-08 00:49:04 +02:00
vite.config.ts feat(gui, tauri): Accept --testnet flag, default to mainnet (#106) 2024-10-10 14:51:56 +02:00
yarn.lock refactor(gui): Update MUI to v7 (#383) 2025-06-06 22:31:33 +02:00

Requirements

  • For compiling the Rust code: cargo and cargo tauri (installation)
  • For running the Typescript code: node and yarn
  • For formatting and bindings: dprint (cargo install dprint@0.50.0) and typeshare (cargo install typeshare-cli)
  • If you are on Windows and you want to use the check-bindings command you'll need to manually install the GNU DiffUtils (installation) and GNU CoreUtils (installtion). Remember to add the installation path (probably C:\Program Files (x86)\GnuWin32\bin) to the PATH in your enviroment variables.

Start development servers

For development, we need to run both vite and tauri servers:

cd src-gui
yarn install && yarn run dev
# let this run
cd src-tauri
cargo tauri dev --no-watch -- -- --testnet
# let this run as well

Generate bindings for Tauri API

Running yarn run dev or yarn build should automatically re-build the Typescript bindings whenever something changes. You can also manually trigger this using the gen-bindings command:

yarn run gen-bindings

You can also check whether the current bindings are up to date:

yarn run check-bindings

Debugging

Because the GUI is running in an embedded browser, we can't use the usual Browser extensions to debug the GUI. Instead we use standalone React DevTools / Redux DevTools.

React DevTools

Run this command to start the React DevTools server. The frontend will connect to this server automatically:

npx react-devtools

Redux DevTools

Run this command to start the Redux DevTools server. The frontend will connect to this server automatically. You can then debug the global Redux state. Observe how it changes over time, go back in time, see dispatch history, etc.

You may have to go to Settings -> 'use local custom server' -> connect inside the devtools window for the state to be reflected correctly.

npx redux-devtools --hostname=localhost --port=8098 --open