From 9bb30fe55bcefbe9b00756011d1a4801236562fd Mon Sep 17 00:00:00 2001 From: DanGould Date: Tue, 30 Jul 2024 15:30:32 -0400 Subject: [PATCH] Bump bitcoin-v0.32.2 --- Cargo.lock | 264 ++++++++++++++++++++++------------ Cargo.toml | 3 + payjoin-cli/Cargo.toml | 6 +- payjoin-cli/src/app/config.rs | 5 +- payjoin-cli/src/app/mod.rs | 2 +- payjoin-cli/src/app/v1.rs | 22 +-- payjoin-cli/src/app/v2.rs | 9 +- payjoin-cli/tests/e2e.rs | 2 +- payjoin-directory/Cargo.toml | 2 +- payjoin-directory/src/lib.rs | 9 +- payjoin/Cargo.toml | 6 +- payjoin/src/input_type.rs | 25 ++-- payjoin/src/psbt.rs | 14 +- payjoin/src/receive/mod.rs | 22 +-- payjoin/src/receive/v2/mod.rs | 14 +- payjoin/src/send/error.rs | 5 +- payjoin/src/send/mod.rs | 25 ++-- payjoin/src/v2.rs | 11 +- payjoin/tests/integration.rs | 10 +- 19 files changed, 275 insertions(+), 181 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 58e548b3..3cc762c9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -114,6 +114,12 @@ version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" +[[package]] +name = "arrayvec" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" + [[package]] name = "async-trait" version = "0.1.80" @@ -157,6 +163,16 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base58ck" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c8d66485a3a2ea485c1913c4572ce0256067a5377ac8c75c4960e1cda98605f" +dependencies = [ + "bitcoin-internals", + "bitcoin_hashes", +] + [[package]] name = "base64" version = "0.13.1" @@ -175,11 +191,17 @@ version = "0.22.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" +[[package]] +name = "base64ct" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" + [[package]] name = "bech32" -version = "0.9.1" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d86b93f97252c47b41663388e6d155714a9d0c398b99f1005cbc5f978b29f445" +checksum = "d965446196e3b7decd44aa7ee49e31d630118f90ef12f97900f262eb915c951d" [[package]] name = "bhttp" @@ -193,9 +215,7 @@ dependencies = [ [[package]] name = "bip21" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b9532c632b068e45a478f5e309126b6e2ec1dbf0bbd327b73836f33d9a43ede" +version = "0.5.0" dependencies = [ "bitcoin", "percent-encoding-rfc3986", @@ -203,44 +223,67 @@ dependencies = [ [[package]] name = "bitcoin" -version = "0.30.2" +version = "0.32.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1945a5048598e4189e239d3f809b19bdad4845c4b2ba400d304d2dcf26d2c462" +checksum = "ea507acc1cd80fc084ace38544bbcf7ced7c2aa65b653b102de0ce718df668f6" dependencies = [ - "base64 0.13.1", + "base58ck", + "base64 0.21.7", "bech32", - "bitcoin-private", + "bitcoin-internals", + "bitcoin-io", + "bitcoin-units", "bitcoin_hashes", + "hex-conservative", "hex_lit", "secp256k1", "serde", ] [[package]] -name = "bitcoin-private" -version = "0.1.0" +name = "bitcoin-internals" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30bdbe14aa07b06e6cfeffc529a1f099e5fbe249524f8125358604df99a4bed2" +dependencies = [ + "serde", +] + +[[package]] +name = "bitcoin-io" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73290177011694f38ec25e165d0387ab7ea749a4b81cd4c80dae5988229f7a57" +checksum = "340e09e8399c7bd8912f495af6aa58bea0c9214773417ffaa8f6460f93aaee56" + +[[package]] +name = "bitcoin-units" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5285c8bcaa25876d07f37e3d30c303f2609179716e11d688f51e8f1fe70063e2" +dependencies = [ + "bitcoin-internals", + "serde", +] [[package]] name = "bitcoin_hashes" -version = "0.12.0" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d7066118b13d4b20b23645932dfb3a81ce7e29f95726c2036fa33cd7b092501" +checksum = "bb18c03d0db0247e147a21a6faafd5a7eb851c743db062de72018b6b7e8e4d16" dependencies = [ - "bitcoin-private", + "bitcoin-io", + "hex-conservative", "serde", ] [[package]] name = "bitcoincore-rpc" -version = "0.17.0" +version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d6c0ee9354e3dac217db4cb1dd31941073a87fe53c86bcf3eb2b8bc97f00a08" +checksum = "aedd23ae0fd321affb4bbbc36126c6f49a32818dc6b979395d24da8c9d4e80ee" dependencies = [ - "bitcoin-private", "bitcoincore-rpc-json", - "jsonrpc 0.14.1", + "jsonrpc", "log", "serde", "serde_json", @@ -248,25 +291,24 @@ dependencies = [ [[package]] name = "bitcoincore-rpc-json" -version = "0.17.0" +version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d30ce6f40fb0a2e8d98522796219282504b7a4b14e2b4c26139a7bea6aec6586" +checksum = "d8909583c5fab98508e80ef73e5592a651c954993dc6b7739963257d19f0e71a" dependencies = [ "bitcoin", - "bitcoin-private", "serde", "serde_json", ] [[package]] name = "bitcoind" -version = "0.31.1" +version = "0.36.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "395fe8137d13c6859fa68421779cd5a4db8cd7b0ef3122537e56f7a49a0598a9" +checksum = "3ee5cf6a9903ff9cc808494c1232b0e9f6eef6600913d0d69fe1cb5c428f25b9" dependencies = [ "anyhow", "bitcoin_hashes", - "core-rpc", + "bitcoincore-rpc", "flate2", "log", "minreq", @@ -360,6 +402,11 @@ name = "cc" version = "1.0.102" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "779e6b7d17797c0b42023d417228c02889300190e700cb074c3438d9c541d332" +dependencies = [ + "jobserver", + "libc", + "once_cell", +] [[package]] name = "cfg-if" @@ -506,6 +553,12 @@ dependencies = [ "yaml-rust", ] +[[package]] +name = "constant_time_eq" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" + [[package]] name = "core-foundation" version = "0.9.4" @@ -522,32 +575,6 @@ version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" -[[package]] -name = "core-rpc" -version = "0.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26d77079e1b71c2778d6e1daf191adadcd4ff5ec3ccad8298a79061d865b235b" -dependencies = [ - "bitcoin-private", - "core-rpc-json", - "jsonrpc 0.13.0", - "log", - "serde", - "serde_json", -] - -[[package]] -name = "core-rpc-json" -version = "0.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "581898ed9a83f31c64731b1d8ca2dfffcfec14edf1635afacd5234cddbde3a41" -dependencies = [ - "bitcoin", - "bitcoin-private", - "serde", - "serde_json", -] - [[package]] name = "cpufeatures" version = "0.1.5" @@ -940,7 +967,7 @@ checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ "cfg-if", "libc", - "wasi 0.11.0+wasi-snapshot-preview1", + "wasi", ] [[package]] @@ -1030,6 +1057,15 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +[[package]] +name = "hex-conservative" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5313b072ce3c597065a808dbf612c4c8e8590bdbf8b579508bf7a762c5eae6cd" +dependencies = [ + "arrayvec", +] + [[package]] name = "hex_lit" version = "0.1.1" @@ -1396,6 +1432,15 @@ version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" +[[package]] +name = "jobserver" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48d1dbcbbeb6a7fec7e059840aa538bd62aaccf972c7346c4d9d2059312853d0" +dependencies = [ + "libc", +] + [[package]] name = "js-sys" version = "0.3.69" @@ -1418,22 +1463,12 @@ dependencies = [ [[package]] name = "jsonrpc" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd8d6b3f301ba426b30feca834a2a18d48d5b54e5065496b5c1b05537bee3639" -dependencies = [ - "base64 0.13.1", - "serde", - "serde_json", -] - -[[package]] -name = "jsonrpc" -version = "0.14.1" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8128f36b47411cd3f044be8c1f5cc0c9e24d1d1bfdc45f0a57897b32513053f2" +checksum = "3662a38d341d77efecb73caf01420cfa5aa63c0253fd7bc05289ef9f6616e1bf" dependencies = [ "base64 0.13.1", + "minreq", "serde", "serde_json", ] @@ -1524,6 +1559,8 @@ dependencies = [ "once_cell", "rustls 0.21.12", "rustls-webpki 0.101.7", + "serde", + "serde_json", "webpki-roots 0.25.4", ] @@ -1534,7 +1571,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" dependencies = [ "libc", - "wasi 0.11.0+wasi-snapshot-preview1", + "wasi", "windows-sys 0.48.0", ] @@ -1716,6 +1753,17 @@ dependencies = [ "windows-targets 0.52.5", ] +[[package]] +name = "password-hash" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7676374caaee8a325c9e7a2ae557f216c5563a171d6997b0ef8a65af35147700" +dependencies = [ + "base64ct", + "rand_core", + "subtle", +] + [[package]] name = "pathdiff" version = "0.2.1" @@ -1801,6 +1849,18 @@ dependencies = [ "tracing-subscriber", ] +[[package]] +name = "pbkdf2" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83a0692ec44e4cf1ef28ca317f14f8f07da2d95ec3fa01f86e4467b725e60917" +dependencies = [ + "digest 0.10.7", + "hmac 0.12.1", + "password-hash", + "sha2 0.10.8", +] + [[package]] name = "pem" version = "3.0.4" @@ -2091,7 +2151,7 @@ checksum = "52c4f3084aa3bc7dfbba4eff4fab2a54db4324965d8872ab933565e6fbd83bc6" dependencies = [ "pem", "ring 0.16.20", - "time 0.3.36", + "time", "yasna", ] @@ -2459,9 +2519,9 @@ dependencies = [ [[package]] name = "secp256k1" -version = "0.27.0" +version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25996b82292a7a57ed3508f052cfff8640d38d32018784acd714758b43da9c8f" +checksum = "0e0cc0f1cf93f4969faf3ea1c7d8a9faed25918d96affa959720823dfe86d4f3" dependencies = [ "bitcoin_hashes", "rand", @@ -2471,9 +2531,9 @@ dependencies = [ [[package]] name = "secp256k1-sys" -version = "0.8.1" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70a129b9e9efbfb223753b9163c4ab3b13cff7fd9c7f010fbac25ab4099fa07e" +checksum = "1433bd67156263443f14d603720b082dd3121779323fce20cba2aa07b874bc1b" dependencies = [ "cc", ] @@ -2822,17 +2882,6 @@ dependencies = [ "once_cell", ] -[[package]] -name = "time" -version = "0.1.45" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b797afad3f312d1c66a56d11d0316f916356d11bd158fbc6ca6389ff6bf805a" -dependencies = [ - "libc", - "wasi 0.10.0+wasi-snapshot-preview1", - "winapi", -] - [[package]] name = "time" version = "0.3.36" @@ -3180,12 +3229,6 @@ dependencies = [ "try-lock", ] -[[package]] -name = "wasi" -version = "0.10.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" - [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" @@ -3511,7 +3554,7 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e17bb3549cc1321ae1296b9cdc2698e2b6cb1992adfa19a8c72e5b7a738f44cd" dependencies = [ - "time 0.3.36", + "time", ] [[package]] @@ -3536,14 +3579,49 @@ dependencies = [ [[package]] name = "zip" -version = "0.5.13" +version = "0.6.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93ab48844d61251bb3835145c521d88aa4031d7139e8485990f60ca911fa0815" +checksum = "760394e246e4c28189f19d488c058bf16f564016aefac5d32bb1f3b51d5e9261" dependencies = [ + "aes 0.8.4", "byteorder", "bzip2", + "constant_time_eq", "crc32fast", + "crossbeam-utils", "flate2", - "thiserror", - "time 0.1.45", + "hmac 0.12.1", + "pbkdf2", + "sha1", + "time", + "zstd", +] + +[[package]] +name = "zstd" +version = "0.11.2+zstd.1.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20cc960326ece64f010d2d2107537f26dc589a6573a316bd5b1dba685fa5fde4" +dependencies = [ + "zstd-safe", +] + +[[package]] +name = "zstd-safe" +version = "5.0.2+zstd.1.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d2a5585e04f9eea4b2a3d1eca508c4dee9592a89ef6f450c11719da0726f4db" +dependencies = [ + "libc", + "zstd-sys", +] + +[[package]] +name = "zstd-sys" +version = "2.0.12+zstd.1.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a4e40c320c3cb459d9a9ff6de98cff88f4751ee9275d140e2be94a2b74e4c13" +dependencies = [ + "cc", + "pkg-config", ] diff --git a/Cargo.toml b/Cargo.toml index 532c7cda..c09f77a5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,3 +4,6 @@ resolver = "2" [patch.crates-io.payjoin] path = "payjoin" + +[patch.crates-io.bip21] +path = "../bip21" diff --git a/payjoin-cli/Cargo.toml b/payjoin-cli/Cargo.toml index f8be1228..3f615204 100644 --- a/payjoin-cli/Cargo.toml +++ b/payjoin-cli/Cargo.toml @@ -26,8 +26,8 @@ v2 = ["payjoin/v2", "payjoin/io"] [dependencies] anyhow = "1.0.70" async-trait = "0.1" -bip21 = "0.3.1" -bitcoincore-rpc = "0.17.0" +bip21 = "0.5.0" +bitcoincore-rpc = "0.19.0" clap = { version = "~4.0.32", features = ["derive"] } config = "0.13.3" env_logger = "0.9.0" @@ -44,7 +44,7 @@ tokio = { version = "1.12.0", features = ["full"] } url = { version = "2.3.1", features = ["serde"] } [dev-dependencies] -bitcoind = { version = "0.31.1", features = ["0_21_2"] } +bitcoind = { version = "0.36.0", features = ["0_21_2"] } http = "1" ohttp-relay = "0.0.8" once_cell = "1" diff --git a/payjoin-cli/src/app/config.rs b/payjoin-cli/src/app/config.rs index e335dce7..730531e9 100644 --- a/payjoin-cli/src/app/config.rs +++ b/payjoin-cli/src/app/config.rs @@ -3,6 +3,8 @@ use std::path::PathBuf; use anyhow::Result; use clap::ArgMatches; use config::{Config, ConfigError, File, FileFormat}; +use payjoin::base64::engine::general_purpose::URL_SAFE_NO_PAD; +use payjoin::base64::Engine; use serde::Deserialize; use url::Url; @@ -100,7 +102,8 @@ impl AppConfig { .set_override_option( "ohttp_keys", matches.get_one::("ohttp_keys").and_then(|s| { - payjoin::base64::decode_config(s, payjoin::base64::URL_SAFE_NO_PAD) + URL_SAFE_NO_PAD + .decode(s) .map_err(|e| { log::error!("Failed to decode ohttp_keys: {}", e); ConfigError::Message(format!("Invalid ohttp_keys: {}", e)) diff --git a/payjoin-cli/src/app/mod.rs b/payjoin-cli/src/app/mod.rs index 2bc54f6e..9c68fdee 100644 --- a/payjoin-cli/src/app/mod.rs +++ b/payjoin-cli/src/app/mod.rs @@ -117,7 +117,7 @@ fn try_contributing_inputs( // calculate receiver payjoin outputs given receiver payjoin inputs and original_psbt, let txo_to_contribute = bitcoin::TxOut { - value: selected_utxo.amount.to_sat(), + value: selected_utxo.amount, script_pubkey: selected_utxo.script_pub_key.clone(), }; let outpoint_to_contribute = diff --git a/payjoin-cli/src/app/v1.rs b/payjoin-cli/src/app/v1.rs index 37a5eed0..fbfe4545 100644 --- a/payjoin-cli/src/app/v1.rs +++ b/payjoin-cli/src/app/v1.rs @@ -72,8 +72,8 @@ impl AppTrait for App { .with_context(|| "HTTP request failed")?; let fallback_tx = Psbt::from_str(&body) .map_err(|e| anyhow!("Failed to load PSBT from base64: {}", e))? - .extract_tx(); - println!("Sent fallback transaction txid: {}", fallback_tx.txid()); + .extract_tx()?; + println!("Sent fallback transaction txid: {}", fallback_tx.compute_txid()); println!( "Sent fallback transaction hex: {:#}", payjoin::bitcoin::consensus::encode::serialize_hex(&fallback_tx) @@ -243,7 +243,10 @@ impl App { let payjoin_proposal = self.process_v1_proposal(proposal)?; let psbt = payjoin_proposal.psbt(); let body = psbt.to_string(); - println!("Responded with Payjoin proposal {}", psbt.clone().extract_tx().txid()); + println!( + "Responded with Payjoin proposal {}", + psbt.clone().extract_tx().map_err(|e| Error::Server(e.into()))?.compute_txid() + ); Ok(Response::new(Body::from(body))) } @@ -254,12 +257,7 @@ impl App { let _to_broadcast_in_failure_case = proposal.extract_tx_to_schedule_broadcast(); // The network is used for checks later - let network = bitcoind - .get_blockchain_info() - .map_err(|e| Error::Server(e.into())) - .and_then(|info| { - bitcoin::Network::from_core_arg(&info.chain).map_err(|e| Error::Server(e.into())) - })?; + let network = bitcoind.get_blockchain_info().map_err(|e| Error::Server(e.into()))?.chain; // Receive Check 1: Can Broadcast let proposal = proposal.check_broadcast_suitability(None, |tx| { @@ -334,7 +332,11 @@ impl App { let payjoin_proposal_psbt = payjoin_proposal.psbt(); println!( "Responded with Payjoin proposal {}", - payjoin_proposal_psbt.clone().extract_tx().txid() + payjoin_proposal_psbt + .clone() + .extract_tx() + .map_err(|e| Error::Server(e.into()))? + .compute_txid() ); Ok(payjoin_proposal) } diff --git a/payjoin-cli/src/app/v2.rs b/payjoin-cli/src/app/v2.rs index 8beb504c..537f084a 100644 --- a/payjoin-cli/src/app/v2.rs +++ b/payjoin-cli/src/app/v2.rs @@ -167,7 +167,7 @@ impl App { let payjoin_psbt = payjoin_proposal.psbt().clone(); println!( "Response successful. Watch mempool for successful Payjoin. TXID: {}", - payjoin_psbt.extract_tx().clone().txid() + payjoin_psbt.extract_tx()?.clone().compute_txid() ); self.db.clear_recv_session()?; Ok(()) @@ -280,12 +280,7 @@ impl App { let _to_broadcast_in_failure_case = proposal.extract_tx_to_schedule_broadcast(); // The network is used for checks later - let network = bitcoind - .get_blockchain_info() - .map_err(|e| Error::Server(e.into())) - .and_then(|info| { - bitcoin::Network::from_core_arg(&info.chain).map_err(|e| Error::Server(e.into())) - })?; + let network = bitcoind.get_blockchain_info().map_err(|e| Error::Server(e.into()))?.chain; // Receive Check 1: Can Broadcast let proposal = proposal.check_broadcast_suitability(None, |tx| { diff --git a/payjoin-cli/tests/e2e.rs b/payjoin-cli/tests/e2e.rs index 900a93be..a4e9dbd5 100644 --- a/payjoin-cli/tests/e2e.rs +++ b/payjoin-cli/tests/e2e.rs @@ -3,7 +3,7 @@ mod e2e { use std::env; use std::process::Stdio; - use bitcoind::bitcoincore_rpc::core_rpc_json::AddressType; + use bitcoincore_rpc::json::AddressType; use bitcoind::bitcoincore_rpc::RpcApi; use log::{log_enabled, Level}; use payjoin::bitcoin::Amount; diff --git a/payjoin-directory/Cargo.toml b/payjoin-directory/Cargo.toml index 25749490..0b31b0e4 100644 --- a/payjoin-directory/Cargo.toml +++ b/payjoin-directory/Cargo.toml @@ -18,7 +18,7 @@ danger-local-https = ["hyper-rustls", "rustls"] [dependencies] anyhow = "1.0.71" -bitcoin = { version = "0.30.0", features = ["base64"] } +bitcoin = { version = "0.32.2", features = ["base64"] } bhttp = { version = "=0.5.1", features = ["http"] } futures = "0.3.17" hyper = { version = "0.14", features = ["full"] } diff --git a/payjoin-directory/src/lib.rs b/payjoin-directory/src/lib.rs index 94c95806..024bdc51 100644 --- a/payjoin-directory/src/lib.rs +++ b/payjoin-directory/src/lib.rs @@ -3,7 +3,8 @@ use std::sync::Arc; use std::time::Duration; use anyhow::Result; -use bitcoin::{self, base64}; +use bitcoin::base64::prelude::BASE64_URL_SAFE_NO_PAD; +use bitcoin::base64::Engine; use hyper::header::{HeaderValue, ACCESS_CONTROL_ALLOW_ORIGIN, CONTENT_TYPE}; use hyper::service::{make_service_fn, service_fn}; use hyper::{Body, Method, Request, Response, Server, StatusCode, Uri}; @@ -102,7 +103,7 @@ fn init_ohttp() -> Result { // create or read from file let server_config = ohttp::KeyConfig::new(KEY_ID, KEM, Vec::from(SYMMETRIC))?; let encoded_config = server_config.encode()?; - let b64_config = base64::encode_config(encoded_config, base64::URL_SAFE_NO_PAD); + let b64_config = BASE64_URL_SAFE_NO_PAD.encode(encoded_config); info!("ohttp-keys server config base64 UrlSafe: {:?}", b64_config); Ok(ohttp::Server::new(server_config)?) } @@ -243,8 +244,8 @@ async fn post_session(body: Body) -> Result, HandlerError> { hyper::body::to_bytes(body).await.map_err(|e| HandlerError::BadRequest(e.into()))?; let base64_id = String::from_utf8(bytes.to_vec()).map_err(|e| HandlerError::BadRequest(e.into()))?; - let pubkey_bytes: Vec = base64::decode_config(base64_id, base64::URL_SAFE_NO_PAD) - .map_err(|e| HandlerError::BadRequest(e.into()))?; + let pubkey_bytes: Vec = + BASE64_URL_SAFE_NO_PAD.decode(base64_id).map_err(|e| HandlerError::BadRequest(e.into()))?; let pubkey = bitcoin::secp256k1::PublicKey::from_slice(&pubkey_bytes) .map_err(|e| HandlerError::BadRequest(e.into()))?; tracing::info!("Initialized session with pubkey: {:?}", pubkey); diff --git a/payjoin/Cargo.toml b/payjoin/Cargo.toml index 985a1e7c..ca3ce295 100644 --- a/payjoin/Cargo.toml +++ b/payjoin/Cargo.toml @@ -24,8 +24,8 @@ io = ["reqwest/rustls-tls"] danger-local-https = ["io", "reqwest/rustls-tls", "rustls"] [dependencies] -bitcoin = { version = "0.30.0", features = ["base64"] } -bip21 = "0.3.1" +bitcoin = { version = "0.32.2", features = ["base64"] } +bip21 = "0.5.0" chacha20poly1305 = { version = "0.10.1", optional = true } log = { version = "0.4.14"} http = { version = "1", optional = true } @@ -38,7 +38,7 @@ url = "2.2.2" serde_json = "1.0.108" [dev-dependencies] -bitcoind = { version = "0.31.1", features = ["0_21_2"] } +bitcoind = { version = "0.36.0", features = ["0_21_2"] } http = "1" payjoin-directory = { path = "../payjoin-directory", features = ["danger-local-https"] } ohttp-relay = "0.0.8" diff --git a/payjoin/src/input_type.rs b/payjoin/src/input_type.rs index ded3fc7d..bc8d11f9 100644 --- a/payjoin/src/input_type.rs +++ b/payjoin/src/input_type.rs @@ -213,10 +213,12 @@ impl std::error::Error for InputTypeError {} mod tests { use bitcoin::psbt::Input as PsbtInput; use bitcoin::script::PushBytesBuf; - use bitcoin::{PublicKey, ScriptBuf}; + use bitcoin::{Amount, PublicKey, ScriptBuf}; use super::*; + static FORTY_TWO: Amount = Amount::from_sat(42); + fn wrap_p2sh_script(script: &Script) -> ScriptBuf { let bytes: PushBytesBuf = script .to_bytes() @@ -227,13 +229,13 @@ mod tests { #[test] fn test_p2pk() { - let input_type = InputType::from_spent_input(&TxOut { script_pubkey: ScriptBuf::new_p2pk(&PublicKey::from_slice(b"\x02\x50\x86\x3A\xD6\x4A\x87\xAE\x8A\x2F\xE8\x3C\x1A\xF1\xA8\x40\x3C\xB5\x3F\x53\xE4\x86\xD8\x51\x1D\xAD\x8A\x04\x88\x7E\x5B\x23\x52").unwrap()), value: 42, }, &Default::default()).unwrap(); + let input_type = InputType::from_spent_input(&TxOut { script_pubkey: ScriptBuf::new_p2pk(&PublicKey::from_slice(b"\x02\x50\x86\x3A\xD6\x4A\x87\xAE\x8A\x2F\xE8\x3C\x1A\xF1\xA8\x40\x3C\xB5\x3F\x53\xE4\x86\xD8\x51\x1D\xAD\x8A\x04\x88\x7E\x5B\x23\x52").unwrap()), value: FORTY_TWO, }, &Default::default()).unwrap(); assert_eq!(input_type, InputType::P2Pk); } #[test] fn test_p2pkh() { - let input_type = InputType::from_spent_input(&TxOut { script_pubkey: ScriptBuf::new_p2pkh(&PublicKey::from_slice(b"\x02\x50\x86\x3A\xD6\x4A\x87\xAE\x8A\x2F\xE8\x3C\x1A\xF1\xA8\x40\x3C\xB5\x3F\x53\xE4\x86\xD8\x51\x1D\xAD\x8A\x04\x88\x7E\x5B\x23\x52").unwrap().pubkey_hash()), value: 42, }, &Default::default()).unwrap(); + let input_type = InputType::from_spent_input(&TxOut { script_pubkey: ScriptBuf::new_p2pkh(&PublicKey::from_slice(b"\x02\x50\x86\x3A\xD6\x4A\x87\xAE\x8A\x2F\xE8\x3C\x1A\xF1\xA8\x40\x3C\xB5\x3F\x53\xE4\x86\xD8\x51\x1D\xAD\x8A\x04\x88\x7E\x5B\x23\x52").unwrap().pubkey_hash()), value: FORTY_TWO, }, &Default::default()).unwrap(); assert_eq!(input_type, InputType::P2Pkh); } @@ -241,7 +243,7 @@ mod tests { fn test_p2sh() { let script = ScriptBuf::new_op_return(&[42]); let input_type = InputType::from_spent_input( - &TxOut { script_pubkey: ScriptBuf::new_p2sh(&script.script_hash()), value: 42 }, + &TxOut { script_pubkey: ScriptBuf::new_p2sh(&script.script_hash()), value: FORTY_TWO }, &PsbtInput { final_script_sig: Some(script), ..Default::default() }, ) .unwrap(); @@ -250,7 +252,7 @@ mod tests { #[test] fn test_p2wpkh() { - let input_type = InputType::from_spent_input(&TxOut { script_pubkey: ScriptBuf::new_v0_p2wpkh(&PublicKey::from_slice(b"\x02\x50\x86\x3A\xD6\x4A\x87\xAE\x8A\x2F\xE8\x3C\x1A\xF1\xA8\x40\x3C\xB5\x3F\x53\xE4\x86\xD8\x51\x1D\xAD\x8A\x04\x88\x7E\x5B\x23\x52").unwrap().wpubkey_hash().expect("WTF, the key is uncompressed")), value: 42, }, &Default::default()).unwrap(); + let input_type = InputType::from_spent_input(&TxOut { script_pubkey: ScriptBuf::new_p2wpkh(&PublicKey::from_slice(b"\x02\x50\x86\x3A\xD6\x4A\x87\xAE\x8A\x2F\xE8\x3C\x1A\xF1\xA8\x40\x3C\xB5\x3F\x53\xE4\x86\xD8\x51\x1D\xAD\x8A\x04\x88\x7E\x5B\x23\x52").unwrap().wpubkey_hash().expect("WTF, the key is uncompressed")), value: FORTY_TWO, }, &Default::default()).unwrap(); assert_eq!(input_type, InputType::SegWitV0 { ty: SegWitV0Type::Pubkey, nested: false }); } @@ -258,7 +260,10 @@ mod tests { fn test_p2wsh() { let script = ScriptBuf::new_op_return(&[42]); let input_type = InputType::from_spent_input( - &TxOut { script_pubkey: ScriptBuf::new_v0_p2wsh(&script.wscript_hash()), value: 42 }, + &TxOut { + script_pubkey: ScriptBuf::new_p2wsh(&script.wscript_hash()), + value: FORTY_TWO, + }, &PsbtInput { final_script_sig: Some(script), ..Default::default() }, ) .unwrap(); @@ -267,12 +272,12 @@ mod tests { #[test] fn test_p2sh_p2wpkh() { - let segwit_script = ScriptBuf::new_v0_p2wpkh(&PublicKey::from_slice(b"\x02\x50\x86\x3A\xD6\x4A\x87\xAE\x8A\x2F\xE8\x3C\x1A\xF1\xA8\x40\x3C\xB5\x3F\x53\xE4\x86\xD8\x51\x1D\xAD\x8A\x04\x88\x7E\x5B\x23\x52").unwrap().wpubkey_hash().expect("WTF, the key is uncompressed")); + let segwit_script = ScriptBuf::new_p2wpkh(&PublicKey::from_slice(b"\x02\x50\x86\x3A\xD6\x4A\x87\xAE\x8A\x2F\xE8\x3C\x1A\xF1\xA8\x40\x3C\xB5\x3F\x53\xE4\x86\xD8\x51\x1D\xAD\x8A\x04\x88\x7E\x5B\x23\x52").unwrap().wpubkey_hash().expect("WTF, the key is uncompressed")); let segwit_script_hash = segwit_script.script_hash(); let script_sig = wrap_p2sh_script(&segwit_script); let input_type = InputType::from_spent_input( - &TxOut { script_pubkey: ScriptBuf::new_p2sh(&segwit_script_hash), value: 42 }, + &TxOut { script_pubkey: ScriptBuf::new_p2sh(&segwit_script_hash), value: FORTY_TWO }, &PsbtInput { final_script_sig: Some(script_sig), ..Default::default() }, ) .unwrap(); @@ -282,12 +287,12 @@ mod tests { #[test] fn test_p2sh_p2wsh() { let script = ScriptBuf::new_op_return(&[42]); - let segwit_script = ScriptBuf::new_v0_p2wsh(&script.wscript_hash()); + let segwit_script = ScriptBuf::new_p2wsh(&script.wscript_hash()); let segwit_script_hash = segwit_script.script_hash(); let script_sig = wrap_p2sh_script(&segwit_script); let input_type = InputType::from_spent_input( - &TxOut { script_pubkey: ScriptBuf::new_p2sh(&segwit_script_hash), value: 42 }, + &TxOut { script_pubkey: ScriptBuf::new_p2sh(&segwit_script_hash), value: FORTY_TWO }, &PsbtInput { final_script_sig: Some(script_sig), ..Default::default() }, ) .unwrap(); diff --git a/payjoin/src/psbt.rs b/payjoin/src/psbt.rs index fab7b82f..c8fa043e 100644 --- a/payjoin/src/psbt.rs +++ b/payjoin/src/psbt.rs @@ -29,7 +29,7 @@ pub(crate) trait PsbtExt: Sized { fn outputs_mut(&mut self) -> &mut [psbt::Output]; fn xpub_mut( &mut self, - ) -> &mut BTreeMap; + ) -> &mut BTreeMap; fn proprietary_mut(&mut self) -> &mut BTreeMap>; fn unknown_mut(&mut self) -> &mut BTreeMap>; fn input_pairs(&self) -> Box> + '_>; @@ -47,7 +47,7 @@ impl PsbtExt for Psbt { fn xpub_mut( &mut self, - ) -> &mut BTreeMap { + ) -> &mut BTreeMap { &mut self.xpub } @@ -95,11 +95,11 @@ impl PsbtExt for Psbt { let mut total_inputs = bitcoin::Amount::ZERO; for output in &self.unsigned_tx.output { - total_outputs += bitcoin::Amount::from_sat(output.value); + total_outputs += output.value; } for input in self.input_pairs() { - total_inputs += bitcoin::Amount::from_sat(input.previous_txout().unwrap().value); + total_inputs += input.previous_txout().unwrap().value; } log::debug!(" total_inputs: {}", total_inputs); log::debug!("- total_outputs: {}", total_outputs); @@ -138,7 +138,7 @@ impl<'a> InputPair<'a> { (None, None) if treat_missing_as_error => Err(PsbtInputError::PrevTxOut(PrevTxOutError::MissingUtxoInformation)), (None, None) => Ok(()), - (Some(tx), None) if tx.txid() == self.txin.previous_output.txid => tx + (Some(tx), None) if tx.compute_txid() == self.txin.previous_output.txid => tx .output .get::(self.txin.previous_output.vout.try_into().map_err(|_| { PrevTxOutError::IndexOutOfBounds { @@ -156,7 +156,9 @@ impl<'a> InputPair<'a> { .map(drop), (Some(_), None) => Err(PsbtInputError::UnequalTxid), (None, Some(_)) => Ok(()), - (Some(tx), Some(witness_txout)) if tx.txid() == self.txin.previous_output.txid => { + (Some(tx), Some(witness_txout)) + if tx.compute_txid() == self.txin.previous_output.txid => + { let non_witness_txout = tx .output .get::(self.txin.previous_output.vout.try_into().map_err(|_| { diff --git a/payjoin/src/receive/mod.rs b/payjoin/src/receive/mod.rs index 794fa793..c1fcd09a 100644 --- a/payjoin/src/receive/mod.rs +++ b/payjoin/src/receive/mod.rs @@ -27,8 +27,10 @@ use std::cmp::{max, min}; use std::collections::HashMap; +use bitcoin::base64::prelude::BASE64_URL_SAFE_NO_PAD; +use bitcoin::base64::Engine; use bitcoin::psbt::Psbt; -use bitcoin::{base64, Amount, FeeRate, OutPoint, Script, TxOut}; +use bitcoin::{Amount, FeeRate, OutPoint, Script, TxOut}; mod error; mod optional_parameters; @@ -88,7 +90,7 @@ impl UncheckedProposal { // enforce the limit let mut buf = vec![0; content_length as usize]; // 4_000_000 * 4 / 3 fits in u32 body.read_exact(&mut buf).map_err(InternalRequestError::Io)?; - let base64 = base64::decode(&buf).map_err(InternalRequestError::Base64)?; + let base64 = BASE64_URL_SAFE_NO_PAD.decode(&buf).map_err(InternalRequestError::Base64)?; let unchecked_psbt = Psbt::deserialize(&base64).map_err(InternalRequestError::Psbt)?; let psbt = unchecked_psbt.validate().map_err(InternalRequestError::InconsistentPsbt)?; @@ -105,7 +107,7 @@ impl UncheckedProposal { /// The Sender's Original PSBT transaction pub fn extract_tx_to_schedule_broadcast(&self) -> bitcoin::Transaction { - self.psbt.clone().extract_tx() + self.psbt.clone().extract_tx_unchecked_fee_rate() } fn psbt_fee_rate(&self) -> Result { @@ -143,7 +145,7 @@ impl UncheckedProposal { .into()); } } - if can_broadcast(&self.psbt.clone().extract_tx())? { + if can_broadcast(&self.psbt.clone().extract_tx_unchecked_fee_rate())? { Ok(MaybeInputsOwned { psbt: self.psbt, params: self.params }) } else { Err(InternalRequestError::OriginalPsbtNotBroadcastable.into()) @@ -387,19 +389,19 @@ impl ProvisionalProposal { .iter() .map(|output| output.value) .min() - .unwrap_or_else(|| Amount::MAX_MONEY.to_sat()); + .unwrap_or_else(|| Amount::MAX_MONEY); let min_original_in_sats = self .payjoin_psbt .input_pairs() .filter_map(|input| input.previous_txout().ok().map(|txo| txo.value)) .min() - .unwrap_or_else(|| Amount::MAX_MONEY.to_sat()); + .unwrap_or_else(|| Amount::MAX_MONEY); let prior_payment_sats = self.payjoin_psbt.unsigned_tx.output[self.owned_vouts[0]].value; for candidate in candidate_inputs { - let candidate_sats = candidate.0.to_sat(); + let candidate_sats = candidate.0; let candidate_min_out = min(min_original_out_sats, prior_payment_sats + candidate_sats); let candidate_min_in = min(min_original_in_sats, candidate_sats); @@ -549,7 +551,7 @@ impl ProvisionalProposal { if !self.owned_vouts.contains(&additional_fee_output_index) { // remove additional miner fee from the sender's specified output self.payjoin_psbt.unsigned_tx.output[additional_fee_output_index].value -= - additional_fee.to_sat(); + additional_fee; } } } @@ -715,10 +717,10 @@ mod test { .expect("No inputs should be seen before") .identify_receiver_outputs(|script| { let network = Network::Bitcoin; - Ok(Address::from_script(script, network) + Ok(Address::from_script(script, network).unwrap() == Address::from_str(&"3CZZi7aWFugaCdUCS15dgrUUViupmB8bVM") .unwrap() - .require_network(network)) + .assume_checked()) }) .expect("Receiver output should be identified"); let payjoin = payjoin.apply_fee(None); diff --git a/payjoin/src/receive/v2/mod.rs b/payjoin/src/receive/v2/mod.rs index c040b244..25cc6b4c 100644 --- a/payjoin/src/receive/v2/mod.rs +++ b/payjoin/src/receive/v2/mod.rs @@ -4,9 +4,11 @@ use std::str::FromStr; use std::time::{Duration, SystemTime}; use bitcoin::address::NetworkUnchecked; +use bitcoin::base64::prelude::BASE64_URL_SAFE_NO_PAD; +use bitcoin::base64::Engine; use bitcoin::psbt::Psbt; use bitcoin::secp256k1::{rand, PublicKey}; -use bitcoin::{base64, Address, Amount, FeeRate, OutPoint, Script, TxOut}; +use bitcoin::{Address, Amount, FeeRate, OutPoint, Script, TxOut}; use serde::de::{self, Deserializer, MapAccess, Visitor}; use serde::ser::SerializeStruct; use serde::{Deserialize, Serialize, Serializer}; @@ -30,7 +32,7 @@ struct SessionContext { ohttp_keys: OhttpKeys, expiry: SystemTime, ohttp_relay: url::Url, - s: bitcoin::secp256k1::KeyPair, + s: bitcoin::secp256k1::Keypair, e: Option, } @@ -74,7 +76,7 @@ impl SessionInitializer { ohttp_relay, expiry: SystemTime::now() + expire_after.unwrap_or(TWENTY_FOUR_HOURS_DEFAULT_EXPIRY), - s: bitcoin::secp256k1::KeyPair::from_secret_key(&secp, &sk), + s: bitcoin::secp256k1::Keypair::from_secret_key(&secp, &sk), e: None, }, } @@ -110,7 +112,7 @@ impl SessionInitializer { } fn subdir_path_from_pubkey(pubkey: &bitcoin::secp256k1::PublicKey) -> String { - base64::encode_config(pubkey.serialize(), base64::URL_SAFE_NO_PAD) + BASE64_URL_SAFE_NO_PAD.encode(pubkey.serialize()) } /// An active payjoin V2 session, allowing for polled requests to the @@ -222,7 +224,7 @@ impl ActiveSession { // This identifies a session at the payjoin directory server. pub fn pj_url(&self) -> Url { let pubkey = &self.context.s.public_key().serialize(); - let pubkey_base64 = base64::encode_config(pubkey, base64::URL_SAFE_NO_PAD); + let pubkey_base64 = BASE64_URL_SAFE_NO_PAD.encode(pubkey); let mut url = self.context.directory.clone(); { let mut path_segments = @@ -651,7 +653,7 @@ mod test { ), ohttp_relay: url::Url::parse("https://relay.com").unwrap(), expiry: SystemTime::now() + Duration::from_secs(60), - s: bitcoin::secp256k1::KeyPair::from_secret_key( + s: bitcoin::secp256k1::Keypair::from_secret_key( &bitcoin::secp256k1::Secp256k1::new(), &bitcoin::secp256k1::SecretKey::from_slice(&[1; 32]).unwrap(), ), diff --git a/payjoin/src/send/error.rs b/payjoin/src/send/error.rs index e7305e67..681cad51 100644 --- a/payjoin/src/send/error.rs +++ b/payjoin/src/send/error.rs @@ -1,6 +1,7 @@ use std::fmt::{self, Display}; use bitcoin::locktime::absolute::LockTime; +use bitcoin::transaction::Version; use bitcoin::Sequence; use crate::input_type::{InputType, InputTypeError}; @@ -21,8 +22,8 @@ pub(crate) enum InternalValidationError { InvalidInputType(InputTypeError), InvalidProposedInput(crate::psbt::PrevTxOutError), VersionsDontMatch { - proposed: i32, - original: i32, + proposed: Version, + original: Version, }, LockTimesDontMatch { proposed: LockTime, diff --git a/payjoin/src/send/mod.rs b/payjoin/src/send/mod.rs index 175b3dce..754c222b 100644 --- a/payjoin/src/send/mod.rs +++ b/payjoin/src/send/mod.rs @@ -129,7 +129,7 @@ impl<'a> RequestBuilder<'a> { .into_iter() .enumerate() .find(|(_, txo)| payout_scripts.all(|script| script != txo.script_pubkey)) - .map(|(i, txo)| (i, bitcoin::Amount::from_sat(txo.value))) + .map(|(i, txo)| (i, txo.value)) { let input_types = self .psbt @@ -358,7 +358,8 @@ impl RequestContext { #[cfg(feature = "v2")] fn rs_pubkey_from_dir_endpoint(endpoint: &Url) -> Result { - use bitcoin::base64; + use bitcoin::base64::prelude::BASE64_URL_SAFE_NO_PAD; + use bitcoin::base64::Engine; use crate::send::error::ParseSubdirectoryError; @@ -369,7 +370,8 @@ impl RequestContext { .ok_or(ParseSubdirectoryError::MissingSubdirectory)? .to_string(); - let pubkey_bytes = base64::decode_config(subdirectory, base64::URL_SAFE_NO_PAD) + let pubkey_bytes = BASE64_URL_SAFE_NO_PAD + .decode(subdirectory) .map_err(ParseSubdirectoryError::SubdirectoryNotBase64)?; bitcoin::secp256k1::PublicKey::from_slice(&pubkey_bytes) .map_err(ParseSubdirectoryError::SubdirectoryInvalidPubkey) @@ -695,7 +697,7 @@ impl ContextV1 { SenderTxinContainsFinalScriptWitness ); let prevout = original.previous_txout().expect("We've validated this before"); - total_value += bitcoin::Amount::from_sat(prevout.value); + total_value += prevout.value; // We assume the signture will be the same size // I know sigs can be slightly different size but there isn't much to do about // it other than prefer Taproot. @@ -738,7 +740,7 @@ impl ContextV1 { let txout = proposed .previous_txout() .map_err(InternalValidationError::InvalidProposedInput)?; - total_value += bitcoin::Amount::from_sat(txout.value); + total_value += txout.value; check_eq!( InputType::from_spent_input(txout, proposed.psbtin)?, self.input_type, @@ -784,8 +786,8 @@ impl ContextV1 { proposal.unsigned_tx.output.iter().zip(&proposal.outputs) { ensure!(proposed_psbtout.bip32_derivation.is_empty(), TxOutContainsKeyPaths); - total_value += bitcoin::Amount::from_sat(proposed_txout.value); - total_weight += Weight::from_wu(proposed_txout.weight() as u64); + total_value += proposed_txout.value; + total_weight += proposed_txout.weight(); match (original_outputs.peek(), self.fee_contribution) { // fee output ( @@ -795,8 +797,7 @@ impl ContextV1 { && *original_output_index == fee_contrib_idx => { if proposed_txout.value < original_output.value { - contributed_fee = - bitcoin::Amount::from_sat(original_output.value - proposed_txout.value); + contributed_fee = original_output.value - proposed_txout.value; ensure!(contributed_fee < max_fee_contrib, FeeContributionExceedsMaximum); //The remaining fee checks are done in the caller } @@ -852,7 +853,7 @@ fn check_single_payee( for output in &psbt.unsigned_tx.output { if output.script_pubkey == *script_pubkey { if let Some(amount) = amount { - if output.value != amount.to_sat() { + if output.value != amount { return Err(InternalCreateRequestError::PayeeValueNotEqual); } } @@ -897,9 +898,9 @@ fn check_fee_output_amount( fee: bitcoin::Amount, clamp_fee_contribution: bool, ) -> Result { - if output.value < fee.to_sat() { + if output.value < fee { if clamp_fee_contribution { - Ok(bitcoin::Amount::from_sat(output.value)) + Ok(output.value) } else { Err(InternalCreateRequestError::FeeOutputValueLowerThanFeeContribution) } diff --git a/payjoin/src/v2.rs b/payjoin/src/v2.rs index cb30eac8..64d96ed7 100644 --- a/payjoin/src/v2.rs +++ b/payjoin/src/v2.rs @@ -1,7 +1,8 @@ use std::ops::{Deref, DerefMut}; use std::{error, fmt}; -use bitcoin::base64; +use bitcoin::base64::prelude::BASE64_URL_SAFE_NO_PAD; +use bitcoin::base64::Engine; use bitcoin::secp256k1::ecdh::SharedSecret; use bitcoin::secp256k1::{PublicKey, Secp256k1, SecretKey}; use chacha20poly1305::aead::{Aead, KeyInit, OsRng, Payload}; @@ -252,8 +253,7 @@ impl OhttpKeys { impl fmt::Display for OhttpKeys { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - let encoded = - base64::encode_config(self.encode().map_err(|_| fmt::Error)?, base64::URL_SAFE_NO_PAD); + let encoded = BASE64_URL_SAFE_NO_PAD.encode(self.encode().map_err(|_| fmt::Error)?); write!(f, "{}", encoded) } } @@ -262,8 +262,7 @@ impl std::str::FromStr for OhttpKeys { type Err = ParseOhttpKeysError; fn from_str(s: &str) -> Result { - let bytes = base64::decode_config(s, base64::URL_SAFE_NO_PAD) - .map_err(ParseOhttpKeysError::DecodeBase64)?; + let bytes = BASE64_URL_SAFE_NO_PAD.decode(s).map_err(ParseOhttpKeysError::DecodeBase64)?; OhttpKeys::decode(&bytes).map_err(ParseOhttpKeysError::DecodeKeyConfig) } } @@ -312,7 +311,7 @@ impl serde::Serialize for OhttpKeys { #[derive(Debug)] pub enum ParseOhttpKeysError { - DecodeBase64(base64::DecodeError), + DecodeBase64(bitcoin::base64::DecodeError), DecodeKeyConfig(ohttp::Error), } diff --git a/payjoin/tests/integration.rs b/payjoin/tests/integration.rs index 62385acf..e6d8bcf4 100644 --- a/payjoin/tests/integration.rs +++ b/payjoin/tests/integration.rs @@ -6,7 +6,7 @@ mod integration { use bitcoin::psbt::Psbt; use bitcoin::{Amount, FeeRate, OutPoint}; - use bitcoind::bitcoincore_rpc::core_rpc_json::{AddressType, WalletProcessPsbtResult}; + use bitcoind::bitcoincore_rpc::json::{AddressType, WalletProcessPsbtResult}; use bitcoind::bitcoincore_rpc::{self, RpcApi}; use log::{log_enabled, Level}; use once_cell::sync::{Lazy, OnceCell}; @@ -164,7 +164,7 @@ mod integration { // calculate receiver payjoin outputs given receiver payjoin inputs and original_psbt, let txo_to_contribute = bitcoin::TxOut { - value: selected_utxo.amount.to_sat(), + value: selected_utxo.amount, script_pubkey: selected_utxo.script_pub_key.clone(), }; let outpoint_to_contribute = @@ -276,7 +276,7 @@ mod integration { let payjoin_psbt = Psbt::from_str(&payjoin_psbt)?; debug!("Sender's Payjoin PSBT: {:#?}", payjoin_psbt); - Ok(payjoin_psbt.extract_tx()) + Ok(payjoin_psbt.extract_tx()?) } } @@ -763,7 +763,7 @@ mod integration { // calculate receiver payjoin outputs given receiver payjoin inputs and original_psbt, let txo_to_contribute = bitcoin::TxOut { - value: selected_utxo.amount.to_sat(), + value: selected_utxo.amount, script_pubkey: selected_utxo.script_pub_key.clone(), }; let outpoint_to_contribute = @@ -937,7 +937,7 @@ mod integration { let payjoin_psbt = sender.finalize_psbt(&payjoin_psbt, Some(false))?.psbt.unwrap(); let payjoin_psbt = Psbt::from_str(&payjoin_psbt)?; - Ok(payjoin_psbt.extract_tx()) + Ok(payjoin_psbt.extract_tx()?) } } }