From 6badf0939486bc1de5a07b89088fe15d89b9cf05 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 13 May 2021 06:42:14 +0000 Subject: [PATCH 1/5] Bump bdk from 0.6.0 to 0.7.0 Bumps [bdk](https://github.com/bitcoindevkit/bdk) from 0.6.0 to 0.7.0. - [Release notes](https://github.com/bitcoindevkit/bdk/releases) - [Changelog](https://github.com/bitcoindevkit/bdk/blob/v0.7.0/CHANGELOG.md) - [Commits](https://github.com/bitcoindevkit/bdk/compare/v0.6.0...v0.7.0) Signed-off-by: dependabot[bot] --- Cargo.lock | 4 ++-- swap/Cargo.toml | 2 +- swap/src/bitcoin/wallet.rs | 15 +++++++++++---- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 506650d6..08717947 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -237,9 +237,9 @@ checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" [[package]] name = "bdk" -version = "0.6.0" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51dcf686dfc6200d641e8619019c027976533b7e2d5c00de2b4182c88287a18b" +checksum = "d85959e6883d0286e39e89aa7791b2edc2b8712f0f7152fda43b692c4db96c06" dependencies = [ "async-trait", "bdk-macros", diff --git a/swap/Cargo.toml b/swap/Cargo.toml index 80dca924..cb08a792 100644 --- a/swap/Cargo.toml +++ b/swap/Cargo.toml @@ -15,7 +15,7 @@ async-trait = "0.1" atty = "0.2" backoff = { version = "0.3", features = [ "tokio" ] } base64 = "0.13" -bdk = "0.6" +bdk = "0.7" big-bytes = "1" bitcoin = { version = "0.26", features = [ "rand", "use-serde" ] } bmrng = "0.5" diff --git a/swap/src/bitcoin/wallet.rs b/swap/src/bitcoin/wallet.rs index 6268d64e..90276b0a 100644 --- a/swap/src/bitcoin/wallet.rs +++ b/swap/src/bitcoin/wallet.rs @@ -10,7 +10,7 @@ use bdk::descriptor::Segwitv0; use bdk::electrum_client::{ElectrumApi, GetHistoryRes}; use bdk::keys::DerivableKey; use bdk::wallet::AddressIndex; -use bdk::{FeeRate, KeychainKind}; +use bdk::{FeeRate, KeychainKind, SignOptions}; use bitcoin::{Network, Script}; use reqwest::Url; use rust_decimal::prelude::*; @@ -246,14 +246,21 @@ where C: EstimateFeeRate, D: BatchDatabase, { - pub async fn sign_and_finalize(&self, psbt: PartiallySignedTransaction) -> Result { - let (signed_psbt, finalized) = self.wallet.lock().await.sign(psbt, None)?; + pub async fn sign_and_finalize( + &self, + mut psbt: PartiallySignedTransaction, + ) -> Result { + let finalized = self + .wallet + .lock() + .await + .sign(&mut psbt, SignOptions::default())?; if !finalized { bail!("PSBT is not finalized") } - let tx = signed_psbt.extract_tx(); + let tx = psbt.extract_tx(); Ok(tx) } From f95a080cb50850838eb290afde67070505d14fe9 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 8 Jun 2021 06:19:55 +0000 Subject: [PATCH 2/5] Bump rust_decimal from 1.14.1 to 1.14.2 Bumps [rust_decimal](https://github.com/paupino/rust-decimal) from 1.14.1 to 1.14.2. - [Release notes](https://github.com/paupino/rust-decimal/releases) - [Commits](https://github.com/paupino/rust-decimal/compare/1.14.1...1.14.2) --- updated-dependencies: - dependency-name: rust_decimal 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 a92f090a..7220ee81 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3240,9 +3240,9 @@ dependencies = [ [[package]] name = "rust_decimal" -version = "1.14.1" +version = "1.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d52f6513cf330c84095570b1f3ac073d718a50541c8392a98eaac9c6333324bf" +checksum = "9787e62372fc0c5a0f3af64c392652db72d3ec1cc0cff1becc175d2c11e6fbcc" dependencies = [ "arrayvec", "num-traits", From 2b64e2619b095937b84d612a2e68ef462d2885c1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 16 Jun 2021 06:28:03 +0000 Subject: [PATCH 3/5] Bump tokio from 1.6.0 to 1.7.0 Bumps [tokio](https://github.com/tokio-rs/tokio) from 1.6.0 to 1.7.0. - [Release notes](https://github.com/tokio-rs/tokio/releases) - [Commits](https://github.com/tokio-rs/tokio/compare/tokio-1.6.0...tokio-1.7.0) --- updated-dependencies: - dependency-name: tokio dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a92f090a..65c16b9e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4160,9 +4160,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" -version = "1.6.0" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd3076b5c8cc18138b8f8814895c11eb4de37114a5d127bafdc5e55798ceef37" +checksum = "c79ba603c337335df6ba6dd6afc38c38a7d5e1b0c871678439ea973cd62a118e" dependencies = [ "autocfg 1.0.1", "bytes 1.0.1", From 8b62240acbb52cab22dee140819de54dfdc87eab Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 16 Jun 2021 06:28:23 +0000 Subject: [PATCH 4/5] Bump thomaseizinger/create-pull-request from 1.0.0 to 1.1.0 Bumps [thomaseizinger/create-pull-request](https://github.com/thomaseizinger/create-pull-request) from 1.0.0 to 1.1.0. - [Release notes](https://github.com/thomaseizinger/create-pull-request/releases) - [Changelog](https://github.com/thomaseizinger/create-pull-request/blob/master/CHANGELOG.md) - [Commits](https://github.com/thomaseizinger/create-pull-request/compare/1.0.0...1.1.0) --- updated-dependencies: - dependency-name: thomaseizinger/create-pull-request 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 5d8275fc..b59ef00f 100644 --- a/.github/workflows/draft-new-release.yml +++ b/.github/workflows/draft-new-release.yml @@ -54,7 +54,7 @@ jobs: run: git push origin release/${{ github.event.inputs.version }} --force - name: Create pull request - uses: thomaseizinger/create-pull-request@1.0.0 + uses: thomaseizinger/create-pull-request@1.1.0 with: GITHUB_TOKEN: ${{ secrets.BOTTY_GITHUB_TOKEN }} head: release/${{ github.event.inputs.version }} From 03857ca835691d3b57adbd9074fb2c85e1536d77 Mon Sep 17 00:00:00 2001 From: xscd Date: Sun, 30 May 2021 14:53:43 +0300 Subject: [PATCH 5/5] Print the Bitcoin address to the terminal as a QR code --- CHANGELOG.md | 5 ++++ Cargo.lock | 56 +++++++++++++++++++++++++++++++++++++++++++- swap/Cargo.toml | 1 + swap/src/bin/swap.rs | 25 ++++++++++++++++++++ 4 files changed, 86 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bb62f50b..03c055b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- Printing the deposit address to the terminal as a QR code. + To not break automated scripts or integrations with other software, this behaviour is disabled if `--json` is passed to the application. + ## [0.7.0] - 2021-05-28 ### Fixed diff --git a/Cargo.lock b/Cargo.lock index a92f090a..eaa39b13 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -486,6 +486,12 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7" +[[package]] +name = "bytemuck" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bed57e2090563b83ba8f83366628ce535a7584c9afa4c9fc0612a03925c6df58" + [[package]] name = "byteorder" version = "1.4.3" @@ -578,6 +584,12 @@ dependencies = [ "zeroize", ] +[[package]] +name = "checked_int_cast" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17cc5e6b5ab06331c33589842070416baa137e8b0eb912b008cfd4a78ada7919" + [[package]] name = "chrono" version = "0.4.19" @@ -624,6 +636,12 @@ dependencies = [ "bitflags", ] +[[package]] +name = "color_quant" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" + [[package]] name = "config" version = "0.11.0" @@ -1560,6 +1578,20 @@ dependencies = [ "libc", ] +[[package]] +name = "image" +version = "0.23.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24ffcb7e7244a9bf19d35bf2883b9c080c4ced3c07a9895572178cdb8f13f6a1" +dependencies = [ + "bytemuck", + "byteorder", + "color_quant", + "num-iter", + "num-rational 0.3.2", + "num-traits", +] + [[package]] name = "indexmap" version = "1.6.2" @@ -2372,7 +2404,7 @@ dependencies = [ "num-complex", "num-integer", "num-iter", - "num-rational", + "num-rational 0.1.42", "num-traits", ] @@ -2431,6 +2463,17 @@ dependencies = [ "rustc-serialize", ] +[[package]] +name = "num-rational" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12ac428b1cb17fce6f731001d307d351ec70a6d202fc2e60f7d4c5e42d8f4f07" +dependencies = [ + "autocfg 1.0.1", + "num-integer", + "num-traits", +] + [[package]] name = "num-traits" version = "0.2.14" @@ -2833,6 +2876,16 @@ dependencies = [ "prost", ] +[[package]] +name = "qrcode" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16d2f1455f3630c6e5107b4f2b94e74d76dea80736de0981fd27644216cff57f" +dependencies = [ + "checked_int_cast", + "image", +] + [[package]] name = "quick-error" version = "1.2.3" @@ -3913,6 +3966,7 @@ dependencies = [ "port_check", "prettytable-rs", "proptest", + "qrcode", "rand 0.8.3", "rand_chacha 0.3.0", "reqwest", diff --git a/swap/Cargo.toml b/swap/Cargo.toml index ba8ed7b3..51cb8e84 100644 --- a/swap/Cargo.toml +++ b/swap/Cargo.toml @@ -37,6 +37,7 @@ monero-rpc = { path = "../monero-rpc" } pem = "0.8" prettytable-rs = "0.8" proptest = "1" +qrcode = "0.12" rand = "0.8" rand_chacha = "0.3" reqwest = { version = "0.11", features = [ "rustls-tls", "stream", "socks" ], default-features = false } diff --git a/swap/src/bin/swap.rs b/swap/src/bin/swap.rs index 314b5697..1db5b150 100644 --- a/swap/src/bin/swap.rs +++ b/swap/src/bin/swap.rs @@ -14,6 +14,8 @@ use anyhow::{bail, Context, Result}; use prettytable::{row, Table}; +use qrcode::render::unicode; +use qrcode::QrCode; use std::cmp::min; use std::env; use std::future::Future; @@ -101,6 +103,7 @@ async fn main() -> Result<()> { let max_givable = || bitcoin_wallet.max_giveable(TxLock::script_size()); let (amount, fees) = determine_btc_to_swap( + json, event_loop_handle.request_quote(), bitcoin_wallet.new_address(), || bitcoin_wallet.balance(), @@ -325,7 +328,18 @@ async fn init_monero_wallet( Ok((monero_wallet, monero_wallet_rpc_process)) } +fn qr_code(value: &impl ToString) -> Result { + let code = QrCode::new(value.to_string())?; + let qr_code = code + .render::() + .dark_color(unicode::Dense1x2::Light) + .light_color(unicode::Dense1x2::Dark) + .build(); + Ok(qr_code) +} + async fn determine_btc_to_swap( + json: bool, bid_quote: impl Future>, get_new_address: impl Future>, balance: FB, @@ -358,6 +372,10 @@ where let minimum_amount = bid_quote.min_quantity; let maximum_amount = bid_quote.max_quantity; + if !json { + eprintln!("{}", qr_code(&deposit_address)?); + } + info!( %deposit_address, %current_maximum_giveable, @@ -449,6 +467,7 @@ mod tests { ]))); let (amount, fees) = determine_btc_to_swap( + true, async { Ok(quote_with_max(0.01)) }, get_dummy_address(), || async { Ok(Amount::from_btc(0.001)?) }, @@ -475,6 +494,7 @@ mod tests { ]))); let (amount, fees) = determine_btc_to_swap( + true, async { Ok(quote_with_max(0.01)) }, get_dummy_address(), || async { Ok(Amount::from_btc(0.1001)?) }, @@ -502,6 +522,7 @@ mod tests { ]))); let (amount, fees) = determine_btc_to_swap( + true, async { Ok(quote_with_max(0.01)) }, async { panic!("should not request new address when initial balance is > 0") }, || async { Ok(Amount::from_btc(0.005)?) }, @@ -529,6 +550,7 @@ mod tests { ]))); let (amount, fees) = determine_btc_to_swap( + true, async { Ok(quote_with_max(0.01)) }, async { panic!("should not request new address when initial balance is > 0") }, || async { Ok(Amount::from_btc(0.1001)?) }, @@ -556,6 +578,7 @@ mod tests { ]))); let (amount, fees) = determine_btc_to_swap( + true, async { Ok(quote_with_min(0.01)) }, get_dummy_address(), || async { Ok(Amount::from_btc(0.0101)?) }, @@ -583,6 +606,7 @@ mod tests { ]))); let (amount, fees) = determine_btc_to_swap( + true, async { Ok(quote_with_min(0.01)) }, get_dummy_address(), || async { Ok(Amount::from_btc(0.0101)?) }, @@ -615,6 +639,7 @@ mod tests { let error = tokio::time::timeout( Duration::from_secs(1), determine_btc_to_swap( + true, async { Ok(quote_with_min(0.1)) }, get_dummy_address(), || async { Ok(Amount::from_btc(0.0101)?) },