From 2fe428779a27aecea220204f09c24e6ea702ca37 Mon Sep 17 00:00:00 2001 From: Einliterflasche <81313171+Einliterflasche@users.noreply.github.com> Date: Thu, 25 Jul 2024 23:06:50 +0200 Subject: [PATCH 01/24] feat(asb): Retry locking Monero (#1731) We retry to lock the Monero wallet until we succeed or until the cancel timelock expires. This is necessary because the monero-wallet-rpc can sometimes error out due to various reasons, such as - no connection to the daemon - "failed to get output distribution" See https://github.com/comit-network/xmr-btc-swap/issues/1726 --- CHANGELOG.md | 1 + swap/src/protocol/alice/swap.rs | 61 ++++++++++++++++++++++++++++----- 2 files changed, 53 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5152d646..e496e3cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] - ASB: The `history` command can now be used while the asb is running. +- ASB: Retry locking of Monero if it fails on first attempt ## [0.13.3] - 2024-07-15 diff --git a/swap/src/protocol/alice/swap.rs b/swap/src/protocol/alice/swap.rs index 79236563..3848a2e1 100644 --- a/swap/src/protocol/alice/swap.rs +++ b/swap/src/protocol/alice/swap.rs @@ -1,11 +1,14 @@ //! Run an XMR/BTC swap in the role of Alice. //! Alice holds XMR and wishes receive BTC. +use std::time::Duration; + use crate::asb::{EventLoopHandle, LatestRate}; use crate::bitcoin::ExpiredTimelocks; use crate::env::Config; use crate::protocol::alice::{AliceState, Swap}; use crate::{bitcoin, monero}; use anyhow::{bail, Context, Result}; +use backoff::ExponentialBackoffBuilder; use tokio::select; use tokio::time::timeout; use uuid::Uuid; @@ -111,23 +114,63 @@ where } } AliceState::BtcLocked { state3 } => { - match state3.expired_timelocks(bitcoin_wallet).await? { - ExpiredTimelocks::None { .. } => { - // Record the current monero wallet block height so we don't have to scan from - // block 0 for scenarios where we create a refund wallet. - let monero_wallet_restore_blockheight = monero_wallet.block_height().await?; + // We retry to lock the Monero wallet until we succeed or until the cancel timelock expires. + // + // This is necessary because the monero-wallet-rpc can sometimes error out due to various reasons, such as + // - no connection to the daemon + // - "failed to get output distribution" + // See https://github.com/comit-network/xmr-btc-swap/issues/1726 + let backoff = ExponentialBackoffBuilder::new() + .with_initial_interval(Duration::from_secs(5)) + .with_max_interval(Duration::from_secs(60 * 3)) + .with_max_elapsed_time(None) + .build(); - let transfer_proof = monero_wallet - .transfer(state3.lock_xmr_transfer_request()) - .await?; + let result = backoff::future::retry_notify( + backoff, + || async { + match state3.expired_timelocks(bitcoin_wallet).await { + Ok(ExpiredTimelocks::None { .. }) => { + // Record the current monero wallet block height so we don't have to scan from + // block 0 for scenarios where we create a refund wallet. + let monero_wallet_restore_blockheight = monero_wallet + .block_height() + .await + .map_err(backoff::Error::transient)?; + let transfer_proof = monero_wallet + .transfer(state3.lock_xmr_transfer_request()) + .await + .map_err(backoff::Error::transient)?; + + Ok(Some((monero_wallet_restore_blockheight, transfer_proof))) + } + Ok(_) => Ok(None), + Err(e) => Err(backoff::Error::transient(e)), + } + }, + |err, delay: Duration| { + tracing::warn!( + %err, + delay_secs = delay.as_secs(), + "Failed to lock XMR. We will retry after a delay" + ); + }, + ) + .await; + + match result { + Ok(Some((monero_wallet_restore_blockheight, transfer_proof))) => { AliceState::XmrLockTransactionSent { monero_wallet_restore_blockheight, transfer_proof, state3, } } - _ => AliceState::SafelyAborted, + Ok(None) => AliceState::SafelyAborted, + Err(e) => { + unreachable!("We should retry forever until the cancel timelock expires. But we got an error: {:#}", e); + } } } AliceState::XmrLockTransactionSent { From 33ad3c374a6472210e878041435e2b6a145c4bc4 Mon Sep 17 00:00:00 2001 From: COMIT Botty McBotface <68941619+comit-botty-mc-botface@users.noreply.github.com> Date: Fri, 26 Jul 2024 07:14:31 +1000 Subject: [PATCH 02/24] Prepare release 0.13.4 (#1734) --- CHANGELOG.md | 5 ++++- Cargo.lock | 2 +- swap/Cargo.toml | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e496e3cc..bb8e53e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.13.4] - 2024-07-25 + - ASB: The `history` command can now be used while the asb is running. - ASB: Retry locking of Monero if it fails on first attempt @@ -373,7 +375,8 @@ It is possible to migrate critical data from the old db to the sqlite but there - Fixed an issue where Alice would not verify if Bob's Bitcoin lock transaction is semantically correct, i.e. pays the agreed upon amount to an output owned by both of them. Fixing this required a **breaking change** on the network layer and hence old versions are not compatible with this version. -[unreleased]: https://github.com/comit-network/xmr-btc-swap/compare/0.13.3...HEAD +[unreleased]: https://github.com/comit-network/xmr-btc-swap/compare/0.13.4...HEAD +[0.13.4]: https://github.com/comit-network/xmr-btc-swap/compare/0.13.3...0.13.4 [0.13.3]: https://github.com/comit-network/xmr-btc-swap/compare/0.13.2...0.13.3 [0.13.2]: https://github.com/comit-network/xmr-btc-swap/compare/0.13.1...0.13.2 [0.13.1]: https://github.com/comit-network/xmr-btc-swap/compare/0.13.0...0.13.1 diff --git a/Cargo.lock b/Cargo.lock index 4c2826b8..6ef8e322 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4515,7 +4515,7 @@ checksum = "8049cf85f0e715d6af38dde439cb0ccb91f67fb9f5f63c80f8b43e48356e1a3f" [[package]] name = "swap" -version = "0.13.3" +version = "0.13.4" dependencies = [ "anyhow", "async-compression", diff --git a/swap/Cargo.toml b/swap/Cargo.toml index 6af34a86..a75c29a7 100644 --- a/swap/Cargo.toml +++ b/swap/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "swap" -version = "0.13.3" +version = "0.13.4" authors = [ "The COMIT guys " ] edition = "2021" description = "XMR/BTC trustless atomic swaps." From 0ad78e4f30562b87942fc3357e1caf4669dcdd14 Mon Sep 17 00:00:00 2001 From: binarybaron <86064887+binarybaron@users.noreply.github.com> Date: Fri, 26 Jul 2024 00:20:17 +0200 Subject: [PATCH 03/24] revert: Update CHANGELOG.md --- CHANGELOG.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bb8e53e6..721f9fc2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,8 +7,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -## [0.13.4] - 2024-07-25 - - ASB: The `history` command can now be used while the asb is running. - ASB: Retry locking of Monero if it fails on first attempt From 8284bea778fb4003d339d6fc4ca93f6d8299e635 Mon Sep 17 00:00:00 2001 From: UnstoppableSwap Botty Date: Thu, 25 Jul 2024 22:31:14 +0000 Subject: [PATCH 04/24] Prepare release 0.13.4 --- CHANGELOG.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 721f9fc2..7127c424 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.13.4] - 2024-07-25 + - ASB: The `history` command can now be used while the asb is running. - ASB: Retry locking of Monero if it fails on first attempt @@ -373,7 +375,8 @@ It is possible to migrate critical data from the old db to the sqlite but there - Fixed an issue where Alice would not verify if Bob's Bitcoin lock transaction is semantically correct, i.e. pays the agreed upon amount to an output owned by both of them. Fixing this required a **breaking change** on the network layer and hence old versions are not compatible with this version. -[unreleased]: https://github.com/comit-network/xmr-btc-swap/compare/0.13.4...HEAD +[unreleased]: https://github.com/UnstoppableSwap/xmr-btc-swap/compare/0.13.4...HEAD +[0.13.4]: https://github.com/UnstoppableSwap/xmr-btc-swap/compare/0.13.4...0.13.4 [0.13.4]: https://github.com/comit-network/xmr-btc-swap/compare/0.13.3...0.13.4 [0.13.3]: https://github.com/comit-network/xmr-btc-swap/compare/0.13.2...0.13.3 [0.13.2]: https://github.com/comit-network/xmr-btc-swap/compare/0.13.1...0.13.2 From 49cae19059f09b5eadb72b4f73fef7c82c9913e0 Mon Sep 17 00:00:00 2001 From: binarybaron Date: Fri, 26 Jul 2024 11:40:16 +0200 Subject: [PATCH 05/24] fix: Reintroduce docker build action --- .github/workflows/build-release-binaries.yml | 53 +++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-release-binaries.yml b/.github/workflows/build-release-binaries.yml index 662e3a5e..4f466ada 100644 --- a/.github/workflows/build-release-binaries.yml +++ b/.github/workflows/build-release-binaries.yml @@ -4,6 +4,9 @@ on: release: types: [created] +env: + DOCKER_IMAGE_NAME: unstoppableswap/asb + jobs: build_binaries: name: Build @@ -82,7 +85,7 @@ jobs: run: target/${{ matrix.target }}/release/${{ matrix.bin }} --help - id: create-archive-name - shell: python # Use python to have a prettier name for the archive on Windows. + shell: python run: | import platform os_info = platform.uname() @@ -122,3 +125,51 @@ jobs: asset_path: ./${{ steps.create-archive-name.outputs.archive }} asset_name: ${{ steps.create-archive-name.outputs.archive }} asset_content_type: application/gzip + + build_and_push_docker: + name: Build and Push Docker Image + runs-on: ubuntu-latest + needs: build_binaries + steps: + - name: Checkout code + uses: actions/checkout@v4.1.7 + with: + ref: ${{ github.event.release.target_commitish }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Login to DockerHub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Set Docker tags + id: docker_tags + run: | + if [[ ${{ github.event.release.tag_name }} == "preview" ]]; then + echo "::set-output name=preview::true" + else + echo "::set-output name=preview::false" + fi + + - name: Build and push Docker image + uses: docker/build-push-action@v4 + with: + context: . + file: ./Dockerfile + push: true + tags: | + ${{ env.DOCKER_IMAGE_NAME }}:${{ github.event.release.tag_name }} + ${{ env.DOCKER_IMAGE_NAME }}:latest + if: steps.docker_tags.outputs.preview == 'false' + + - name: Build and push Docker image without latest tag (preview release) + uses: docker/build-push-action@v4 + with: + context: . + file: ./Dockerfile + push: true + tags: ${{ env.DOCKER_IMAGE_NAME }}:${{ github.event.release.tag_name }} + if: steps.docker_tags.outputs.preview == 'true' From 77a43ba28cca49d269f22ba7dce13c19c5b435a7 Mon Sep 17 00:00:00 2001 From: binarybaron Date: Fri, 26 Jul 2024 11:45:48 +0200 Subject: [PATCH 06/24] fix: Reintroduce Dockerfile --- Dockerfile | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..2dbf5397 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,18 @@ +FROM rust:1.59-slim AS builder + +WORKDIR /build + +RUN apt-get update +RUN apt-get install -y git clang cmake libsnappy-dev + +COPY . . + +RUN cargo build --release --bin=asb + +FROM debian:bullseye-slim + +WORKDIR /data + +COPY --from=builder /build/target/release/asb /bin/asb + +ENTRYPOINT ["asb"] From b52e07ace9e6d7853fbc20bc965141db7d7756fb Mon Sep 17 00:00:00 2001 From: binarybaron Date: Fri, 26 Jul 2024 11:46:19 +0200 Subject: [PATCH 07/24] Revert "fix: Reintroduce docker build action" This reverts commit 49cae19059f09b5eadb72b4f73fef7c82c9913e0. --- .github/workflows/build-release-binaries.yml | 53 +------------------- 1 file changed, 1 insertion(+), 52 deletions(-) diff --git a/.github/workflows/build-release-binaries.yml b/.github/workflows/build-release-binaries.yml index 4f466ada..662e3a5e 100644 --- a/.github/workflows/build-release-binaries.yml +++ b/.github/workflows/build-release-binaries.yml @@ -4,9 +4,6 @@ on: release: types: [created] -env: - DOCKER_IMAGE_NAME: unstoppableswap/asb - jobs: build_binaries: name: Build @@ -85,7 +82,7 @@ jobs: run: target/${{ matrix.target }}/release/${{ matrix.bin }} --help - id: create-archive-name - shell: python + shell: python # Use python to have a prettier name for the archive on Windows. run: | import platform os_info = platform.uname() @@ -125,51 +122,3 @@ jobs: asset_path: ./${{ steps.create-archive-name.outputs.archive }} asset_name: ${{ steps.create-archive-name.outputs.archive }} asset_content_type: application/gzip - - build_and_push_docker: - name: Build and Push Docker Image - runs-on: ubuntu-latest - needs: build_binaries - steps: - - name: Checkout code - uses: actions/checkout@v4.1.7 - with: - ref: ${{ github.event.release.target_commitish }} - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - - name: Login to DockerHub - uses: docker/login-action@v2 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Set Docker tags - id: docker_tags - run: | - if [[ ${{ github.event.release.tag_name }} == "preview" ]]; then - echo "::set-output name=preview::true" - else - echo "::set-output name=preview::false" - fi - - - name: Build and push Docker image - uses: docker/build-push-action@v4 - with: - context: . - file: ./Dockerfile - push: true - tags: | - ${{ env.DOCKER_IMAGE_NAME }}:${{ github.event.release.tag_name }} - ${{ env.DOCKER_IMAGE_NAME }}:latest - if: steps.docker_tags.outputs.preview == 'false' - - - name: Build and push Docker image without latest tag (preview release) - uses: docker/build-push-action@v4 - with: - context: . - file: ./Dockerfile - push: true - tags: ${{ env.DOCKER_IMAGE_NAME }}:${{ github.event.release.tag_name }} - if: steps.docker_tags.outputs.preview == 'true' From f29bf20e8d694ae29a7202efe2cc0f014a6f7248 Mon Sep 17 00:00:00 2001 From: binarybaron Date: Fri, 26 Jul 2024 11:46:27 +0200 Subject: [PATCH 08/24] Revert "fix: Reintroduce Dockerfile" This reverts commit 77a43ba28cca49d269f22ba7dce13c19c5b435a7. --- Dockerfile | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 2dbf5397..00000000 --- a/Dockerfile +++ /dev/null @@ -1,18 +0,0 @@ -FROM rust:1.59-slim AS builder - -WORKDIR /build - -RUN apt-get update -RUN apt-get install -y git clang cmake libsnappy-dev - -COPY . . - -RUN cargo build --release --bin=asb - -FROM debian:bullseye-slim - -WORKDIR /data - -COPY --from=builder /build/target/release/asb /bin/asb - -ENTRYPOINT ["asb"] From 45e14c5a1e1b13807db182abfbe2885e5f8cf9f7 Mon Sep 17 00:00:00 2001 From: binarybaron Date: Fri, 26 Jul 2024 11:51:33 +0200 Subject: [PATCH 09/24] Revert: 8284bea778fb4003d339d6fc4ca93f6d8299e635 --- CHANGELOG.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7127c424..bb8e53e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -375,8 +375,7 @@ It is possible to migrate critical data from the old db to the sqlite but there - Fixed an issue where Alice would not verify if Bob's Bitcoin lock transaction is semantically correct, i.e. pays the agreed upon amount to an output owned by both of them. Fixing this required a **breaking change** on the network layer and hence old versions are not compatible with this version. -[unreleased]: https://github.com/UnstoppableSwap/xmr-btc-swap/compare/0.13.4...HEAD -[0.13.4]: https://github.com/UnstoppableSwap/xmr-btc-swap/compare/0.13.4...0.13.4 +[unreleased]: https://github.com/comit-network/xmr-btc-swap/compare/0.13.4...HEAD [0.13.4]: https://github.com/comit-network/xmr-btc-swap/compare/0.13.3...0.13.4 [0.13.3]: https://github.com/comit-network/xmr-btc-swap/compare/0.13.2...0.13.3 [0.13.2]: https://github.com/comit-network/xmr-btc-swap/compare/0.13.1...0.13.2 From f3640aceb2d5e412e650a098957e366836f82351 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 26 Jul 2024 12:23:43 +0000 Subject: [PATCH 10/24] build(deps): bump toml from 0.8.15 to 0.8.16 Bumps [toml](https://github.com/toml-rs/toml) from 0.8.15 to 0.8.16. - [Commits](https://github.com/toml-rs/toml/compare/toml-v0.8.15...toml-v0.8.16) --- updated-dependencies: - dependency-name: toml dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- Cargo.lock | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6ef8e322..73be37fc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -743,7 +743,7 @@ dependencies = [ "nom", "pathdiff", "serde", - "toml 0.8.15", + "toml 0.8.16", ] [[package]] @@ -4046,9 +4046,9 @@ dependencies = [ [[package]] name = "serde_spanned" -version = "0.6.6" +version = "0.6.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79e674e01f999af37c49f70a6ede167a8a60b2503e56c5599532a65baa5969a0" +checksum = "eb5b1b31579f3811bf615c144393417496f152e12ac8b7663bf664f4a815306d" dependencies = [ "serde", ] @@ -4579,7 +4579,7 @@ dependencies = [ "tokio-tar", "tokio-tungstenite", "tokio-util", - "toml 0.8.15", + "toml 0.8.16", "torut", "tracing", "tracing-appender", @@ -4919,9 +4919,9 @@ dependencies = [ [[package]] name = "toml" -version = "0.8.15" +version = "0.8.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac2caab0bf757388c6c0ae23b3293fdb463fee59434529014f85e3263b995c28" +checksum = "81967dd0dd2c1ab0bc3468bd7caecc32b8a4aa47d0c8c695d8c2b2108168d62c" dependencies = [ "serde", "serde_spanned", @@ -4931,18 +4931,18 @@ dependencies = [ [[package]] name = "toml_datetime" -version = "0.6.6" +version = "0.6.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4badfd56924ae69bcc9039335b2e017639ce3f9b001c393c1b2d1ef846ce2cbf" +checksum = "f8fb9f64314842840f1d940ac544da178732128f1c78c21772e876579e0da1db" dependencies = [ "serde", ] [[package]] name = "toml_edit" -version = "0.22.16" +version = "0.22.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "278f3d518e152219c994ce877758516bca5e118eaed6996192a774fb9fbf0788" +checksum = "8d9f8729f5aea9562aac1cc0441f5d6de3cff1ee0c5d67293eeca5eb36ee7c16" dependencies = [ "indexmap 2.1.0", "serde", From 011aa0cb9cd62a0c06ee80b5e7570a71924c969d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 29 Jul 2024 11:25:26 +0000 Subject: [PATCH 11/24] build(deps): bump thomaseizinger/keep-a-changelog-new-release Bumps [thomaseizinger/keep-a-changelog-new-release](https://github.com/thomaseizinger/keep-a-changelog-new-release) from 3.0.0 to 3.1.0. - [Release notes](https://github.com/thomaseizinger/keep-a-changelog-new-release/releases) - [Changelog](https://github.com/thomaseizinger/keep-a-changelog-new-release/blob/master/CHANGELOG.md) - [Commits](https://github.com/thomaseizinger/keep-a-changelog-new-release/compare/3.0.0...3.1.0) --- updated-dependencies: - dependency-name: thomaseizinger/keep-a-changelog-new-release dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .github/workflows/draft-new-release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/draft-new-release.yml b/.github/workflows/draft-new-release.yml index 74ff34ba..9b9c849d 100644 --- a/.github/workflows/draft-new-release.yml +++ b/.github/workflows/draft-new-release.yml @@ -20,7 +20,7 @@ jobs: run: git checkout -b release/${{ github.event.inputs.version }} - name: Update changelog - uses: thomaseizinger/keep-a-changelog-new-release@3.0.0 + uses: thomaseizinger/keep-a-changelog-new-release@3.1.0 with: version: ${{ github.event.inputs.version }} changelogPath: CHANGELOG.md From 254874276c99bbb7ef6f2c7c5cf75c8fb1d63cc5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 29 Jul 2024 12:00:29 +0000 Subject: [PATCH 12/24] build(deps): bump serde_json from 1.0.118 to 1.0.121 Bumps [serde_json](https://github.com/serde-rs/json) from 1.0.118 to 1.0.121. - [Release notes](https://github.com/serde-rs/json/releases) - [Commits](https://github.com/serde-rs/json/compare/v1.0.118...v1.0.121) --- updated-dependencies: - dependency-name: serde_json dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- Cargo.lock | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 73be37fc..48d0552a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4035,11 +4035,12 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.118" +version = "1.0.121" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d947f6b3163d8857ea16c4fa0dd4840d52f3041039a85decd46867eb1abef2e4" +checksum = "4ab380d7d9f22ef3f21ad3e6c1ebe8e4fc7a2000ccba2e4d71fc96f15b2cb609" dependencies = [ "itoa", + "memchr", "ryu", "serde", ] From 9700d192b2623f35fbb5549d056ee76db5a5546a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 29 Jul 2024 12:02:43 +0000 Subject: [PATCH 13/24] build(deps): bump tokio-socks from 0.5.1 to 0.5.2 Bumps [tokio-socks](https://github.com/sticnarf/tokio-socks) from 0.5.1 to 0.5.2. - [Release notes](https://github.com/sticnarf/tokio-socks/releases) - [Changelog](https://github.com/sticnarf/tokio-socks/blob/master/CHANGELOG.md) - [Commits](https://github.com/sticnarf/tokio-socks/compare/v0.5.1...v0.5.2) --- updated-dependencies: - dependency-name: tokio-socks dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 73be37fc..b6804d26 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4841,9 +4841,9 @@ dependencies = [ [[package]] name = "tokio-socks" -version = "0.5.1" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51165dfa029d2a65969413a6cc96f354b86b464498702f174a4efa13608fd8c0" +checksum = "0d4770b8024672c1101b3f6733eab95b18007dbe0847a8afe341fcf79e06043f" dependencies = [ "either", "futures-util", From 6e09c73cf369c2a9ae5620e9c88fcb80e11ef031 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 31 Jul 2024 11:39:26 +0000 Subject: [PATCH 14/24] build(deps): bump toml from 0.8.16 to 0.8.17 Bumps [toml](https://github.com/toml-rs/toml) from 0.8.16 to 0.8.17. - [Commits](https://github.com/toml-rs/toml/compare/toml-v0.8.16...toml-v0.8.17) --- updated-dependencies: - dependency-name: toml dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- Cargo.lock | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bb01de1b..78413bfc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -743,7 +743,7 @@ dependencies = [ "nom", "pathdiff", "serde", - "toml 0.8.16", + "toml 0.8.17", ] [[package]] @@ -4580,7 +4580,7 @@ dependencies = [ "tokio-tar", "tokio-tungstenite", "tokio-util", - "toml 0.8.16", + "toml 0.8.17", "torut", "tracing", "tracing-appender", @@ -4920,9 +4920,9 @@ dependencies = [ [[package]] name = "toml" -version = "0.8.16" +version = "0.8.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81967dd0dd2c1ab0bc3468bd7caecc32b8a4aa47d0c8c695d8c2b2108168d62c" +checksum = "7a44eede9b727419af8095cb2d72fab15487a541f54647ad4414b34096ee4631" dependencies = [ "serde", "serde_spanned", @@ -4932,18 +4932,18 @@ dependencies = [ [[package]] name = "toml_datetime" -version = "0.6.7" +version = "0.6.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8fb9f64314842840f1d940ac544da178732128f1c78c21772e876579e0da1db" +checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" dependencies = [ "serde", ] [[package]] name = "toml_edit" -version = "0.22.17" +version = "0.22.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d9f8729f5aea9562aac1cc0441f5d6de3cff1ee0c5d67293eeca5eb36ee7c16" +checksum = "1490595c74d930da779e944f5ba2ecdf538af67df1a9848cbd156af43c1b7cf0" dependencies = [ "indexmap 2.1.0", "serde", @@ -5767,9 +5767,9 @@ checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" [[package]] name = "winnow" -version = "0.6.5" +version = "0.6.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dffa400e67ed5a4dd237983829e66475f0a4a26938c4b04c21baede6262215b8" +checksum = "b480ae9340fc261e6be3e95a1ba86d54ae3f9171132a73ce8d4bbaf68339507c" dependencies = [ "memchr", ] From 587212abc7e4c5d81bea31b9e236b3ef33f58e4b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 1 Aug 2024 11:38:09 +0000 Subject: [PATCH 15/24] build(deps): bump mockito from 1.4.0 to 1.5.0 Bumps [mockito](https://github.com/lipanski/mockito) from 1.4.0 to 1.5.0. - [Release notes](https://github.com/lipanski/mockito/releases) - [Commits](https://github.com/lipanski/mockito/compare/1.4.0...1.5.0) --- updated-dependencies: - dependency-name: mockito dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- Cargo.lock | 14 ++++++++++---- swap/Cargo.toml | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 78413bfc..d75c78d9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1774,6 +1774,7 @@ dependencies = [ "http 1.0.0", "http-body 1.0.0", "httparse", + "httpdate", "itoa", "pin-project-lite 0.2.13", "smallvec", @@ -2593,14 +2594,19 @@ dependencies = [ [[package]] name = "mockito" -version = "1.4.0" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2f6e023aa5bdf392aa06c78e4a4e6d498baab5138d0c993503350ebbc37bf1e" +checksum = "09b34bd91b9e5c5b06338d392463e1318d683cf82ec3d3af4014609be6e2108d" dependencies = [ "assert-json-diff", + "bytes", "colored", - "futures-core", - "hyper 0.14.28", + "futures-util", + "http 1.0.0", + "http-body 1.0.0", + "http-body-util", + "hyper 1.4.1", + "hyper-util", "log", "rand 0.8.3", "regex", diff --git a/swap/Cargo.toml b/swap/Cargo.toml index a75c29a7..f7837c6a 100644 --- a/swap/Cargo.toml +++ b/swap/Cargo.toml @@ -81,7 +81,7 @@ bitcoin-harness = { git = "https://github.com/delta1/bitcoin-harness-rs.git", re get-port = "3" hyper = "1.4" jsonrpsee = { version = "0.16.2", features = [ "ws-client" ] } -mockito = "1.4" +mockito = "1.5" monero-harness = { path = "../monero-harness" } port_check = "0.2" proptest = "1" From af6bc47ed344055cc9e5e6a6a9ab15d8eb20528b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 1 Aug 2024 11:39:35 +0000 Subject: [PATCH 16/24] build(deps): bump toml from 0.8.17 to 0.8.19 Bumps [toml](https://github.com/toml-rs/toml) from 0.8.17 to 0.8.19. - [Commits](https://github.com/toml-rs/toml/compare/toml-v0.8.17...toml-v0.8.19) --- updated-dependencies: - dependency-name: toml dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- Cargo.lock | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 78413bfc..fcb20f9b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -743,7 +743,7 @@ dependencies = [ "nom", "pathdiff", "serde", - "toml 0.8.17", + "toml 0.8.19", ] [[package]] @@ -4580,7 +4580,7 @@ dependencies = [ "tokio-tar", "tokio-tungstenite", "tokio-util", - "toml 0.8.17", + "toml 0.8.19", "torut", "tracing", "tracing-appender", @@ -4920,9 +4920,9 @@ dependencies = [ [[package]] name = "toml" -version = "0.8.17" +version = "0.8.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a44eede9b727419af8095cb2d72fab15487a541f54647ad4414b34096ee4631" +checksum = "a1ed1f98e3fdc28d6d910e6737ae6ab1a93bf1985935a1193e68f93eeb68d24e" dependencies = [ "serde", "serde_spanned", @@ -4941,9 +4941,9 @@ dependencies = [ [[package]] name = "toml_edit" -version = "0.22.18" +version = "0.22.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1490595c74d930da779e944f5ba2ecdf538af67df1a9848cbd156af43c1b7cf0" +checksum = "583c44c02ad26b0c3f3066fe629275e50627026c51ac2e595cca4c230ce1ce1d" dependencies = [ "indexmap 2.1.0", "serde", @@ -5767,9 +5767,9 @@ checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" [[package]] name = "winnow" -version = "0.6.16" +version = "0.6.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b480ae9340fc261e6be3e95a1ba86d54ae3f9171132a73ce8d4bbaf68339507c" +checksum = "68a9bda4691f099d435ad181000724da8e5899daa10713c2d432552b9ccd3a6f" dependencies = [ "memchr", ] From cc854be8f4f2568905703b12a728320987ee9f5f Mon Sep 17 00:00:00 2001 From: binarybaron <86064887+binarybaron@users.noreply.github.com> Date: Thu, 1 Aug 2024 18:35:03 +0200 Subject: [PATCH 17/24] feat: Enhance history command with more swap details (#1725) --- swap/src/api.rs | 4 ++ swap/src/api/request.rs | 98 ++++++++++++++++++++++++++++++-- swap/src/asb/command.rs | 24 ++++++-- swap/src/bin/asb.rs | 86 +++++++++++++++++++++++++--- swap/src/cli/command.rs | 30 ++++++++-- swap/src/monero.rs | 15 +++-- swap/src/protocol/alice/state.rs | 4 +- swap/src/protocol/alice/swap.rs | 2 +- swap/src/protocol/bob/state.rs | 2 +- swap/tests/rpc.rs | 19 ++++++- 10 files changed, 248 insertions(+), 36 deletions(-) diff --git a/swap/src/api.rs b/swap/src/api.rs index 5640c833..a87db7c5 100644 --- a/swap/src/api.rs +++ b/swap/src/api.rs @@ -167,6 +167,7 @@ pub struct Context { pub swap_lock: Arc, pub config: Config, pub tasks: Arc, + pub is_daemon: bool, } #[allow(clippy::too_many_arguments)] @@ -180,6 +181,7 @@ impl Context { debug: bool, json: bool, server_address: Option, + is_daemon: bool, ) -> Result { let data_dir = data::data_dir_from(data, is_testnet)?; let env_config = env_config_from(is_testnet); @@ -241,6 +243,7 @@ impl Context { }, swap_lock: Arc::new(SwapLock::new()), tasks: Arc::new(PendingTaskList::default()), + is_daemon, }; Ok(context) @@ -265,6 +268,7 @@ impl Context { monero_rpc_process: None, swap_lock: Arc::new(SwapLock::new()), tasks: Arc::new(PendingTaskList::default()), + is_daemon: true, } } diff --git a/swap/src/api/request.rs b/swap/src/api/request.rs index b1e9c68c..d47e9a0d 100644 --- a/swap/src/api/request.rs +++ b/swap/src/api/request.rs @@ -8,9 +8,12 @@ use crate::protocol::bob::{BobState, Swap}; use crate::protocol::{bob, State}; use crate::{bitcoin, cli, monero, rpc}; use anyhow::{bail, Context as AnyContext, Result}; +use comfy_table::Table; use libp2p::core::Multiaddr; use qrcode::render::unicode; use qrcode::QrCode; +use rust_decimal::prelude::FromPrimitive; +use rust_decimal::Decimal; use serde_json::json; use std::cmp::min; use std::convert::TryInto; @@ -638,14 +641,97 @@ impl Request { }) } Method::History => { - let swaps = context.db.all().await?; - let mut vec: Vec<(Uuid, String)> = Vec::new(); - for (swap_id, state) in swaps { - let state: BobState = state.try_into()?; - vec.push((swap_id, state.to_string())); + let mut table = Table::new(); + table.set_header(vec![ + "Swap ID", + "Start Date", + "State", + "BTC Amount", + "XMR Amount", + "Exchange Rate", + "Trading Partner Peer ID", + ]); + + let all_swaps = context.db.all().await?; + let mut json_results = Vec::new(); + + for (swap_id, state) in all_swaps { + let result: Result<_> = async { + let latest_state: BobState = state.try_into()?; + let all_states = context.db.get_states(swap_id).await?; + let state3 = all_states + .iter() + .find_map(|s| { + if let State::Bob(BobState::BtcLocked { state3, .. }) = s { + Some(state3) + } else { + None + } + }) + .context("Failed to get \"BtcLocked\" state")?; + + let swap_start_date = context.db.get_swap_start_date(swap_id).await?; + let peer_id = context.db.get_peer_id(swap_id).await?; + let btc_amount = state3.tx_lock.lock_amount(); + let xmr_amount = state3.xmr; + let exchange_rate = Decimal::from_f64(btc_amount.to_btc()) + .ok_or_else(|| { + anyhow::anyhow!("Failed to convert BTC amount to Decimal") + })? + .checked_div(xmr_amount.as_xmr()) + .ok_or_else(|| anyhow::anyhow!("Division by zero or overflow"))?; + let exchange_rate = format!("{} XMR/BTC", exchange_rate.round_dp(8)); + + let swap_data = json!({ + "swapId": swap_id.to_string(), + "startDate": swap_start_date.to_string(), + "state": latest_state.to_string(), + "btcAmount": btc_amount.to_string(), + "xmrAmount": xmr_amount.to_string(), + "exchangeRate": exchange_rate, + "tradingPartnerPeerId": peer_id.to_string() + }); + + if context.config.json { + tracing::info!( + swap_id = %swap_id, + swap_start_date = %swap_start_date, + latest_state = %latest_state, + btc_amount = %btc_amount, + xmr_amount = %xmr_amount, + exchange_rate = %exchange_rate, + trading_partner_peer_id = %peer_id, + "Found swap in database" + ); + } else { + table.add_row(vec![ + swap_id.to_string(), + swap_start_date.to_string(), + latest_state.to_string(), + btc_amount.to_string(), + xmr_amount.to_string(), + exchange_rate, + peer_id.to_string(), + ]); + } + + Ok(swap_data) + } + .await; + + match result { + Ok(swap_data) => json_results.push(swap_data), + Err(e) => { + tracing::error!(swap_id = %swap_id, error = %e, "Failed to get swap details") + } + } } - Ok(json!({ "swaps": vec })) + if !context.config.json && !context.is_daemon { + println!("{}", table); + } + + Ok(json!({"swaps": json_results})) } Method::GetRawStates => { let raw_history = context.db.raw_all().await?; diff --git a/swap/src/asb/command.rs b/swap/src/asb/command.rs index f22e1500..260b5e9d 100644 --- a/swap/src/asb/command.rs +++ b/swap/src/asb/command.rs @@ -33,13 +33,13 @@ where env_config: env_config(testnet), cmd: Command::Start { resume_only }, }, - RawCommand::History => Arguments { + RawCommand::History { only_unfinished } => Arguments { testnet, json, disable_timestamp, config_path: config_path(config, testnet)?, env_config: env_config(testnet), - cmd: Command::History, + cmd: Command::History { only_unfinished }, }, RawCommand::WithdrawBtc { amount, address } => Arguments { testnet, @@ -195,7 +195,9 @@ pub enum Command { Start { resume_only: bool, }, - History, + History { + only_unfinished: bool, + }, Config, WithdrawBtc { amount: Option, @@ -269,7 +271,13 @@ pub enum RawCommand { resume_only: bool, }, #[structopt(about = "Prints swap-id and the state of each swap ever made.")] - History, + History { + #[structopt( + long = "only-unfinished", + help = "If set, only unfinished swaps will be printed." + )] + only_unfinished: bool, + }, #[structopt(about = "Prints the current config")] Config, #[structopt(about = "Allows withdrawing BTC from the internal Bitcoin wallet.")] @@ -387,7 +395,9 @@ mod tests { disable_timestamp: false, config_path: default_mainnet_conf_path, env_config: mainnet_env_config, - cmd: Command::History, + cmd: Command::History { + only_unfinished: false, + }, }; let args = parse_args(raw_ars).unwrap(); assert_eq!(expected_args, args); @@ -570,7 +580,9 @@ mod tests { disable_timestamp: false, config_path: default_testnet_conf_path, env_config: testnet_env_config, - cmd: Command::History, + cmd: Command::History { + only_unfinished: false, + }, }; let args = parse_args(raw_ars).unwrap(); assert_eq!(expected_args, args); diff --git a/swap/src/bin/asb.rs b/swap/src/bin/asb.rs index 0f2f13b5..66630b88 100644 --- a/swap/src/bin/asb.rs +++ b/swap/src/bin/asb.rs @@ -18,6 +18,8 @@ use libp2p::core::multiaddr::Protocol; use libp2p::core::Multiaddr; use libp2p::swarm::AddressScore; use libp2p::Swarm; +use rust_decimal::prelude::FromPrimitive; +use rust_decimal::Decimal; use std::convert::TryInto; use std::env; use std::net::{IpAddr, Ipv4Addr, SocketAddr}; @@ -33,7 +35,9 @@ use swap::common::check_latest_version; use swap::database::{open_db, AccessMode}; use swap::network::rendezvous::XmrBtcNamespace; use swap::network::swarm; +use swap::protocol::alice::swap::is_complete; use swap::protocol::alice::{run, AliceState}; +use swap::protocol::State; use swap::seed::Seed; use swap::tor::AuthenticatedClient; use swap::{asb, bitcoin, kraken, monero, tor}; @@ -224,19 +228,87 @@ async fn main() -> Result<()> { event_loop.run().await; } - Command::History => { + Command::History { only_unfinished } => { let db = open_db(config.data.dir.join("sqlite"), AccessMode::ReadOnly).await?; + let mut table: Table = Table::new(); - let mut table = Table::new(); + table.set_header(vec![ + "Swap ID", + "Start Date", + "State", + "BTC Amount", + "XMR Amount", + "Exchange Rate", + "Trading Partner Peer ID", + "Completed", + ]); - table.set_header(vec!["SWAP ID", "STATE"]); + let all_swaps = db.all().await?; + for (swap_id, state) in all_swaps { + if let Err(e) = async { + let latest_state: AliceState = state.try_into()?; + let is_completed = is_complete(&latest_state); - for (swap_id, state) in db.all().await? { - let state: AliceState = state.try_into()?; - table.add_row(vec![swap_id.to_string(), state.to_string()]); + if only_unfinished && is_completed { + return Ok::<_, anyhow::Error>(()); + } + + let all_states = db.get_states(swap_id).await?; + let state3 = all_states + .iter() + .find_map(|s| match s { + State::Alice(AliceState::BtcLockTransactionSeen { state3 }) => { + Some(state3) + } + _ => None, + }) + .context("Failed to get \"BtcLockTransactionSeen\" state")?; + + let swap_start_date = db.get_swap_start_date(swap_id).await?; + let peer_id = db.get_peer_id(swap_id).await?; + + let exchange_rate = Decimal::from_f64(state3.btc.to_btc()) + .ok_or_else(|| anyhow::anyhow!("Failed to convert BTC amount to Decimal"))? + .checked_div(state3.xmr.as_xmr()) + .ok_or_else(|| anyhow::anyhow!("Division by zero or overflow"))?; + let exchange_rate = format!("{} XMR/BTC", exchange_rate.round_dp(8)); + + if json { + tracing::info!( + swap_id = %swap_id, + swap_start_date = %swap_start_date, + latest_state = %latest_state, + btc_amount = %state3.btc, + xmr_amount = %state3.xmr, + exchange_rate = %exchange_rate, + trading_partner_peer_id = %peer_id, + completed = is_completed, + "Found swap in database" + ); + } else { + table.add_row(vec![ + swap_id.to_string(), + swap_start_date.to_string(), + latest_state.to_string(), + state3.btc.to_string(), + state3.xmr.to_string(), + exchange_rate, + peer_id.to_string(), + is_completed.to_string(), + ]); + } + + Ok::<_, anyhow::Error>(()) + } + .await + { + tracing::error!(swap_id = %swap_id, error = %e, "Failed to get swap details"); + } } - println!("{}", table); + if !json { + println!("{}", table); + } } Command::Config => { let config_json = serde_json::to_string_pretty(&config)?; diff --git a/swap/src/cli/command.rs b/swap/src/cli/command.rs index 4881d94e..6c460f82 100644 --- a/swap/src/cli/command.rs +++ b/swap/src/cli/command.rs @@ -78,6 +78,7 @@ where debug, json, None, + false, ) .await?; @@ -100,14 +101,16 @@ where let request = Request::new(Method::History); let context = - Context::build(None, None, None, data, is_testnet, debug, json, None).await?; + Context::build(None, None, None, data, is_testnet, debug, json, None, false) + .await?; (context, request) } CliCommand::Config => { let request = Request::new(Method::Config); let context = - Context::build(None, None, None, data, is_testnet, debug, json, None).await?; + Context::build(None, None, None, data, is_testnet, debug, json, None, false) + .await?; (context, request) } CliCommand::Balance { bitcoin } => { @@ -124,6 +127,7 @@ where debug, json, None, + false, ) .await?; (context, request) @@ -145,6 +149,7 @@ where debug, json, server_address, + true, ) .await?; (context, request) @@ -166,6 +171,7 @@ where debug, json, None, + false, ) .await?; (context, request) @@ -187,6 +193,7 @@ where debug, json, None, + false, ) .await?; (context, request) @@ -207,6 +214,7 @@ where debug, json, None, + false, ) .await?; (context, request) @@ -217,8 +225,18 @@ where } => { let request = Request::new(Method::ListSellers { rendezvous_point }); - let context = - Context::build(None, None, Some(tor), data, is_testnet, debug, json, None).await?; + let context = Context::build( + None, + None, + Some(tor), + data, + is_testnet, + debug, + json, + None, + false, + ) + .await?; (context, request) } @@ -234,6 +252,7 @@ where debug, json, None, + false, ) .await?; (context, request) @@ -244,7 +263,8 @@ where let request = Request::new(Method::MoneroRecovery { swap_id }); let context = - Context::build(None, None, None, data, is_testnet, debug, json, None).await?; + Context::build(None, None, None, data, is_testnet, debug, json, None, false) + .await?; (context, request) } diff --git a/swap/src/monero.rs b/swap/src/monero.rs index 8205e75f..e5dd9e80 100644 --- a/swap/src/monero.rs +++ b/swap/src/monero.rs @@ -142,6 +142,14 @@ impl Amount { Decimal::from(self.as_piconero()) } + pub fn as_xmr(&self) -> Decimal { + let mut decimal = Decimal::from(self.0); + decimal + .set_scale(12) + .expect("12 is smaller than max precision of 28"); + decimal + } + fn from_decimal(amount: Decimal) -> Result { let piconeros_dec = amount.mul(Decimal::from_u64(PICONERO_OFFSET).expect("constant to fit into u64")); @@ -184,11 +192,8 @@ impl From for u64 { impl fmt::Display for Amount { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - let mut decimal = Decimal::from(self.0); - decimal - .set_scale(12) - .expect("12 is smaller than max precision of 28"); - write!(f, "{} XMR", decimal) + let xmr_value = self.as_xmr(); + write!(f, "{} XMR", xmr_value) } } diff --git a/swap/src/protocol/alice/state.rs b/swap/src/protocol/alice/state.rs index f0acab23..7627a529 100644 --- a/swap/src/protocol/alice/state.rs +++ b/swap/src/protocol/alice/state.rs @@ -384,8 +384,8 @@ pub struct State3 { S_b_bitcoin: bitcoin::PublicKey, pub v: monero::PrivateViewKey, #[serde(with = "::bitcoin::util::amount::serde::as_sat")] - btc: bitcoin::Amount, - xmr: monero::Amount, + pub btc: bitcoin::Amount, + pub xmr: monero::Amount, pub cancel_timelock: CancelTimelock, pub punish_timelock: PunishTimelock, refund_address: bitcoin::Address, diff --git a/swap/src/protocol/alice/swap.rs b/swap/src/protocol/alice/swap.rs index 3848a2e1..14f718d3 100644 --- a/swap/src/protocol/alice/swap.rs +++ b/swap/src/protocol/alice/swap.rs @@ -440,7 +440,7 @@ where }) } -pub(crate) fn is_complete(state: &AliceState) -> bool { +pub fn is_complete(state: &AliceState) -> bool { matches!( state, AliceState::XmrRefunded diff --git a/swap/src/protocol/bob/state.rs b/swap/src/protocol/bob/state.rs index 8fe5ca32..04e7778e 100644 --- a/swap/src/protocol/bob/state.rs +++ b/swap/src/protocol/bob/state.rs @@ -369,7 +369,7 @@ pub struct State3 { S_a_monero: monero::PublicKey, S_a_bitcoin: bitcoin::PublicKey, v: monero::PrivateViewKey, - xmr: monero::Amount, + pub xmr: monero::Amount, pub cancel_timelock: CancelTimelock, punish_timelock: PunishTimelock, refund_address: bitcoin::Address, diff --git a/swap/tests/rpc.rs b/swap/tests/rpc.rs index 5dc640d4..553ccf46 100644 --- a/swap/tests/rpc.rs +++ b/swap/tests/rpc.rs @@ -103,13 +103,26 @@ mod test { let (client, _, _) = setup_daemon(harness_ctx).await; - let response: HashMap> = client + let response: HashMap> = client .request("get_history", ObjectParams::new()) .await .unwrap(); - let swaps: Vec<(Uuid, String)> = vec![(bob_swap_id, "btc is locked".to_string())]; - assert_eq!(response, HashMap::from([("swaps".to_string(), swaps)])); + let swaps = response.get("swaps").unwrap(); + assert_eq!(swaps.len(), 1); + + assert_has_keys_serde( + swaps[0].as_object().unwrap(), + &[ + "swapId", + "startDate", + "state", + "btcAmount", + "xmrAmount", + "exchangeRate", + "tradingPartnerPeerId", + ], + ); let response: HashMap>> = client .request("get_raw_states", ObjectParams::new()) From 9aaa7d358f565384eda5592914ecea9122a79d46 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 2 Aug 2024 11:39:10 +0000 Subject: [PATCH 18/24] build(deps): bump serde_json from 1.0.121 to 1.0.122 Bumps [serde_json](https://github.com/serde-rs/json) from 1.0.121 to 1.0.122. - [Release notes](https://github.com/serde-rs/json/releases) - [Commits](https://github.com/serde-rs/json/compare/v1.0.121...v1.0.122) --- updated-dependencies: - dependency-name: serde_json dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7f374293..c95f4443 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4041,9 +4041,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.121" +version = "1.0.122" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ab380d7d9f22ef3f21ad3e6c1ebe8e4fc7a2000ccba2e4d71fc96f15b2cb609" +checksum = "784b6203951c57ff748476b126ccb5e8e2959a5c19e5c617ab1956be3dbc68da" dependencies = [ "itoa", "memchr", From 6a76e9efbe2c06febd2da3263b6e789308b46cd8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 5 Aug 2024 11:18:44 +0000 Subject: [PATCH 19/24] build(deps): bump tempfile from 3.10.1 to 3.11.0 Bumps [tempfile](https://github.com/Stebalien/tempfile) from 3.10.1 to 3.11.0. - [Changelog](https://github.com/Stebalien/tempfile/blob/master/CHANGELOG.md) - [Commits](https://github.com/Stebalien/tempfile/compare/v3.10.1...v3.11.0) --- updated-dependencies: - dependency-name: tempfile dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- Cargo.lock | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c95f4443..233be0d3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4641,12 +4641,13 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.10.1" +version = "3.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1" +checksum = "b8fcd239983515c23a32fb82099f97d0b11b8c72f654ed659363a95c3dad7a53" dependencies = [ "cfg-if 1.0.0", "fastrand", + "once_cell", "rustix", "windows-sys 0.52.0", ] From 952fb71a6a22598c5f00ca3fe02bfb1ccb0ac65f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 7 Aug 2024 11:15:11 +0000 Subject: [PATCH 20/24] build(deps): bump tempfile from 3.11.0 to 3.12.0 Bumps [tempfile](https://github.com/Stebalien/tempfile) from 3.11.0 to 3.12.0. - [Changelog](https://github.com/Stebalien/tempfile/blob/master/CHANGELOG.md) - [Commits](https://github.com/Stebalien/tempfile/commits) --- updated-dependencies: - dependency-name: tempfile dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- Cargo.lock | 70 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 43 insertions(+), 27 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 233be0d3..2addb45b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4641,15 +4641,15 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.11.0" +version = "3.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8fcd239983515c23a32fb82099f97d0b11b8c72f654ed659363a95c3dad7a53" +checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" dependencies = [ "cfg-if 1.0.0", "fastrand", "once_cell", "rustix", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -5625,7 +5625,16 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets 0.52.0", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", ] [[package]] @@ -5645,17 +5654,18 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.52.0" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ - "windows_aarch64_gnullvm 0.52.0", - "windows_aarch64_msvc 0.52.0", - "windows_i686_gnu 0.52.0", - "windows_i686_msvc 0.52.0", - "windows_x86_64_gnu 0.52.0", - "windows_x86_64_gnullvm 0.52.0", - "windows_x86_64_msvc 0.52.0", + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", ] [[package]] @@ -5666,9 +5676,9 @@ checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" [[package]] name = "windows_aarch64_gnullvm" -version = "0.52.0" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" [[package]] name = "windows_aarch64_msvc" @@ -5684,9 +5694,9 @@ checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" [[package]] name = "windows_aarch64_msvc" -version = "0.52.0" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" [[package]] name = "windows_i686_gnu" @@ -5702,9 +5712,15 @@ checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" [[package]] name = "windows_i686_gnu" -version = "0.52.0" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" [[package]] name = "windows_i686_msvc" @@ -5720,9 +5736,9 @@ checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" [[package]] name = "windows_i686_msvc" -version = "0.52.0" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" [[package]] name = "windows_x86_64_gnu" @@ -5738,9 +5754,9 @@ checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" [[package]] name = "windows_x86_64_gnu" -version = "0.52.0" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" [[package]] name = "windows_x86_64_gnullvm" @@ -5750,9 +5766,9 @@ checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" [[package]] name = "windows_x86_64_gnullvm" -version = "0.52.0" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" [[package]] name = "windows_x86_64_msvc" @@ -5768,9 +5784,9 @@ checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" [[package]] name = "windows_x86_64_msvc" -version = "0.52.0" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "winnow" From f799da5203e9c27a91581aa444d02a42e62cbd87 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 8 Aug 2024 11:50:16 +0000 Subject: [PATCH 21/24] build(deps): bump serde from 1.0.204 to 1.0.205 Bumps [serde](https://github.com/serde-rs/serde) from 1.0.204 to 1.0.205. - [Release notes](https://github.com/serde-rs/serde/releases) - [Commits](https://github.com/serde-rs/serde/compare/v1.0.204...v1.0.205) --- updated-dependencies: - dependency-name: serde dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- Cargo.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 233be0d3..9d4b3d1a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4001,9 +4001,9 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.204" +version = "1.0.205" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc76f558e0cbb2a839d37354c575f1dc3fdc6546b5be373ba43d95f231bf7c12" +checksum = "e33aedb1a7135da52b7c21791455563facbbcc43d0f0f66165b42c21b3dfb150" dependencies = [ "serde_derive", ] @@ -4030,9 +4030,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.204" +version = "1.0.205" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0cd7e117be63d3c3678776753929474f3b04a43a080c744d6b0ae2a8c28e222" +checksum = "692d6f5ac90220161d6774db30c662202721e64aed9058d2c394f451261420c1" dependencies = [ "proc-macro2", "quote", From c8cbd27b795947c4950d75f71ebd5f264de2d05a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 12 Aug 2024 11:07:36 +0000 Subject: [PATCH 22/24] build(deps): bump serde_json from 1.0.122 to 1.0.124 Bumps [serde_json](https://github.com/serde-rs/json) from 1.0.122 to 1.0.124. - [Release notes](https://github.com/serde-rs/json/releases) - [Commits](https://github.com/serde-rs/json/compare/v1.0.122...v1.0.124) --- updated-dependencies: - dependency-name: serde_json dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 35962604..a4c51e62 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4041,9 +4041,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.122" +version = "1.0.124" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "784b6203951c57ff748476b126ccb5e8e2959a5c19e5c617ab1956be3dbc68da" +checksum = "66ad62847a56b3dba58cc891acd13884b9c61138d330c0d7b6181713d4fce38d" dependencies = [ "itoa", "memchr", From 33901a2ea9c3067b54025731eb7cbae6285fec69 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 12 Aug 2024 11:07:58 +0000 Subject: [PATCH 23/24] build(deps): bump serde from 1.0.205 to 1.0.206 Bumps [serde](https://github.com/serde-rs/serde) from 1.0.205 to 1.0.206. - [Release notes](https://github.com/serde-rs/serde/releases) - [Commits](https://github.com/serde-rs/serde/compare/v1.0.205...v1.0.206) --- updated-dependencies: - dependency-name: serde dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- Cargo.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 35962604..f5f1b250 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4001,9 +4001,9 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.205" +version = "1.0.206" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e33aedb1a7135da52b7c21791455563facbbcc43d0f0f66165b42c21b3dfb150" +checksum = "5b3e4cd94123dd520a128bcd11e34d9e9e423e7e3e50425cb1b4b1e3549d0284" dependencies = [ "serde_derive", ] @@ -4030,9 +4030,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.205" +version = "1.0.206" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "692d6f5ac90220161d6774db30c662202721e64aed9058d2c394f451261420c1" +checksum = "fabfb6138d2383ea8208cf98ccf69cdfb1aff4088460681d84189aa259762f97" dependencies = [ "proc-macro2", "quote", From 4eff6fe503e6a39fdee543703e974d1ffc5109ad Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 16 Aug 2024 11:04:29 +0000 Subject: [PATCH 24/24] build(deps): bump serde from 1.0.206 to 1.0.208 Bumps [serde](https://github.com/serde-rs/serde) from 1.0.206 to 1.0.208. - [Release notes](https://github.com/serde-rs/serde/releases) - [Commits](https://github.com/serde-rs/serde/compare/v1.0.206...v1.0.208) --- updated-dependencies: - dependency-name: serde dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- Cargo.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 99040c5c..44e21ae8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4001,9 +4001,9 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.206" +version = "1.0.208" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b3e4cd94123dd520a128bcd11e34d9e9e423e7e3e50425cb1b4b1e3549d0284" +checksum = "cff085d2cb684faa248efb494c39b68e522822ac0de72ccf08109abde717cfb2" dependencies = [ "serde_derive", ] @@ -4030,9 +4030,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.206" +version = "1.0.208" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fabfb6138d2383ea8208cf98ccf69cdfb1aff4088460681d84189aa259762f97" +checksum = "24008e81ff7613ed8e5ba0cfaf24e2c2f1e5b8a0495711e44fcd4882fca62bcf" dependencies = [ "proc-macro2", "quote",