From f92e91c6c6a966b258219910233c99a038d86bd4 Mon Sep 17 00:00:00 2001 From: Sonkeng Maldini Date: Wed, 7 Jan 2026 22:56:11 +0100 Subject: [PATCH 1/4] feat: integrate BIP 353 dns payment instructions --- Cargo.lock | 418 +++++++++++++++++++------------- Cargo.toml | 4 +- src/commands.rs | 21 ++ src/dns_payment_instructions.rs | 287 ++++++++++++++++++++++ src/handlers.rs | 64 ++++- src/main.rs | 3 + src/utils.rs | 11 + 7 files changed, 638 insertions(+), 170 deletions(-) create mode 100644 src/dns_payment_instructions.rs diff --git a/Cargo.lock b/Cargo.lock index 6134d115..2f84fb4f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -150,9 +150,9 @@ checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" [[package]] name = "aws-lc-rs" -version = "1.16.2" +version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a054912289d18629dc78375ba2c3726a3afe3ff71b4edba9dedfca0e3446d1fc" +checksum = "5ec2f1fc3ec205783a5da9a7e6c1509cc69dedf09a1949e412c1e18469326d00" dependencies = [ "aws-lc-sys", "zeroize", @@ -160,9 +160,9 @@ dependencies = [ [[package]] name = "aws-lc-sys" -version = "0.39.1" +version = "0.41.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83a25cf98105baa966497416dbd42565ce3a8cf8dbfd59803ec9ad46f3126399" +checksum = "1a2f9779ce85b93ab6170dd940ad0169b5766ff848247aff13bb788b832fe3f4" dependencies = [ "cc", "cmake", @@ -210,6 +210,7 @@ dependencies = [ "bdk_redb", "bdk_sp", "bdk_wallet", + "bitcoin-payment-instructions", "claims", "clap", "clap_complete", @@ -218,14 +219,14 @@ dependencies = [ "env_logger", "log", "payjoin", - "reqwest 0.13.2", + "reqwest 0.13.4", "serde", "serde_json", "shlex", "tap", "thiserror 2.0.18", "tokio", - "toml 1.1.1+spec-1.1.0", + "toml 1.1.2+spec-1.1.0", "tracing", "tracing-subscriber", "url", @@ -380,7 +381,7 @@ dependencies = [ "bitcoin", "bitcoin_hashes 0.15.0", "chacha20-poly1305", - "rand 0.8.5", + "rand 0.8.6", "tokio", ] @@ -397,9 +398,9 @@ dependencies = [ [[package]] name = "bitcoin" -version = "0.32.8" +version = "0.32.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e499f9fc0407f50fe98af744ab44fa67d409f76b6772e1689ec8485eb0c0f66" +checksum = "9cf93e61f2dbc3e3c41234ca26a65e2c0b0975c52e0f069ab9893ebbede584d3" dependencies = [ "base58ck", "base64 0.21.7", @@ -487,7 +488,7 @@ dependencies = [ "hkdf 0.11.0", "lazy_static", "log", - "rand 0.8.5", + "rand 0.8.6", "serde", "serde_derive", "sha2 0.9.9", @@ -495,11 +496,24 @@ dependencies = [ "toml 0.5.11", ] +[[package]] +name = "bitcoin-payment-instructions" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c300c948b2ff78c965ea3a613372352125448a22f1acf49e95e3878149824091" +dependencies = [ + "bitcoin", + "dnssec-prover", + "getrandom 0.3.4", + "lightning", + "lightning-invoice", +] + [[package]] name = "bitcoin-units" -version = "0.1.2" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5285c8bcaa25876d07f37e3d30c303f2609179716e11d688f51e8f1fe70063e2" +checksum = "346568ebaab2918487cea76dd55dae13c27bb618cdb737c952e69eb2017c4118" dependencies = [ "bitcoin-internals 0.3.0", "serde", @@ -562,9 +576,9 @@ dependencies = [ [[package]] name = "bitflags" -version = "2.11.0" +version = "2.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "843867be96c8daad0d758b57df9392b6d8d271134fce549de6ce169ff98a92af" +checksum = "c4512299f36f043ab09a583e57bceb5a5aab7a73db1805848e8fef3c9e8c78b3" [[package]] name = "block-buffer" @@ -586,9 +600,9 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.20.2" +version = "3.20.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d20789868f4b01b2f2caec9f5c4e0213b41e3e5702a50157d699ae31ced2fcb" +checksum = "72f5acc6cb2ba439de613abc23857ec3d78374d8ed5ac84e9d11336e87da8649" [[package]] name = "byteorder" @@ -604,9 +618,9 @@ checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33" [[package]] name = "cc" -version = "1.2.58" +version = "1.2.62" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1e928d4b69e3077709075a938a05ffbedfa53a84c8f766efbf8220bb1ff60e1" +checksum = "a1dce859f0832a7d088c4f1119888ab94ef4b5d6795d1ce05afb7fe159d79f98" dependencies = [ "find-msvc-tools", "jobserver", @@ -736,9 +750,9 @@ checksum = "bba18ee93d577a8428902687bcc2b6b45a56b1981a1f6d779731c86cc4c5db18" [[package]] name = "clap" -version = "4.6.0" +version = "4.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b193af5b67834b676abd72466a96c1024e6a6ad978a1f484bd90b85c94041351" +checksum = "1ddb117e43bbf7dacf0a4190fef4d345b9bad68dfc649cb349e7d17d28428e51" dependencies = [ "clap_builder", "clap_derive", @@ -758,18 +772,18 @@ dependencies = [ [[package]] name = "clap_complete" -version = "4.6.0" +version = "4.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19c9f1dde76b736e3681f28cec9d5a61299cbaae0fce80a68e43724ad56031eb" +checksum = "e0a7a9bfdb35811f9e59832f0f05975114d2251b415fb534108e6f34060fd772" dependencies = [ "clap", ] [[package]] name = "clap_derive" -version = "4.6.0" +version = "4.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1110bd8a634a1ab8cb04345d8d878267d57c3cf1b38d91b71af6686408bbca6a" +checksum = "f2ce8604710f6733aa641a2b3731eaa1e8b3d9973d5e3565da11800813f997a9" dependencies = [ "heck", "proc-macro2", @@ -964,6 +978,16 @@ dependencies = [ "syn", ] +[[package]] +name = "dnssec-prover" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec4f825369fc7134da70ca4040fddc8e03b80a46d249ae38d9c1c39b7b4476bf" +dependencies = [ + "bitcoin_hashes 0.14.1", + "tokio", +] + [[package]] name = "dunce" version = "1.0.5" @@ -980,7 +1004,7 @@ dependencies = [ "byteorder", "libc", "log", - "rustls 0.23.37", + "rustls 0.23.40", "serde", "serde_json", "webpki-roots 0.25.4", @@ -1056,9 +1080,9 @@ checksum = "7360491ce676a36bf9bb3c56c1aa791658183a54d2744120f27285738d90465a" [[package]] name = "fastrand" -version = "2.3.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" +checksum = "9f1f227452a390804cdb637b74a86990f2a7d7ba4b7d5693aac9b4dd6defd8d6" [[package]] name = "find-msvc-tools" @@ -1261,6 +1285,12 @@ dependencies = [ "zerocopy", ] +[[package]] +name = "hashbrown" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" + [[package]] name = "hashbrown" version = "0.14.5" @@ -1282,9 +1312,9 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.16.1" +version = "0.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100" +checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a" [[package]] name = "hashlink" @@ -1430,19 +1460,18 @@ dependencies = [ [[package]] name = "hyper-rustls" -version = "0.27.7" +version = "0.27.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3c93eb611681b207e1fe55d5a71ecf91572ec8a6705cdb6857f7d8d5242cf58" +checksum = "33ca68d021ef39cf6463ab54c1d0f5daf03377b70561305bb89a8f83aab66e0f" dependencies = [ "http", "hyper", "hyper-util", - "rustls 0.23.37", - "rustls-pki-types", + "rustls 0.23.40", "tokio", "tokio-rustls", "tower-service", - "webpki-roots 1.0.6", + "webpki-roots 1.0.7", ] [[package]] @@ -1486,12 +1515,13 @@ dependencies = [ [[package]] name = "icu_collections" -version = "2.1.1" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c6b649701667bbe825c3b7e6388cb521c23d88644678e83c0c4d0a621a34b43" +checksum = "2984d1cd16c883d7935b9e07e44071dca8d917fd52ecc02c04d5fa0b5a3f191c" dependencies = [ "displaydoc", "potential_utf", + "utf8_iter", "yoke", "zerofrom", "zerovec", @@ -1499,9 +1529,9 @@ dependencies = [ [[package]] name = "icu_locale_core" -version = "2.1.1" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "edba7861004dd3714265b4db54a3c390e880ab658fec5f7db895fae2046b5bb6" +checksum = "92219b62b3e2b4d88ac5119f8904c10f8f61bf7e95b640d25ba3075e6cac2c29" dependencies = [ "displaydoc", "litemap", @@ -1512,9 +1542,9 @@ dependencies = [ [[package]] name = "icu_normalizer" -version = "2.1.1" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f6c8828b67bf8908d82127b2054ea1b4427ff0230ee9141c54251934ab1b599" +checksum = "c56e5ee99d6e3d33bd91c5d85458b6005a22140021cc324cea84dd0e72cff3b4" dependencies = [ "icu_collections", "icu_normalizer_data", @@ -1526,15 +1556,15 @@ dependencies = [ [[package]] name = "icu_normalizer_data" -version = "2.1.1" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7aedcccd01fc5fe81e6b489c15b247b8b0690feb23304303a9e560f37efc560a" +checksum = "da3be0ae77ea334f4da67c12f149704f19f81d1adf7c51cf482943e84a2bad38" [[package]] name = "icu_properties" -version = "2.1.2" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "020bfc02fe870ec3a66d93e677ccca0562506e5872c650f893269e08615d74ec" +checksum = "bee3b67d0ea5c2cca5003417989af8996f8604e34fb9ddf96208a033901e70de" dependencies = [ "icu_collections", "icu_locale_core", @@ -1546,15 +1576,15 @@ dependencies = [ [[package]] name = "icu_properties_data" -version = "2.1.2" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "616c294cf8d725c6afcd8f55abc17c56464ef6211f9ed59cccffe534129c77af" +checksum = "8e2bbb201e0c04f7b4b3e14382af113e17ba4f63e2c9d2ee626b720cbce54a14" [[package]] name = "icu_provider" -version = "2.1.1" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85962cf0ce02e1e0a629cc34e7ca3e373ce20dda4c4d7294bbd0bf1fdb59e614" +checksum = "139c4cf31c8b5f33d7e199446eff9c1e02decfc2f0eec2c8d71f65befa45b421" dependencies = [ "displaydoc", "icu_locale_core", @@ -1584,9 +1614,9 @@ dependencies = [ [[package]] name = "idna_adapter" -version = "1.2.1" +version = "1.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3acae9609540aa318d1bc588455225fb2085b9ed0c4f6bd0d9d5bcd86f1a0344" +checksum = "cb68373c0d6620ef8105e855e7745e18b0d00d3bdb07fb532e434244cdb9a714" dependencies = [ "icu_normalizer", "icu_properties", @@ -1594,12 +1624,12 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.13.0" +version = "2.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7714e70437a7dc3ac8eb7e6f8df75fd8eb422675fc7678aff7364301092b1017" +checksum = "d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9" dependencies = [ "equivalent", - "hashbrown 0.16.1", + "hashbrown 0.17.1", "serde", "serde_core", ] @@ -1619,16 +1649,6 @@ version = "2.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d98f6fed1fde3f8c21bc40a1abb88dd75e67924f9cffc3ef95607bad8017f8e2" -[[package]] -name = "iri-string" -version = "0.7.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25e659a4bb38e810ebc252e53b5814ff908a8c58c2a9ce2fae1bbec24cbf4e20" -dependencies = [ - "memchr", - "serde", -] - [[package]] name = "is_terminal_polyfill" version = "1.70.2" @@ -1643,9 +1663,9 @@ checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" [[package]] name = "jiff" -version = "0.2.23" +version = "0.2.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a3546dc96b6d42c5f24902af9e2538e82e39ad350b0c766eb3fbf2d8f3d8359" +checksum = "6835eea34fb6321b9b3aa7b685c2b433948c09447e389dc017fdf687d5d11e65" dependencies = [ "jiff-static", "log", @@ -1656,9 +1676,9 @@ dependencies = [ [[package]] name = "jiff-static" -version = "0.2.23" +version = "0.2.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a8c8b344124222efd714b73bb41f8b5120b27a7cc1c75593a6ff768d9d05aa4" +checksum = "3c22e04db9c58f5136eb1757f3d5c49a7b187f49e52185228cbd2f5acdfcc08c" dependencies = [ "proc-macro2", "quote", @@ -1677,9 +1697,9 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.93" +version = "0.3.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "797146bb2677299a1eb6b7b50a890f4c361b29ef967addf5b2fa45dae1bb6d7d" +checksum = "142bc4740e452c1e57ade0cbc129f139c9093e354346f0872ef985f4f5cf5f11" dependencies = [ "cfg-if", "futures-util", @@ -1713,15 +1733,21 @@ checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2" [[package]] name = "libc" -version = "0.2.183" +version = "0.2.186" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68ab91017fe16c622486840e4c83c9a37afeff978bd239b5293d61ece587de66" + +[[package]] +name = "libm" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5b646652bf6661599e1da8901b3b9522896f01e736bad5f723fe7a3a27f899d" +checksum = "b6d2cec3eae94f9f509c767b45932f1ada8350c4bdb85af2fcab4a3c14807981" [[package]] name = "libredox" -version = "0.1.15" +version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ddbf48fd451246b1f8c2610bd3b4ac0cc6e149d89832867093ab69a17194f08" +checksum = "e02f3bb43d335493c96bf3fd3a321600bf6bd07ed34bc64118e9293bdffea46c" dependencies = [ "libc", ] @@ -1737,6 +1763,54 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "lightning" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c90397b635e3ece6b9a723fb470a46cb9b3592f217d72e40540a5fada00289d" +dependencies = [ + "bech32", + "bitcoin", + "dnssec-prover", + "hashbrown 0.13.2", + "libm", + "lightning-invoice", + "lightning-macros", + "lightning-types", + "possiblyrandom", +] + +[[package]] +name = "lightning-invoice" +version = "0.34.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b85e5e14bcdb30d746e9785b04f27938292e8944f78f26517e01e91691f6b3f2" +dependencies = [ + "bech32", + "bitcoin", + "lightning-types", +] + +[[package]] +name = "lightning-macros" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4c717494cdc2c8bb85bee7113031248f5f6c64f8802b33c1c9e2d98e594aa71" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "lightning-types" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb1aac93f22f2c2eac8a0ee83bb1a1ea58673caa2c82847302710b83364d04e6" +dependencies = [ + "bitcoin", +] + [[package]] name = "linux-raw-sys" version = "0.12.1" @@ -1745,9 +1819,9 @@ checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53" [[package]] name = "litemap" -version = "0.8.1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6373607a59f0be73a39b6fe456b8192fcc3585f602af20751600e974dd455e77" +checksum = "92daf443525c4cce67b150400bc2316076100ce0b3686209eb8cf3c31612e6f0" [[package]] name = "lock_api" @@ -1760,9 +1834,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.29" +version = "0.4.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897" +checksum = "616ec5685824bcc94416c6d4a7a446eea774a31efd7062c8480ba6fd06d7a6e5" [[package]] name = "lru-slab" @@ -1778,9 +1852,9 @@ checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79" [[package]] name = "miniscript" -version = "12.3.5" +version = "12.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "487906208f38448e186e3deb02f2b8ef046a9078b0de00bdb28bf4fb9b76951c" +checksum = "c14116d8342edd3626b0f8e84df16f4e6a76dc04799ba747493403236a1b8ac5" dependencies = [ "bech32", "bitcoin", @@ -1858,15 +1932,14 @@ checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" [[package]] name = "openssl" -version = "0.10.76" +version = "0.10.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "951c002c75e16ea2c65b8c7e4d3d51d5530d8dfa7d060b4776828c88cfb18ecf" +checksum = "a45fa2aa886c42762255da344f0a0d313e254066c46aad76f300c3d3da62d967" dependencies = [ "bitflags", "cfg-if", "foreign-types", "libc", - "once_cell", "openssl-macros", "openssl-sys", ] @@ -1890,9 +1963,9 @@ checksum = "7c87def4c32ab89d880effc9e097653c8da5d6ef28e6b539d313baaacfbafcbe" [[package]] name = "openssl-sys" -version = "0.9.112" +version = "0.9.116" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57d55af3b3e226502be1526dfdba67ab0e9c96fc293004e79576b2b9edb0dbdb" +checksum = "f28a22dc7140cda5f096e5e7724a6962ca81a7f8bfd2979f9b18c11af56318c4" dependencies = [ "cc", "libc", @@ -1968,9 +2041,9 @@ checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" [[package]] name = "pkg-config" -version = "0.3.32" +version = "0.3.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" +checksum = "19f132c84eca552bf34cab8ec81f1c1dcc229b811638f9d283dceabe58c5569e" [[package]] name = "poly1305" @@ -2014,18 +2087,27 @@ checksum = "c33a9471896f1c69cecef8d20cbe2f7accd12527ce60845ff44c153bb2a21b49" [[package]] name = "portable-atomic-util" -version = "0.2.6" +version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "091397be61a01d4be58e7841595bd4bfedb15f1cd54977d79b8271e94ed799a3" +checksum = "c2a106d1259c23fac8e543272398ae0e3c0b8d33c88ed73d0cc71b0f1d902618" dependencies = [ "portable-atomic", ] +[[package]] +name = "possiblyrandom" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b122a615d72104fb3d8b26523fdf9232cd8ee06949fb37e4ce3ff964d15dffd" +dependencies = [ + "getrandom 0.2.17", +] + [[package]] name = "potential_utf" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b73949432f5e2a09657003c25bca5e19a0e9c84f8058ca374f49e0ebe605af77" +checksum = "0103b1cef7ec0cf76490e969665504990193874ea05c85ff9bab8b911d0a0564" dependencies = [ "zerovec", ] @@ -2070,7 +2152,7 @@ dependencies = [ "quinn-proto", "quinn-udp", "rustc-hash", - "rustls 0.23.37", + "rustls 0.23.40", "socket2", "thiserror 2.0.18", "tokio", @@ -2087,10 +2169,10 @@ dependencies = [ "bytes", "getrandom 0.3.4", "lru-slab", - "rand 0.9.3", + "rand 0.9.4", "ring", "rustc-hash", - "rustls 0.23.37", + "rustls 0.23.40", "rustls-pki-types", "slab", "thiserror 2.0.18", @@ -2136,9 +2218,9 @@ checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" [[package]] name = "rand" -version = "0.8.5" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +checksum = "5ca0ecfa931c29007047d1bc58e623ab12e5590e8c7cc53200d5202b69266d8a" dependencies = [ "libc", "rand_chacha 0.3.1", @@ -2147,9 +2229,9 @@ dependencies = [ [[package]] name = "rand" -version = "0.9.3" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ec095654a25171c2124e9e3393a930bddbffdc939556c914957a4c3e0a87166" +checksum = "44c5af06bb1b7d3216d91932aed5265164bf384dc89cd6ba05cf59a35f5f76ea" dependencies = [ "rand_chacha 0.9.0", "rand_core 0.9.5", @@ -2273,7 +2355,7 @@ dependencies = [ "percent-encoding", "pin-project-lite", "quinn", - "rustls 0.23.37", + "rustls 0.23.40", "rustls-pki-types", "serde", "serde_json", @@ -2289,14 +2371,14 @@ dependencies = [ "wasm-bindgen", "wasm-bindgen-futures", "web-sys", - "webpki-roots 1.0.6", + "webpki-roots 1.0.7", ] [[package]] name = "reqwest" -version = "0.13.2" +version = "0.13.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab3f43e3283ab1488b624b44b0e988d0acea0b3214e694730a055cb6b2efa801" +checksum = "219c5811de6525e5416c7d5d53bb656d3afdbc6c5af816e0802bcfa42dbdc1c3" dependencies = [ "base64 0.22.1", "bytes", @@ -2382,25 +2464,25 @@ dependencies = [ [[package]] name = "rustls" -version = "0.23.37" +version = "0.23.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "758025cb5fccfd3bc2fd74708fd4682be41d99e5dff73c377c0646c6012c73a4" +checksum = "ef86cd5876211988985292b91c96a8f2d298df24e75989a43a3c73f2d4d8168b" dependencies = [ "aws-lc-rs", "log", "once_cell", "ring", "rustls-pki-types", - "rustls-webpki 0.103.10", + "rustls-webpki 0.103.13", "subtle", "zeroize", ] [[package]] name = "rustls-pki-types" -version = "1.14.0" +version = "1.14.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be040f8b0a225e40375822a563fa9524378b9d63112f53e19ffff34df5d33fdd" +checksum = "30a7197ae7eb376e574fe940d068c30fe0462554a3ddbe4eca7838e049c937a9" dependencies = [ "web-time", "zeroize", @@ -2418,9 +2500,9 @@ dependencies = [ [[package]] name = "rustls-webpki" -version = "0.103.10" +version = "0.103.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df33b2b81ac578cabaf06b89b0631153a3f416b0a886e8a7a1707fb51abbd1ef" +checksum = "61c429a8649f110dddef65e2a5ad240f747e85f7758a6bccc7e5777bd33f756e" dependencies = [ "aws-lc-rs", "ring", @@ -2472,7 +2554,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9465315bc9d4566e1724f0fffcbcc446268cb522e60f9a27bcded6b19c108113" dependencies = [ "bitcoin_hashes 0.14.1", - "rand 0.8.5", + "rand 0.8.6", "secp256k1-sys", "serde", ] @@ -2511,9 +2593,9 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.27" +version = "1.0.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d767eb0aabc880b29956c35734170f26ed551a859dbd361d140cdbeca61ab1e2" +checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd" [[package]] name = "serde" @@ -2547,9 +2629,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.149" +version = "1.0.150" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86" +checksum = "e8014e44b4736ed0538adeecded0fce2a272f22dc9578a7eb6b2d9993c74cfb9" dependencies = [ "itoa", "memchr", @@ -2778,9 +2860,9 @@ dependencies = [ [[package]] name = "tinystr" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42d3e9c45c09de15d06dd8acf5f4e0e399e85927b7f00711024eb7ae10fa4869" +checksum = "c8323304221c2a851516f22236c5722a72eaa19749016521d6dff0824447d96d" dependencies = [ "displaydoc", "zerovec", @@ -2803,9 +2885,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.50.0" +version = "1.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "27ad5e34374e03cfffefc301becb44e9dc3c17584f414349ebe29ed26661822d" +checksum = "8fc7f01b389ac15039e4dc9531aa973a135d7a4135281b12d7c1bc79fd57fffe" dependencies = [ "bytes", "libc", @@ -2820,9 +2902,9 @@ dependencies = [ [[package]] name = "tokio-macros" -version = "2.6.1" +version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c55a2eff8b69ce66c84f85e1da1c233edc36ceb85a2058d11b0d6a3c7e7569c" +checksum = "385a6cb71ab9ab790c5fe8d67f1645e6c450a7ce006a33de03daa956cf70a496" dependencies = [ "proc-macro2", "quote", @@ -2845,7 +2927,7 @@ version = "0.26.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1729aa945f29d91ba541258c8df89027d5792d85a8841fb65e8bf0f4ede4ef61" dependencies = [ - "rustls 0.23.37", + "rustls 0.23.40", "tokio", ] @@ -2860,9 +2942,9 @@ dependencies = [ [[package]] name = "toml" -version = "1.1.1+spec-1.1.0" +version = "1.1.2+spec-1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "994b95d9e7bae62b34bab0e2a4510b801fa466066a6a8b2b57361fa1eba068ee" +checksum = "81f3d15e84cbcd896376e6730314d59fb5a87f31e4b038454184435cd57defee" dependencies = [ "indexmap", "serde_core", @@ -2884,9 +2966,9 @@ dependencies = [ [[package]] name = "toml_parser" -version = "1.1.1+spec-1.1.0" +version = "1.1.2+spec-1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39ca317ebc49f06bd748bfba29533eac9485569dc9bf80b849024b025e814fb9" +checksum = "a2abe9b86193656635d2411dc43050282ca48aa31c2451210f4202550afb7526" dependencies = [ "winnow", ] @@ -2914,20 +2996,20 @@ dependencies = [ [[package]] name = "tower-http" -version = "0.6.8" +version = "0.6.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4e6559d53cc268e5031cd8429d05415bc4cb4aefc4aa5d6cc35fbf5b924a1f8" +checksum = "4cfcf7e2740e6fc6d4d688b4ef00650406bb94adf4731e43c096c3a19fe40840" dependencies = [ "bitflags", "bytes", "futures-util", "http", "http-body", - "iri-string", "pin-project-lite", "tower", "tower-layer", "tower-service", + "url", ] [[package]] @@ -3007,9 +3089,9 @@ checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" [[package]] name = "typenum" -version = "1.19.0" +version = "1.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "562d481066bde0658276a35467c4af00bdc6ee726305698a55b86e61d7ad82bb" +checksum = "40ce102ab67701b8526c123c1bab5cbe42d7040ccfd0f64af1a385808d2f43de" [[package]] name = "unicode-ident" @@ -3124,11 +3206,11 @@ checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" [[package]] name = "wasip2" -version = "1.0.2+wasi-0.2.9" +version = "1.0.3+wasi-0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9517f9239f02c069db75e65f174b3da828fe5f5b945c4dd26bd25d89c03ebcf5" +checksum = "20064672db26d7cdc89c7798c48a0fdfac8213434a1186e5ef29fd560ae223d6" dependencies = [ - "wit-bindgen", + "wit-bindgen 0.57.1", ] [[package]] @@ -3137,14 +3219,14 @@ version = "0.4.0+wasi-0.3.0-rc-2026-01-06" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5428f8bf88ea5ddc08faddef2ac4a67e390b88186c703ce6dbd955e1c145aca5" dependencies = [ - "wit-bindgen", + "wit-bindgen 0.51.0", ] [[package]] name = "wasm-bindgen" -version = "0.2.116" +version = "0.2.122" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dc0882f7b5bb01ae8c5215a1230832694481c1a4be062fd410e12ea3da5b631" +checksum = "3ed04576f974d2b2fba0f38c51dbc5518011e38c36bf1143164be765528fd409" dependencies = [ "cfg-if", "once_cell", @@ -3155,9 +3237,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.66" +version = "0.4.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19280959e2844181895ef62f065c63e0ca07ece4771b53d89bfdb967d97cbf05" +checksum = "9473dbd2991ae90b6291c3c32c30c6187ac49aa32f9905d1cce280ec1e110b0f" dependencies = [ "js-sys", "wasm-bindgen", @@ -3165,9 +3247,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.116" +version = "0.2.122" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75973d3066e01d035dbedaad2864c398df42f8dd7b1ea057c35b8407c015b537" +checksum = "916151b09da36bd82f6615cbf3a419e2f0ba23a03c6160e8e92eb6bd4aa1dec6" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -3175,9 +3257,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.116" +version = "0.2.122" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91af5e4be765819e0bcfee7322c14374dc821e35e72fa663a830bbc7dc199eac" +checksum = "299047362ccbfce148b67ab7e73349f77748e00c8296f9542adfad2ad82c5c5e" dependencies = [ "bumpalo", "proc-macro2", @@ -3188,9 +3270,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.116" +version = "0.2.122" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9bf0406a78f02f336bf1e451799cca198e8acde4ffa278f0fb20487b150a633" +checksum = "9a929b2c61f11ba3e9bc35b50c1f25cb38e0e892c0c231ae2b8cf78d5dad4437" dependencies = [ "unicode-ident", ] @@ -3231,9 +3313,9 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.93" +version = "0.3.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "749466a37ee189057f54748b200186b59a03417a117267baf3fd89cecc9fb837" +checksum = "6d621441cfc37b84979402712047321980c178f299193a3589d05b99e8763436" dependencies = [ "js-sys", "wasm-bindgen", @@ -3257,9 +3339,9 @@ checksum = "5f20c57d8d7db6d3b86154206ae5d8fba62dd39573114de97c2cb0578251f8e1" [[package]] name = "webpki-roots" -version = "1.0.6" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22cfaf3c063993ff62e73cb4311efde4db1efb31ab78a3e5c457939ad5cc0bed" +checksum = "52f5ee44c96cf55f1b349600768e3ece3a8f26010c05265ab73f945bb1a2eb9d" dependencies = [ "rustls-pki-types", ] @@ -3459,9 +3541,9 @@ checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650" [[package]] name = "winnow" -version = "1.0.1" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09dac053f1cd375980747450bfc7250c264eaae0583872e845c0c7cd578872b5" +checksum = "0592e1c9d151f854e6fd382574c3a0855250e1d9b2f99d9281c6e6391af352f1" [[package]] name = "wit-bindgen" @@ -3472,6 +3554,12 @@ dependencies = [ "wit-bindgen-rust-macro", ] +[[package]] +name = "wit-bindgen" +version = "0.57.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ebf944e87a7c253233ad6766e082e3cd714b5d03812acc24c318f549614536e" + [[package]] name = "wit-bindgen-core" version = "0.51.0" @@ -3553,15 +3641,15 @@ dependencies = [ [[package]] name = "writeable" -version = "0.6.2" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9edde0db4769d2dc68579893f2306b26c6ecfbe0ef499b013d731b7b9247e0b9" +checksum = "1ffae5123b2d3fc086436f8834ae3ab053a283cfac8fe0a0b8eaae044768a4c4" [[package]] name = "yoke" -version = "0.8.1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72d6e5c6afb84d73944e5cedb052c4680d5657337201555f9f2a16b7406d4954" +checksum = "abe8c5fda708d9ca3df187cae8bfb9ceda00dd96231bed36e445a1a48e66f9ca" dependencies = [ "stable_deref_trait", "yoke-derive", @@ -3570,9 +3658,9 @@ dependencies = [ [[package]] name = "yoke-derive" -version = "0.8.1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b659052874eb698efe5b9e8cf382204678a0086ebf46982b79d6ca3182927e5d" +checksum = "de844c262c8848816172cef550288e7dc6c7b7814b4ee56b3e1553f275f1858e" dependencies = [ "proc-macro2", "quote", @@ -3602,18 +3690,18 @@ dependencies = [ [[package]] name = "zerofrom" -version = "0.1.6" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50cc42e0333e05660c3587f3bf9d0478688e15d870fab3346451ce7f8c9fbea5" +checksum = "0ec05a11813ea801ff6d75110ad09cd0824ddba17dfe17128ea0d5f68e6c5272" dependencies = [ "zerofrom-derive", ] [[package]] name = "zerofrom-derive" -version = "0.1.6" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d71e5d6e06ab090c67b5e44993ec16b72dcbaabc526db883a360057678b48502" +checksum = "11532158c46691caf0f2593ea8358fed6bbf68a0315e80aae9bd41fbade684a1" dependencies = [ "proc-macro2", "quote", @@ -3643,9 +3731,9 @@ dependencies = [ [[package]] name = "zerotrie" -version = "0.2.3" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a59c17a5562d507e4b54960e8569ebee33bee890c70aa3fe7b97e85a9fd7851" +checksum = "0f9152d31db0792fa83f70fb2f83148effb5c1f5b8c7686c3459e361d9bc20bf" dependencies = [ "displaydoc", "yoke", @@ -3654,9 +3742,9 @@ dependencies = [ [[package]] name = "zerovec" -version = "0.11.5" +version = "0.11.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c28719294829477f525be0186d13efa9a3c602f7ec202ca9e353d310fb9a002" +checksum = "90f911cbc359ab6af17377d242225f4d75119aec87ea711a880987b18cd7b239" dependencies = [ "yoke", "zerofrom", @@ -3665,9 +3753,9 @@ dependencies = [ [[package]] name = "zerovec-derive" -version = "0.11.2" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eadce39539ca5cb3985590102671f2567e659fca9666581ad3411d59207951f3" +checksum = "625dc425cab0dca6dc3c3319506e6593dcb08a9f387ea3b284dbd52a92c40555" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index e5e54bb5..ffc24b89 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,6 +40,7 @@ payjoin = { version = "=1.0.0-rc.1", features = ["v1", "v2", "io", "_test-utils" reqwest = { version = "0.13.2", default-features = false, optional = true } url = { version = "2.5.8", optional = true } bdk_bip322 = { version = "0.1.0", optional = true } +bitcoin-payment-instructions = { version = "0.7.0", optional = true} [features] default = ["repl", "sqlite"] @@ -55,7 +56,8 @@ redb = ["bdk_redb"] cbf = ["bdk_kyoto", "_payjoin-dependencies"] electrum = ["bdk_electrum", "_payjoin-dependencies"] esplora = ["bdk_esplora", "_payjoin-dependencies"] -rpc = ["bdk_bitcoind_rpc", "_payjoin-dependencies"] +rpc = ["bdk_bitcoind_rpc", "_payjoin-dependencies"] +dns_payment = ["bitcoin-payment-instructions"] # Internal features _payjoin-dependencies = ["payjoin", "reqwest", "url"] diff --git a/src/commands.rs b/src/commands.rs index 46404dcf..2db5276c 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -16,6 +16,7 @@ #[cfg(feature = "silent-payments")] use {crate::utils::parse_sp_code_value_pairs, bdk_sp::encoding::SilentPaymentCode}; + use bdk_wallet::bitcoin::{ Address, Network, OutPoint, ScriptBuf, bip32::{DerivationPath, Xpriv}, @@ -23,6 +24,8 @@ use bdk_wallet::bitcoin::{ use clap::{Args, Parser, Subcommand, ValueEnum, value_parser}; use clap_complete::Shell; +#[cfg(feature = "dns_payment")] +use crate::utils::parse_dns_recipient; #[cfg(any(feature = "electrum", feature = "esplora", feature = "rpc"))] use crate::utils::parse_proxy_auth; use crate::utils::{parse_address, parse_outpoint, parse_recipient}; @@ -198,6 +201,16 @@ pub enum CliSubCommand { #[arg(long = "spend_key")] spend: bdk_sp::bitcoin::secp256k1::PublicKey, }, + + #[cfg(feature = "dns_payment")] + /// Resolves BIP-353 DNS payment instructions for a human-readable name. + ResolveDnsRecipient { + /// Human-readable name (e.g. user@domain.com) + hrn: String, + /// DNS resolver address + #[arg(long, default_value = "8.8.8.8")] + resolver: String, + }, } /// Wallet operation subcommands. @@ -370,6 +383,14 @@ pub enum OfflineWalletSubCommand { // Address and amount parsing is done at run time in handler function. #[arg(env = "ADDRESS:SAT", long = "to", required = true, value_parser = parse_recipient)] recipients: Vec<(ScriptBuf, u64)>, + #[cfg(feature = "dns_payment")] + /// Adds DNS recipients to the transaction + #[arg(long = "to_dns", value_parser = parse_dns_recipient)] + dns_recipients: Vec<(String, u64)>, + #[cfg(feature = "dns_payment")] + /// Custom resolver DNS IP to be used for resolution. + #[arg(long = "dns_resolver", default_value = "8.8.8.8:53")] + dns_resolver: String, /// Sends all the funds (or all the selected utxos). Requires only one recipient with value 0. #[arg(long = "send_all", short = 'a')] send_all: bool, diff --git a/src/dns_payment_instructions.rs b/src/dns_payment_instructions.rs new file mode 100644 index 00000000..88453d7e --- /dev/null +++ b/src/dns_payment_instructions.rs @@ -0,0 +1,287 @@ +use bdk_wallet::bitcoin::{Address, Amount, Network}; +use bitcoin_payment_instructions::{ + FixedAmountPaymentInstructions, ParseError, PaymentInstructions, PaymentMethod, + PaymentMethodType, amount, dns_resolver::DNSHrnResolver, +}; +use cli_table::{Cell, Style, Table, format::Justify}; +use core::{net::SocketAddr, str::FromStr}; + +use crate::{error::BDKCliError as Error, utils::shorten}; + +#[derive(Debug)] +pub struct Payment { + pub payment_methods: Vec, + pub min_amount: Option, + pub max_amount: Option, + pub description: Option, + pub expected_amount: Option, + pub receiving_addr: Option
, + pub hrn: String, + pub notes: String, +} + +impl Payment { + pub fn display(&self, pretty: bool) -> Result { + let mut methods: Vec = Vec::new(); + self.payment_methods.iter().for_each(|pm| match pm { + bitcoin_payment_instructions::PaymentMethod::LightningBolt11(bolt11) => { + methods.push(format!("Bolt 11 invoice ({})", shorten(bolt11, 20, 15))) + } + bitcoin_payment_instructions::PaymentMethod::LightningBolt12(offer) => { + methods.push(format!("Bolt 12 invoice ({})", shorten(offer, 20, 15))) + } + bitcoin_payment_instructions::PaymentMethod::OnChain(address) => { + methods.push(format!("On chain ({})", address)) + } + bitcoin_payment_instructions::PaymentMethod::Cashu(csh) => { + methods.push(format!("Cashu payment ({})", shorten(csh, 20, 15))) + } + }); + + if pretty { + let mut table = vec![vec![ + "HRN".cell().bold(true), + self.hrn.to_string().cell().justify(Justify::Right), + ]]; + + if let Some(min_amnt) = self.min_amount { + table.push(vec![ + "Min amount".cell().bold(true), + min_amnt.to_string().cell().justify(Justify::Right), + ]); + } + + if let Some(max_amnt) = self.max_amount { + table.push(vec![ + "Max amount".cell().bold(true), + max_amnt.to_string().cell().justify(Justify::Right), + ]); + } + + if let Some(send_amnt) = self.expected_amount { + table.push(vec![ + "Expected Amount to send".cell().bold(true), + send_amnt.to_string().cell().justify(Justify::Right), + ]); + } + + if let Some(descr) = &self.description { + table.push(vec![ + "Description".cell().bold(true), + descr.cell().justify(Justify::Right), + ]); + } + + table.push(vec![ + "Accepted methods".cell().bold(true), + methods.join(", ").cell().justify(Justify::Right), + ]); + table.push(vec![ + "Notes".cell().bold(true), + self.notes.clone().cell().justify(Justify::Right), + ]); + + let table = table + .table() + .display() + .map_err(|e| Error::Generic(e.to_string()))?; + + Ok(format!("{table}")) + } else { + Ok(serde_json::to_string_pretty(&serde_json::json!({ + "hrn": self.hrn, + "payment_methods": methods, + "description": self.description, + "min_amount": self.min_amount, + "max_amount": self.max_amount, + "expected_amount_to_send": self.expected_amount, + "notes": self.notes + }))?) + } + } +} +pub(crate) async fn parse_dns_instructions( + hrn: &str, + network: Network, + resolver_ip: String, +) -> Result<(DNSHrnResolver, PaymentInstructions), ParseError> { + let ip_address = if resolver_ip.contains(':') { + resolver_ip + } else { + format!("{resolver_ip}:53") + }; + + let sock_addr = SocketAddr::from_str(&ip_address).map_err(|_| { + ParseError::HrnResolutionError("Unable to create socket from provided address") + })?; + let resolver = DNSHrnResolver(sock_addr); + let instructions = PaymentInstructions::parse(hrn, network, &resolver, true).await?; + Ok((resolver, instructions)) +} + +fn get_onchain_info( + instructions: &FixedAmountPaymentInstructions, +) -> Result<(Address, Amount), Error> { + // Look for on chain payment method as it's the only one we can support + let PaymentMethod::OnChain(addr) = instructions + .methods() + .iter() + .find(|ix| matches!(ix, PaymentMethod::OnChain(_))) + .ok_or(Error::Generic( + "Missing Onchain payment method option.".to_string(), + ))? + else { + return Err(Error::Generic("Unsupported payment method".to_string())); + }; + + let Some(onchain_amount) = instructions.onchain_payment_amount() else { + return Err(Error::Generic( + "On chain amount should be specified".to_string(), + )); + }; + + // We need this conversion since Amount from instructions is different from Amount from bitcoin + Ok((addr.clone(), Amount::from_sat(onchain_amount.milli_sats()))) +} + +pub async fn process_instructions( + amount_to_send: Amount, + payment_instructions: &PaymentInstructions, + resolver: DNSHrnResolver, +) -> Result { + match payment_instructions { + PaymentInstructions::ConfigurableAmount(instructions) => { + // Look for on chain payment method as it's the only one we can support + if !instructions + .methods() + .any(|method| matches!(method.method_type(), PaymentMethodType::OnChain)) + { + return Err(Error::Generic("Unsupported payment method".to_string())); + } + + let min_amount = instructions + .min_amt() + .map(|amnt| Amount::from_sat(amnt.milli_sats())); + + let max_amount = instructions + .max_amt() + .map(|amnt| Amount::from_sat(amnt.milli_sats())); + + if min_amount.is_some_and(|min| amount_to_send < min) { + return Err(Error::Generic( + format!( + "Amount to send should be greater than min {}", + min_amount.unwrap() + ) + .to_string(), + )); + } + + if max_amount.is_some_and(|max| amount_to_send > max) { + return Err(Error::Generic( + format!( + "Amount to send should be lower than max {}", + max_amount.unwrap() + ) + .to_string(), + )); + } + + let fixed_instructions = instructions + .clone() + .set_amount( + amount::Amount::from_sats(amount_to_send.to_sat()).unwrap(), + &resolver, + ) + .await + .map_err(|err| { + Error::Generic(format!("Error occured while parsing instructions {err}")) + })?; + + let onchain_details = get_onchain_info(&fixed_instructions)?; + + Ok(Payment { + payment_methods: vec![PaymentMethod::OnChain(onchain_details.clone().0)], + min_amount, + max_amount, + description: instructions.recipient_description().map(|s| s.to_string()), + expected_amount: Some(onchain_details.1), + receiving_addr: Some(onchain_details.0.clone()), + hrn: instructions.human_readable_name().unwrap().to_string(), + notes: "".to_string(), + }) + } + + PaymentInstructions::FixedAmount(instructions) => { + let onchain_info = get_onchain_info(instructions)?; + + Ok(Payment { + payment_methods: vec![PaymentMethod::OnChain(onchain_info.clone().0)], + min_amount: None, + max_amount: instructions + .max_amount() + .map(|amnt| Amount::from_sat(amnt.milli_sats())), + description: instructions.recipient_description().map(|s| s.to_string()), + expected_amount: Some(onchain_info.1), + receiving_addr: Some(onchain_info.0), + notes: "".to_string(), + hrn: instructions.human_readable_name().unwrap().to_string(), + }) + } + } +} + +/// Resolves the dns payment instructions found at the specified Human Readable Name +pub async fn resolve_dns_recipient( + hrn: &str, + network: Network, + ip: String, +) -> Result { + let (resolver, instructions) = parse_dns_instructions(hrn, network, ip).await?; + + match instructions { + PaymentInstructions::ConfigurableAmount(ix) => { + let description = ix.recipient_description().map(|s| s.to_string()); + let min_amount = ix.min_amt().map(|amnt| Amount::from_sat(amnt.milli_sats())); + let max_amount = ix.max_amt().map(|amnt| Amount::from_sat(amnt.milli_sats())); + + // Let's set a dummy amount to resolve the payment methods accepted. + let fixed_instructions = ix + .set_amount(amount::Amount::ZERO, &resolver) + .await + .map_err(ParseError::InvalidInstructions)?; + + let payment = Payment { + min_amount, + max_amount, + payment_methods: fixed_instructions.methods().into(), + description, + expected_amount: None, + receiving_addr: None, + hrn: hrn.to_string(), + notes: "This is configurable payment instructions. You must send an amount between min_amount and max_amount if set.".to_string() + }; + + Ok(payment) + } + + PaymentInstructions::FixedAmount(ix) => { + let max_amount = ix + .max_amount() + .map(|amnt| Amount::from_sat(amnt.milli_sats())); + + let payment = Payment { + min_amount: None, + max_amount, + payment_methods: ix.methods().into(), + description: ix.recipient_description().map(|s| s.to_string()), + expected_amount: None, + receiving_addr: None, + hrn: hrn.to_string(), + notes: "This is a fixed payment instructions. You must send exactly the amount specified in max_amount.".to_string() + }; + + Ok(payment) + } + } +} diff --git a/src/handlers.rs b/src/handlers.rs index e1e640fe..99a33427 100644 --- a/src/handlers.rs +++ b/src/handlers.rs @@ -12,6 +12,8 @@ use crate::commands::OfflineWalletSubCommand::*; use crate::commands::*; use crate::config::{WalletConfig, WalletConfigInner}; +#[cfg(feature = "dns_payment")] +use crate::dns_payment_instructions::resolve_dns_recipient; use crate::error::BDKCliError as Error; #[cfg(any(feature = "sqlite", feature = "redb"))] use crate::persister::Persister; @@ -21,6 +23,7 @@ use crate::utils::*; #[cfg(feature = "redb")] use bdk_redb::Store as RedbStore; use bdk_wallet::bip39::{Language, Mnemonic}; +use bdk_wallet::bitcoin::ScriptBuf; use bdk_wallet::bitcoin::base64::Engine; use bdk_wallet::bitcoin::base64::prelude::BASE64_STANDARD; use bdk_wallet::bitcoin::{ @@ -120,7 +123,7 @@ const NUMS_UNSPENDABLE_KEY_HEX: &str = /// Execute an offline wallet sub-command /// /// Offline wallet sub-commands are described in [`OfflineWalletSubCommand`]. -pub fn handle_offline_wallet_subcommand( +pub async fn handle_offline_wallet_subcommand( wallet: &mut Wallet, wallet_opts: &WalletOpts, cli_opts: &CliOpts, @@ -534,6 +537,10 @@ pub fn handle_offline_wallet_subcommand( } CreateTx { recipients, + #[cfg(feature = "dns_payment")] + dns_recipients, + #[cfg(feature = "dns_payment")] + dns_resolver, send_all, enable_rbf, offline_signer, @@ -556,10 +563,30 @@ pub fn handle_offline_wallet_subcommand( )); } } else { - let recipients = recipients + #[allow(unused_mut)] + let mut recipients: Vec<(ScriptBuf, Amount)> = recipients .into_iter() .map(|(script, amount)| (script, Amount::from_sat(amount))) .collect(); + + #[cfg(feature = "dns_payment")] + for recipient in dns_recipients { + use crate::dns_payment_instructions::{ + parse_dns_instructions, process_instructions, + }; + let amount = Amount::from_sat(recipient.1); + let (resolver, instructions) = parse_dns_instructions( + &recipient.0, + cli_opts.network, + dns_resolver.clone(), + ) + .await + .map_err(|e| Error::Generic(format!("Parsing error occured {e:#?}")))?; + let payment = process_instructions(amount, &instructions, resolver).await?; + + recipients.push((payment.receiving_addr.unwrap().into(), amount)); + } + tx_builder.set_recipients(recipients); } @@ -1364,6 +1391,20 @@ pub(crate) fn handle_compile_subcommand( } } +#[cfg(feature = "dns_payment")] +pub(crate) async fn handle_resolve_dns_recipient_command( + pretty: bool, + hrn: &str, + resolver: String, + network: Network, +) -> Result { + let resolved = resolve_dns_recipient(hrn, network, resolver) + .await + .map_err(|e| Error::Generic(format!("{:?}", e)))?; + + resolved.display(pretty) +} + /// Handle wallets command to show all saved wallet configurations pub fn handle_wallets_subcommand(datadir: &Path, pretty: bool) -> Result { let load_config = WalletConfig::load(datadir)?; @@ -1605,7 +1646,8 @@ pub(crate) async fn handle_command(cli_opts: CliOpts) -> Result { &wallet_opts, &cli_opts, offline_subcommand.clone(), - )?; + ) + .await?; wallet.persist(&mut persister)?; result }; @@ -1617,7 +1659,8 @@ pub(crate) async fn handle_command(cli_opts: CliOpts) -> Result { &wallet_opts, &cli_opts, offline_subcommand.clone(), - )? + ) + .await? }; Ok(result) } @@ -1743,6 +1786,18 @@ pub(crate) async fn handle_command(cli_opts: CliOpts) -> Result { Ok("".to_string()) } + + #[cfg(feature = "dns_payment")] + CliSubCommand::ResolveDnsRecipient { hrn, resolver } => { + let res = handle_resolve_dns_recipient_command( + cli_opts.pretty, + &hrn, + resolver, + cli_opts.network, + ) + .await?; + Ok(res) + } }; result } @@ -1783,6 +1838,7 @@ async fn respond( } => { let value = handle_offline_wallet_subcommand(wallet, wallet_opts, cli_opts, offline_subcommand) + .await .map_err(|e| e.to_string())?; Some(value) } diff --git a/src/main.rs b/src/main.rs index 90d701b0..6b7745c1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,6 +25,9 @@ mod payjoin; mod persister; mod utils; +#[cfg(feature = "dns_payment")] +mod dns_payment_instructions; + use bdk_wallet::bitcoin::Network; use log::{debug, error, warn}; diff --git a/src/utils.rs b/src/utils.rs index 7d357e81..514b22f2 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -96,6 +96,17 @@ pub(crate) fn parse_sp_code_value_pairs(s: &str) -> Result<(SilentPaymentCode, u Ok((key, value)) } +#[cfg(feature = "dns_payment")] +/// Parse dns recipients in the form "test@me.com:10000" from cli input +pub(crate) fn parse_dns_recipient(s: &str) -> Result<(String, u64), String> { + let parts: Vec<_> = s.split(':').collect(); + if parts.len() != 2 { + return Err("Invalid format".to_string()); + } + let sending_amount = u64::from_str(parts[1]).map_err(|e| e.to_string())?; + Ok((parts[0].to_string(), sending_amount)) +} + #[cfg(any(feature = "electrum", feature = "esplora", feature = "rpc"))] /// Parse the proxy (Socket:Port) argument from the cli input. pub(crate) fn parse_proxy_auth(s: &str) -> Result<(String, String), Error> { From 44404373c737187448acab2f92945c964333add1 Mon Sep 17 00:00:00 2001 From: Sonkeng Maldini Date: Mon, 25 May 2026 18:37:28 +0100 Subject: [PATCH 2/4] discard pretty flag and apply reviews --- src/commands.rs | 2 +- src/dns_payment_instructions.rs | 169 ++++++++------------------------ src/handlers.rs | 34 +++---- 3 files changed, 55 insertions(+), 150 deletions(-) diff --git a/src/commands.rs b/src/commands.rs index 2db5276c..a0d0dd51 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -389,7 +389,7 @@ pub enum OfflineWalletSubCommand { dns_recipients: Vec<(String, u64)>, #[cfg(feature = "dns_payment")] /// Custom resolver DNS IP to be used for resolution. - #[arg(long = "dns_resolver", default_value = "8.8.8.8:53")] + #[arg(long = "dns_resolver", default_value = "8.8.8.8")] dns_resolver: String, /// Sends all the funds (or all the selected utxos). Requires only one recipient with value 0. #[arg(long = "send_all", short = 'a')] diff --git a/src/dns_payment_instructions.rs b/src/dns_payment_instructions.rs index 88453d7e..6dd13eed 100644 --- a/src/dns_payment_instructions.rs +++ b/src/dns_payment_instructions.rs @@ -3,115 +3,58 @@ use bitcoin_payment_instructions::{ FixedAmountPaymentInstructions, ParseError, PaymentInstructions, PaymentMethod, PaymentMethodType, amount, dns_resolver::DNSHrnResolver, }; -use cli_table::{Cell, Style, Table, format::Justify}; use core::{net::SocketAddr, str::FromStr}; use crate::{error::BDKCliError as Error, utils::shorten}; #[derive(Debug)] -pub struct Payment { +pub struct ResolvedPaymentInfo { + pub hrn: String, pub payment_methods: Vec, + pub description: Option, pub min_amount: Option, pub max_amount: Option, - pub description: Option, - pub expected_amount: Option, - pub receiving_addr: Option
, - pub hrn: String, pub notes: String, } -impl Payment { - pub fn display(&self, pretty: bool) -> Result { - let mut methods: Vec = Vec::new(); - self.payment_methods.iter().for_each(|pm| match pm { - bitcoin_payment_instructions::PaymentMethod::LightningBolt11(bolt11) => { - methods.push(format!("Bolt 11 invoice ({})", shorten(bolt11, 20, 15))) - } - bitcoin_payment_instructions::PaymentMethod::LightningBolt12(offer) => { - methods.push(format!("Bolt 12 invoice ({})", shorten(offer, 20, 15))) - } - bitcoin_payment_instructions::PaymentMethod::OnChain(address) => { - methods.push(format!("On chain ({})", address)) - } - bitcoin_payment_instructions::PaymentMethod::Cashu(csh) => { - methods.push(format!("Cashu payment ({})", shorten(csh, 20, 15))) - } - }); - - if pretty { - let mut table = vec![vec![ - "HRN".cell().bold(true), - self.hrn.to_string().cell().justify(Justify::Right), - ]]; - - if let Some(min_amnt) = self.min_amount { - table.push(vec![ - "Min amount".cell().bold(true), - min_amnt.to_string().cell().justify(Justify::Right), - ]); - } - - if let Some(max_amnt) = self.max_amount { - table.push(vec![ - "Max amount".cell().bold(true), - max_amnt.to_string().cell().justify(Justify::Right), - ]); - } - - if let Some(send_amnt) = self.expected_amount { - table.push(vec![ - "Expected Amount to send".cell().bold(true), - send_amnt.to_string().cell().justify(Justify::Right), - ]); - } - - if let Some(descr) = &self.description { - table.push(vec![ - "Description".cell().bold(true), - descr.cell().justify(Justify::Right), - ]); - } - - table.push(vec![ - "Accepted methods".cell().bold(true), - methods.join(", ").cell().justify(Justify::Right), - ]); - table.push(vec![ - "Notes".cell().bold(true), - self.notes.clone().cell().justify(Justify::Right), - ]); - - let table = table - .table() - .display() - .map_err(|e| Error::Generic(e.to_string()))?; - - Ok(format!("{table}")) - } else { - Ok(serde_json::to_string_pretty(&serde_json::json!({ - "hrn": self.hrn, - "payment_methods": methods, - "description": self.description, - "min_amount": self.min_amount, - "max_amount": self.max_amount, - "expected_amount_to_send": self.expected_amount, - "notes": self.notes - }))?) - } +impl ResolvedPaymentInfo { + pub fn display(&self) -> Result { + let methods: Vec = self + .payment_methods + .iter() + .map(|pm| match pm { + PaymentMethod::LightningBolt11(bolt11) => { + format!("Bolt 11 invoice ({})", shorten(bolt11, 20, 15)) + } + PaymentMethod::LightningBolt12(offer) => format!("Bolt 12 invoice ({})", offer), + PaymentMethod::OnChain(address) => format!("On chain ({})", address), + PaymentMethod::Cashu(csh) => format!("Cashu payment ({})", csh), + }) + .collect(); + + Ok(serde_json::to_string_pretty(&serde_json::json!({ + "hrn": self.hrn, + "payment_methods": methods, + "description": self.description, + "min_amount": self.min_amount, + "max_amount": self.max_amount, + "notes": self.notes + }))?) } } + pub(crate) async fn parse_dns_instructions( hrn: &str, network: Network, - resolver_ip: String, + dns_resolver: &str, ) -> Result<(DNSHrnResolver, PaymentInstructions), ParseError> { - let ip_address = if resolver_ip.contains(':') { - resolver_ip + let ip_address = if dns_resolver.contains(':') { + dns_resolver } else { - format!("{resolver_ip}:53") + &format!("{dns_resolver}:53") }; - let sock_addr = SocketAddr::from_str(&ip_address).map_err(|_| { + let sock_addr = SocketAddr::from_str(ip_address).map_err(|_| { ParseError::HrnResolutionError("Unable to create socket from provided address") })?; let resolver = DNSHrnResolver(sock_addr); @@ -148,7 +91,7 @@ pub async fn process_instructions( amount_to_send: Amount, payment_instructions: &PaymentInstructions, resolver: DNSHrnResolver, -) -> Result { +) -> Result<(Address, Amount), Error> { match payment_instructions { PaymentInstructions::ConfigurableAmount(instructions) => { // Look for on chain payment method as it's the only one we can support @@ -200,34 +143,10 @@ pub async fn process_instructions( let onchain_details = get_onchain_info(&fixed_instructions)?; - Ok(Payment { - payment_methods: vec![PaymentMethod::OnChain(onchain_details.clone().0)], - min_amount, - max_amount, - description: instructions.recipient_description().map(|s| s.to_string()), - expected_amount: Some(onchain_details.1), - receiving_addr: Some(onchain_details.0.clone()), - hrn: instructions.human_readable_name().unwrap().to_string(), - notes: "".to_string(), - }) + Ok((onchain_details.0.clone(), onchain_details.1)) } - PaymentInstructions::FixedAmount(instructions) => { - let onchain_info = get_onchain_info(instructions)?; - - Ok(Payment { - payment_methods: vec![PaymentMethod::OnChain(onchain_info.clone().0)], - min_amount: None, - max_amount: instructions - .max_amount() - .map(|amnt| Amount::from_sat(amnt.milli_sats())), - description: instructions.recipient_description().map(|s| s.to_string()), - expected_amount: Some(onchain_info.1), - receiving_addr: Some(onchain_info.0), - notes: "".to_string(), - hrn: instructions.human_readable_name().unwrap().to_string(), - }) - } + PaymentInstructions::FixedAmount(instructions) => Ok(get_onchain_info(instructions)?), } } @@ -235,9 +154,9 @@ pub async fn process_instructions( pub async fn resolve_dns_recipient( hrn: &str, network: Network, - ip: String, -) -> Result { - let (resolver, instructions) = parse_dns_instructions(hrn, network, ip).await?; + dns_resolver: &str, +) -> Result { + let (resolver, instructions) = parse_dns_instructions(hrn, network, dns_resolver).await?; match instructions { PaymentInstructions::ConfigurableAmount(ix) => { @@ -251,15 +170,13 @@ pub async fn resolve_dns_recipient( .await .map_err(ParseError::InvalidInstructions)?; - let payment = Payment { + let payment = ResolvedPaymentInfo { min_amount, max_amount, payment_methods: fixed_instructions.methods().into(), description, - expected_amount: None, - receiving_addr: None, hrn: hrn.to_string(), - notes: "This is configurable payment instructions. You must send an amount between min_amount and max_amount if set.".to_string() + notes: "This is configurable payment instructions. You must send an amount between min_amount and max_amount if set.".to_string(), }; Ok(payment) @@ -270,15 +187,13 @@ pub async fn resolve_dns_recipient( .max_amount() .map(|amnt| Amount::from_sat(amnt.milli_sats())); - let payment = Payment { + let payment = ResolvedPaymentInfo { min_amount: None, max_amount, payment_methods: ix.methods().into(), description: ix.recipient_description().map(|s| s.to_string()), - expected_amount: None, - receiving_addr: None, hrn: hrn.to_string(), - notes: "This is a fixed payment instructions. You must send exactly the amount specified in max_amount.".to_string() + notes: "This is a fixed payment instructions. You must send exactly the amount specified in max_amount.".to_string(), }; Ok(payment) diff --git a/src/handlers.rs b/src/handlers.rs index 99a33427..7a42fb2a 100644 --- a/src/handlers.rs +++ b/src/handlers.rs @@ -13,7 +13,9 @@ use crate::commands::OfflineWalletSubCommand::*; use crate::commands::*; use crate::config::{WalletConfig, WalletConfigInner}; #[cfg(feature = "dns_payment")] -use crate::dns_payment_instructions::resolve_dns_recipient; +use crate::dns_payment_instructions::{ + parse_dns_instructions, process_instructions, resolve_dns_recipient, +}; use crate::error::BDKCliError as Error; #[cfg(any(feature = "sqlite", feature = "redb"))] use crate::persister::Persister; @@ -571,20 +573,14 @@ pub async fn handle_offline_wallet_subcommand( #[cfg(feature = "dns_payment")] for recipient in dns_recipients { - use crate::dns_payment_instructions::{ - parse_dns_instructions, process_instructions, - }; let amount = Amount::from_sat(recipient.1); - let (resolver, instructions) = parse_dns_instructions( - &recipient.0, - cli_opts.network, - dns_resolver.clone(), - ) - .await - .map_err(|e| Error::Generic(format!("Parsing error occured {e:#?}")))?; + let (resolver, instructions) = + parse_dns_instructions(&recipient.0, cli_opts.network, &dns_resolver) + .await + .map_err(|e| Error::Generic(format!("Parsing error occured {e:#?}")))?; let payment = process_instructions(amount, &instructions, resolver).await?; - recipients.push((payment.receiving_addr.unwrap().into(), amount)); + recipients.push((payment.0.into(), payment.1)); } tx_builder.set_recipients(recipients); @@ -1393,16 +1389,15 @@ pub(crate) fn handle_compile_subcommand( #[cfg(feature = "dns_payment")] pub(crate) async fn handle_resolve_dns_recipient_command( - pretty: bool, hrn: &str, - resolver: String, + resolver: &str, network: Network, ) -> Result { let resolved = resolve_dns_recipient(hrn, network, resolver) .await .map_err(|e| Error::Generic(format!("{:?}", e)))?; - resolved.display(pretty) + resolved.display() } /// Handle wallets command to show all saved wallet configurations @@ -1789,13 +1784,8 @@ pub(crate) async fn handle_command(cli_opts: CliOpts) -> Result { #[cfg(feature = "dns_payment")] CliSubCommand::ResolveDnsRecipient { hrn, resolver } => { - let res = handle_resolve_dns_recipient_command( - cli_opts.pretty, - &hrn, - resolver, - cli_opts.network, - ) - .await?; + let res = + handle_resolve_dns_recipient_command(&hrn, &resolver, cli_opts.network).await?; Ok(res) } }; From 76dba4acc1c9ea5353b5c60a5b90c11c2998f576 Mon Sep 17 00:00:00 2001 From: Sonkeng Maldini Date: Tue, 26 May 2026 12:14:17 +0100 Subject: [PATCH 3/4] fix: add log when resolving --- src/commands.rs | 1 - src/handlers.rs | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/commands.rs b/src/commands.rs index a0d0dd51..21a7eaae 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -16,7 +16,6 @@ #[cfg(feature = "silent-payments")] use {crate::utils::parse_sp_code_value_pairs, bdk_sp::encoding::SilentPaymentCode}; - use bdk_wallet::bitcoin::{ Address, Network, OutPoint, ScriptBuf, bip32::{DerivationPath, Xpriv}, diff --git a/src/handlers.rs b/src/handlers.rs index 7a42fb2a..b8b157d1 100644 --- a/src/handlers.rs +++ b/src/handlers.rs @@ -25,7 +25,6 @@ use crate::utils::*; #[cfg(feature = "redb")] use bdk_redb::Store as RedbStore; use bdk_wallet::bip39::{Language, Mnemonic}; -use bdk_wallet::bitcoin::ScriptBuf; use bdk_wallet::bitcoin::base64::Engine; use bdk_wallet::bitcoin::base64::prelude::BASE64_STANDARD; use bdk_wallet::bitcoin::{ @@ -566,13 +565,14 @@ pub async fn handle_offline_wallet_subcommand( } } else { #[allow(unused_mut)] - let mut recipients: Vec<(ScriptBuf, Amount)> = recipients + let mut recipients: Vec<_> = recipients .into_iter() .map(|(script, amount)| (script, Amount::from_sat(amount))) .collect(); #[cfg(feature = "dns_payment")] for recipient in dns_recipients { + println!("Resolving DNS instructions for recipient {}", recipient.0); let amount = Amount::from_sat(recipient.1); let (resolver, instructions) = parse_dns_instructions(&recipient.0, cli_opts.network, &dns_resolver) From 5c496b130d917d483da7a792c0035f56ebca393e Mon Sep 17 00:00:00 2001 From: Sonkeng Maldini Date: Wed, 17 Jun 2026 17:53:17 +0100 Subject: [PATCH 4/4] fix: unifying recipients before send --- Cargo.lock | 341 ++++++++++++++++---------------- src/commands.rs | 2 +- src/dns_payment_instructions.rs | 16 +- src/handlers.rs | 39 ++-- 4 files changed, 208 insertions(+), 190 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2f84fb4f..f7563486 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -150,9 +150,9 @@ checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" [[package]] name = "aws-lc-rs" -version = "1.17.0" +version = "1.16.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ec2f1fc3ec205783a5da9a7e6c1509cc69dedf09a1949e412c1e18469326d00" +checksum = "a054912289d18629dc78375ba2c3726a3afe3ff71b4edba9dedfca0e3446d1fc" dependencies = [ "aws-lc-sys", "zeroize", @@ -160,9 +160,9 @@ dependencies = [ [[package]] name = "aws-lc-sys" -version = "0.41.0" +version = "0.39.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a2f9779ce85b93ab6170dd940ad0169b5766ff848247aff13bb788b832fe3f4" +checksum = "83a25cf98105baa966497416dbd42565ce3a8cf8dbfd59803ec9ad46f3126399" dependencies = [ "cc", "cmake", @@ -219,14 +219,14 @@ dependencies = [ "env_logger", "log", "payjoin", - "reqwest 0.13.4", + "reqwest 0.13.2", "serde", "serde_json", "shlex", "tap", "thiserror 2.0.18", "tokio", - "toml 1.1.2+spec-1.1.0", + "toml 1.1.1+spec-1.1.0", "tracing", "tracing-subscriber", "url", @@ -381,7 +381,7 @@ dependencies = [ "bitcoin", "bitcoin_hashes 0.15.0", "chacha20-poly1305", - "rand 0.8.6", + "rand 0.8.5", "tokio", ] @@ -398,9 +398,9 @@ dependencies = [ [[package]] name = "bitcoin" -version = "0.32.9" +version = "0.32.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cf93e61f2dbc3e3c41234ca26a65e2c0b0975c52e0f069ab9893ebbede584d3" +checksum = "1e499f9fc0407f50fe98af744ab44fa67d409f76b6772e1689ec8485eb0c0f66" dependencies = [ "base58ck", "base64 0.21.7", @@ -488,7 +488,7 @@ dependencies = [ "hkdf 0.11.0", "lazy_static", "log", - "rand 0.8.6", + "rand 0.8.5", "serde", "serde_derive", "sha2 0.9.9", @@ -511,9 +511,9 @@ dependencies = [ [[package]] name = "bitcoin-units" -version = "0.1.3" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "346568ebaab2918487cea76dd55dae13c27bb618cdb737c952e69eb2017c4118" +checksum = "5285c8bcaa25876d07f37e3d30c303f2609179716e11d688f51e8f1fe70063e2" dependencies = [ "bitcoin-internals 0.3.0", "serde", @@ -576,9 +576,9 @@ dependencies = [ [[package]] name = "bitflags" -version = "2.11.1" +version = "2.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4512299f36f043ab09a583e57bceb5a5aab7a73db1805848e8fef3c9e8c78b3" +checksum = "843867be96c8daad0d758b57df9392b6d8d271134fce549de6ce169ff98a92af" [[package]] name = "block-buffer" @@ -600,9 +600,9 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.20.3" +version = "3.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72f5acc6cb2ba439de613abc23857ec3d78374d8ed5ac84e9d11336e87da8649" +checksum = "5d20789868f4b01b2f2caec9f5c4e0213b41e3e5702a50157d699ae31ced2fcb" [[package]] name = "byteorder" @@ -618,9 +618,9 @@ checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33" [[package]] name = "cc" -version = "1.2.62" +version = "1.2.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1dce859f0832a7d088c4f1119888ab94ef4b5d6795d1ce05afb7fe159d79f98" +checksum = "e1e928d4b69e3077709075a938a05ffbedfa53a84c8f766efbf8220bb1ff60e1" dependencies = [ "find-msvc-tools", "jobserver", @@ -750,9 +750,9 @@ checksum = "bba18ee93d577a8428902687bcc2b6b45a56b1981a1f6d779731c86cc4c5db18" [[package]] name = "clap" -version = "4.6.1" +version = "4.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ddb117e43bbf7dacf0a4190fef4d345b9bad68dfc649cb349e7d17d28428e51" +checksum = "b193af5b67834b676abd72466a96c1024e6a6ad978a1f484bd90b85c94041351" dependencies = [ "clap_builder", "clap_derive", @@ -772,18 +772,18 @@ dependencies = [ [[package]] name = "clap_complete" -version = "4.6.5" +version = "4.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0a7a9bfdb35811f9e59832f0f05975114d2251b415fb534108e6f34060fd772" +checksum = "19c9f1dde76b736e3681f28cec9d5a61299cbaae0fce80a68e43724ad56031eb" dependencies = [ "clap", ] [[package]] name = "clap_derive" -version = "4.6.1" +version = "4.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2ce8604710f6733aa641a2b3731eaa1e8b3d9973d5e3565da11800813f997a9" +checksum = "1110bd8a634a1ab8cb04345d8d878267d57c3cf1b38d91b71af6686408bbca6a" dependencies = [ "heck", "proc-macro2", @@ -1004,7 +1004,7 @@ dependencies = [ "byteorder", "libc", "log", - "rustls 0.23.40", + "rustls 0.23.37", "serde", "serde_json", "webpki-roots 0.25.4", @@ -1080,9 +1080,9 @@ checksum = "7360491ce676a36bf9bb3c56c1aa791658183a54d2744120f27285738d90465a" [[package]] name = "fastrand" -version = "2.4.1" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f1f227452a390804cdb637b74a86990f2a7d7ba4b7d5693aac9b4dd6defd8d6" +checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" [[package]] name = "find-msvc-tools" @@ -1312,9 +1312,9 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.17.1" +version = "0.16.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a" +checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100" [[package]] name = "hashlink" @@ -1460,18 +1460,19 @@ dependencies = [ [[package]] name = "hyper-rustls" -version = "0.27.9" +version = "0.27.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33ca68d021ef39cf6463ab54c1d0f5daf03377b70561305bb89a8f83aab66e0f" +checksum = "e3c93eb611681b207e1fe55d5a71ecf91572ec8a6705cdb6857f7d8d5242cf58" dependencies = [ "http", "hyper", "hyper-util", - "rustls 0.23.40", + "rustls 0.23.37", + "rustls-pki-types", "tokio", "tokio-rustls", "tower-service", - "webpki-roots 1.0.7", + "webpki-roots 1.0.6", ] [[package]] @@ -1515,13 +1516,12 @@ dependencies = [ [[package]] name = "icu_collections" -version = "2.2.0" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2984d1cd16c883d7935b9e07e44071dca8d917fd52ecc02c04d5fa0b5a3f191c" +checksum = "4c6b649701667bbe825c3b7e6388cb521c23d88644678e83c0c4d0a621a34b43" dependencies = [ "displaydoc", "potential_utf", - "utf8_iter", "yoke", "zerofrom", "zerovec", @@ -1529,9 +1529,9 @@ dependencies = [ [[package]] name = "icu_locale_core" -version = "2.2.0" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92219b62b3e2b4d88ac5119f8904c10f8f61bf7e95b640d25ba3075e6cac2c29" +checksum = "edba7861004dd3714265b4db54a3c390e880ab658fec5f7db895fae2046b5bb6" dependencies = [ "displaydoc", "litemap", @@ -1542,9 +1542,9 @@ dependencies = [ [[package]] name = "icu_normalizer" -version = "2.2.0" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c56e5ee99d6e3d33bd91c5d85458b6005a22140021cc324cea84dd0e72cff3b4" +checksum = "5f6c8828b67bf8908d82127b2054ea1b4427ff0230ee9141c54251934ab1b599" dependencies = [ "icu_collections", "icu_normalizer_data", @@ -1556,15 +1556,15 @@ dependencies = [ [[package]] name = "icu_normalizer_data" -version = "2.2.0" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da3be0ae77ea334f4da67c12f149704f19f81d1adf7c51cf482943e84a2bad38" +checksum = "7aedcccd01fc5fe81e6b489c15b247b8b0690feb23304303a9e560f37efc560a" [[package]] name = "icu_properties" -version = "2.2.0" +version = "2.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bee3b67d0ea5c2cca5003417989af8996f8604e34fb9ddf96208a033901e70de" +checksum = "020bfc02fe870ec3a66d93e677ccca0562506e5872c650f893269e08615d74ec" dependencies = [ "icu_collections", "icu_locale_core", @@ -1576,15 +1576,15 @@ dependencies = [ [[package]] name = "icu_properties_data" -version = "2.2.0" +version = "2.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e2bbb201e0c04f7b4b3e14382af113e17ba4f63e2c9d2ee626b720cbce54a14" +checksum = "616c294cf8d725c6afcd8f55abc17c56464ef6211f9ed59cccffe534129c77af" [[package]] name = "icu_provider" -version = "2.2.0" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "139c4cf31c8b5f33d7e199446eff9c1e02decfc2f0eec2c8d71f65befa45b421" +checksum = "85962cf0ce02e1e0a629cc34e7ca3e373ce20dda4c4d7294bbd0bf1fdb59e614" dependencies = [ "displaydoc", "icu_locale_core", @@ -1614,9 +1614,9 @@ dependencies = [ [[package]] name = "idna_adapter" -version = "1.2.2" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb68373c0d6620ef8105e855e7745e18b0d00d3bdb07fb532e434244cdb9a714" +checksum = "3acae9609540aa318d1bc588455225fb2085b9ed0c4f6bd0d9d5bcd86f1a0344" dependencies = [ "icu_normalizer", "icu_properties", @@ -1624,12 +1624,12 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.14.0" +version = "2.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9" +checksum = "7714e70437a7dc3ac8eb7e6f8df75fd8eb422675fc7678aff7364301092b1017" dependencies = [ "equivalent", - "hashbrown 0.17.1", + "hashbrown 0.16.1", "serde", "serde_core", ] @@ -1649,6 +1649,16 @@ version = "2.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d98f6fed1fde3f8c21bc40a1abb88dd75e67924f9cffc3ef95607bad8017f8e2" +[[package]] +name = "iri-string" +version = "0.7.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25e659a4bb38e810ebc252e53b5814ff908a8c58c2a9ce2fae1bbec24cbf4e20" +dependencies = [ + "memchr", + "serde", +] + [[package]] name = "is_terminal_polyfill" version = "1.70.2" @@ -1663,9 +1673,9 @@ checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" [[package]] name = "jiff" -version = "0.2.25" +version = "0.2.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6835eea34fb6321b9b3aa7b685c2b433948c09447e389dc017fdf687d5d11e65" +checksum = "1a3546dc96b6d42c5f24902af9e2538e82e39ad350b0c766eb3fbf2d8f3d8359" dependencies = [ "jiff-static", "log", @@ -1676,9 +1686,9 @@ dependencies = [ [[package]] name = "jiff-static" -version = "0.2.25" +version = "0.2.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c22e04db9c58f5136eb1757f3d5c49a7b187f49e52185228cbd2f5acdfcc08c" +checksum = "2a8c8b344124222efd714b73bb41f8b5120b27a7cc1c75593a6ff768d9d05aa4" dependencies = [ "proc-macro2", "quote", @@ -1697,9 +1707,9 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.99" +version = "0.3.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "142bc4740e452c1e57ade0cbc129f139c9093e354346f0872ef985f4f5cf5f11" +checksum = "797146bb2677299a1eb6b7b50a890f4c361b29ef967addf5b2fa45dae1bb6d7d" dependencies = [ "cfg-if", "futures-util", @@ -1733,9 +1743,9 @@ checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2" [[package]] name = "libc" -version = "0.2.186" +version = "0.2.183" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68ab91017fe16c622486840e4c83c9a37afeff978bd239b5293d61ece587de66" +checksum = "b5b646652bf6661599e1da8901b3b9522896f01e736bad5f723fe7a3a27f899d" [[package]] name = "libm" @@ -1745,9 +1755,9 @@ checksum = "b6d2cec3eae94f9f509c767b45932f1ada8350c4bdb85af2fcab4a3c14807981" [[package]] name = "libredox" -version = "0.1.16" +version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e02f3bb43d335493c96bf3fd3a321600bf6bd07ed34bc64118e9293bdffea46c" +checksum = "7ddbf48fd451246b1f8c2610bd3b4ac0cc6e149d89832867093ab69a17194f08" dependencies = [ "libc", ] @@ -1765,9 +1775,9 @@ dependencies = [ [[package]] name = "lightning" -version = "0.2.2" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c90397b635e3ece6b9a723fb470a46cb9b3592f217d72e40540a5fada00289d" +checksum = "63a1ab99a13ab3343a9b4d1d25c455bf72322819fc5a5f05c5182e704528a583" dependencies = [ "bech32", "bitcoin", @@ -1782,9 +1792,9 @@ dependencies = [ [[package]] name = "lightning-invoice" -version = "0.34.0" +version = "0.34.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b85e5e14bcdb30d746e9785b04f27938292e8944f78f26517e01e91691f6b3f2" +checksum = "47d83bd798e04ab9eecc8bbef1fa17d3808859bcdc0406bd16c55d51c8834444" dependencies = [ "bech32", "bitcoin", @@ -1804,9 +1814,9 @@ dependencies = [ [[package]] name = "lightning-types" -version = "0.3.1" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb1aac93f22f2c2eac8a0ee83bb1a1ea58673caa2c82847302710b83364d04e6" +checksum = "c211dfcff95ca308247da8b1e0e81604bc9e568239967cd2c34572558511e869" dependencies = [ "bitcoin", ] @@ -1819,9 +1829,9 @@ checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53" [[package]] name = "litemap" -version = "0.8.2" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92daf443525c4cce67b150400bc2316076100ce0b3686209eb8cf3c31612e6f0" +checksum = "6373607a59f0be73a39b6fe456b8192fcc3585f602af20751600e974dd455e77" [[package]] name = "lock_api" @@ -1834,9 +1844,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.30" +version = "0.4.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "616ec5685824bcc94416c6d4a7a446eea774a31efd7062c8480ba6fd06d7a6e5" +checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897" [[package]] name = "lru-slab" @@ -1852,9 +1862,9 @@ checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79" [[package]] name = "miniscript" -version = "12.3.6" +version = "12.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c14116d8342edd3626b0f8e84df16f4e6a76dc04799ba747493403236a1b8ac5" +checksum = "487906208f38448e186e3deb02f2b8ef046a9078b0de00bdb28bf4fb9b76951c" dependencies = [ "bech32", "bitcoin", @@ -1932,14 +1942,15 @@ checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" [[package]] name = "openssl" -version = "0.10.80" +version = "0.10.76" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a45fa2aa886c42762255da344f0a0d313e254066c46aad76f300c3d3da62d967" +checksum = "951c002c75e16ea2c65b8c7e4d3d51d5530d8dfa7d060b4776828c88cfb18ecf" dependencies = [ "bitflags", "cfg-if", "foreign-types", "libc", + "once_cell", "openssl-macros", "openssl-sys", ] @@ -1963,9 +1974,9 @@ checksum = "7c87def4c32ab89d880effc9e097653c8da5d6ef28e6b539d313baaacfbafcbe" [[package]] name = "openssl-sys" -version = "0.9.116" +version = "0.9.112" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f28a22dc7140cda5f096e5e7724a6962ca81a7f8bfd2979f9b18c11af56318c4" +checksum = "57d55af3b3e226502be1526dfdba67ab0e9c96fc293004e79576b2b9edb0dbdb" dependencies = [ "cc", "libc", @@ -2041,9 +2052,9 @@ checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" [[package]] name = "pkg-config" -version = "0.3.33" +version = "0.3.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19f132c84eca552bf34cab8ec81f1c1dcc229b811638f9d283dceabe58c5569e" +checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" [[package]] name = "poly1305" @@ -2087,27 +2098,27 @@ checksum = "c33a9471896f1c69cecef8d20cbe2f7accd12527ce60845ff44c153bb2a21b49" [[package]] name = "portable-atomic-util" -version = "0.2.7" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2a106d1259c23fac8e543272398ae0e3c0b8d33c88ed73d0cc71b0f1d902618" +checksum = "091397be61a01d4be58e7841595bd4bfedb15f1cd54977d79b8271e94ed799a3" dependencies = [ "portable-atomic", ] [[package]] name = "possiblyrandom" -version = "0.2.0" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b122a615d72104fb3d8b26523fdf9232cd8ee06949fb37e4ce3ff964d15dffd" +checksum = "9c564dbf654befd49035528299f1208a40508f6e07efb11c163444e304e4484f" dependencies = [ "getrandom 0.2.17", ] [[package]] name = "potential_utf" -version = "0.1.5" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0103b1cef7ec0cf76490e969665504990193874ea05c85ff9bab8b911d0a0564" +checksum = "b73949432f5e2a09657003c25bca5e19a0e9c84f8058ca374f49e0ebe605af77" dependencies = [ "zerovec", ] @@ -2152,7 +2163,7 @@ dependencies = [ "quinn-proto", "quinn-udp", "rustc-hash", - "rustls 0.23.40", + "rustls 0.23.37", "socket2", "thiserror 2.0.18", "tokio", @@ -2169,10 +2180,10 @@ dependencies = [ "bytes", "getrandom 0.3.4", "lru-slab", - "rand 0.9.4", + "rand 0.9.3", "ring", "rustc-hash", - "rustls 0.23.40", + "rustls 0.23.37", "rustls-pki-types", "slab", "thiserror 2.0.18", @@ -2218,9 +2229,9 @@ checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" [[package]] name = "rand" -version = "0.8.6" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ca0ecfa931c29007047d1bc58e623ab12e5590e8c7cc53200d5202b69266d8a" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ "libc", "rand_chacha 0.3.1", @@ -2229,9 +2240,9 @@ dependencies = [ [[package]] name = "rand" -version = "0.9.4" +version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44c5af06bb1b7d3216d91932aed5265164bf384dc89cd6ba05cf59a35f5f76ea" +checksum = "7ec095654a25171c2124e9e3393a930bddbffdc939556c914957a4c3e0a87166" dependencies = [ "rand_chacha 0.9.0", "rand_core 0.9.5", @@ -2355,7 +2366,7 @@ dependencies = [ "percent-encoding", "pin-project-lite", "quinn", - "rustls 0.23.40", + "rustls 0.23.37", "rustls-pki-types", "serde", "serde_json", @@ -2371,14 +2382,14 @@ dependencies = [ "wasm-bindgen", "wasm-bindgen-futures", "web-sys", - "webpki-roots 1.0.7", + "webpki-roots 1.0.6", ] [[package]] name = "reqwest" -version = "0.13.4" +version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "219c5811de6525e5416c7d5d53bb656d3afdbc6c5af816e0802bcfa42dbdc1c3" +checksum = "ab3f43e3283ab1488b624b44b0e988d0acea0b3214e694730a055cb6b2efa801" dependencies = [ "base64 0.22.1", "bytes", @@ -2464,25 +2475,25 @@ dependencies = [ [[package]] name = "rustls" -version = "0.23.40" +version = "0.23.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef86cd5876211988985292b91c96a8f2d298df24e75989a43a3c73f2d4d8168b" +checksum = "758025cb5fccfd3bc2fd74708fd4682be41d99e5dff73c377c0646c6012c73a4" dependencies = [ "aws-lc-rs", "log", "once_cell", "ring", "rustls-pki-types", - "rustls-webpki 0.103.13", + "rustls-webpki 0.103.10", "subtle", "zeroize", ] [[package]] name = "rustls-pki-types" -version = "1.14.1" +version = "1.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30a7197ae7eb376e574fe940d068c30fe0462554a3ddbe4eca7838e049c937a9" +checksum = "be040f8b0a225e40375822a563fa9524378b9d63112f53e19ffff34df5d33fdd" dependencies = [ "web-time", "zeroize", @@ -2500,9 +2511,9 @@ dependencies = [ [[package]] name = "rustls-webpki" -version = "0.103.13" +version = "0.103.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61c429a8649f110dddef65e2a5ad240f747e85f7758a6bccc7e5777bd33f756e" +checksum = "df33b2b81ac578cabaf06b89b0631153a3f416b0a886e8a7a1707fb51abbd1ef" dependencies = [ "aws-lc-rs", "ring", @@ -2554,7 +2565,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9465315bc9d4566e1724f0fffcbcc446268cb522e60f9a27bcded6b19c108113" dependencies = [ "bitcoin_hashes 0.14.1", - "rand 0.8.6", + "rand 0.8.5", "secp256k1-sys", "serde", ] @@ -2593,9 +2604,9 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.28" +version = "1.0.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd" +checksum = "d767eb0aabc880b29956c35734170f26ed551a859dbd361d140cdbeca61ab1e2" [[package]] name = "serde" @@ -2629,9 +2640,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.150" +version = "1.0.149" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8014e44b4736ed0538adeecded0fce2a272f22dc9578a7eb6b2d9993c74cfb9" +checksum = "83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86" dependencies = [ "itoa", "memchr", @@ -2860,9 +2871,9 @@ dependencies = [ [[package]] name = "tinystr" -version = "0.8.3" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8323304221c2a851516f22236c5722a72eaa19749016521d6dff0824447d96d" +checksum = "42d3e9c45c09de15d06dd8acf5f4e0e399e85927b7f00711024eb7ae10fa4869" dependencies = [ "displaydoc", "zerovec", @@ -2885,9 +2896,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.52.3" +version = "1.50.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fc7f01b389ac15039e4dc9531aa973a135d7a4135281b12d7c1bc79fd57fffe" +checksum = "27ad5e34374e03cfffefc301becb44e9dc3c17584f414349ebe29ed26661822d" dependencies = [ "bytes", "libc", @@ -2902,9 +2913,9 @@ dependencies = [ [[package]] name = "tokio-macros" -version = "2.7.0" +version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "385a6cb71ab9ab790c5fe8d67f1645e6c450a7ce006a33de03daa956cf70a496" +checksum = "5c55a2eff8b69ce66c84f85e1da1c233edc36ceb85a2058d11b0d6a3c7e7569c" dependencies = [ "proc-macro2", "quote", @@ -2927,7 +2938,7 @@ version = "0.26.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1729aa945f29d91ba541258c8df89027d5792d85a8841fb65e8bf0f4ede4ef61" dependencies = [ - "rustls 0.23.40", + "rustls 0.23.37", "tokio", ] @@ -2942,9 +2953,9 @@ dependencies = [ [[package]] name = "toml" -version = "1.1.2+spec-1.1.0" +version = "1.1.1+spec-1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81f3d15e84cbcd896376e6730314d59fb5a87f31e4b038454184435cd57defee" +checksum = "994b95d9e7bae62b34bab0e2a4510b801fa466066a6a8b2b57361fa1eba068ee" dependencies = [ "indexmap", "serde_core", @@ -2966,9 +2977,9 @@ dependencies = [ [[package]] name = "toml_parser" -version = "1.1.2+spec-1.1.0" +version = "1.1.1+spec-1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2abe9b86193656635d2411dc43050282ca48aa31c2451210f4202550afb7526" +checksum = "39ca317ebc49f06bd748bfba29533eac9485569dc9bf80b849024b025e814fb9" dependencies = [ "winnow", ] @@ -2996,20 +3007,20 @@ dependencies = [ [[package]] name = "tower-http" -version = "0.6.11" +version = "0.6.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4cfcf7e2740e6fc6d4d688b4ef00650406bb94adf4731e43c096c3a19fe40840" +checksum = "d4e6559d53cc268e5031cd8429d05415bc4cb4aefc4aa5d6cc35fbf5b924a1f8" dependencies = [ "bitflags", "bytes", "futures-util", "http", "http-body", + "iri-string", "pin-project-lite", "tower", "tower-layer", "tower-service", - "url", ] [[package]] @@ -3089,9 +3100,9 @@ checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" [[package]] name = "typenum" -version = "1.20.0" +version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40ce102ab67701b8526c123c1bab5cbe42d7040ccfd0f64af1a385808d2f43de" +checksum = "562d481066bde0658276a35467c4af00bdc6ee726305698a55b86e61d7ad82bb" [[package]] name = "unicode-ident" @@ -3206,11 +3217,11 @@ checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" [[package]] name = "wasip2" -version = "1.0.3+wasi-0.2.9" +version = "1.0.2+wasi-0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "20064672db26d7cdc89c7798c48a0fdfac8213434a1186e5ef29fd560ae223d6" +checksum = "9517f9239f02c069db75e65f174b3da828fe5f5b945c4dd26bd25d89c03ebcf5" dependencies = [ - "wit-bindgen 0.57.1", + "wit-bindgen", ] [[package]] @@ -3219,14 +3230,14 @@ version = "0.4.0+wasi-0.3.0-rc-2026-01-06" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5428f8bf88ea5ddc08faddef2ac4a67e390b88186c703ce6dbd955e1c145aca5" dependencies = [ - "wit-bindgen 0.51.0", + "wit-bindgen", ] [[package]] name = "wasm-bindgen" -version = "0.2.122" +version = "0.2.116" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ed04576f974d2b2fba0f38c51dbc5518011e38c36bf1143164be765528fd409" +checksum = "7dc0882f7b5bb01ae8c5215a1230832694481c1a4be062fd410e12ea3da5b631" dependencies = [ "cfg-if", "once_cell", @@ -3237,9 +3248,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.72" +version = "0.4.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9473dbd2991ae90b6291c3c32c30c6187ac49aa32f9905d1cce280ec1e110b0f" +checksum = "19280959e2844181895ef62f065c63e0ca07ece4771b53d89bfdb967d97cbf05" dependencies = [ "js-sys", "wasm-bindgen", @@ -3247,9 +3258,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.122" +version = "0.2.116" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "916151b09da36bd82f6615cbf3a419e2f0ba23a03c6160e8e92eb6bd4aa1dec6" +checksum = "75973d3066e01d035dbedaad2864c398df42f8dd7b1ea057c35b8407c015b537" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -3257,9 +3268,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.122" +version = "0.2.116" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "299047362ccbfce148b67ab7e73349f77748e00c8296f9542adfad2ad82c5c5e" +checksum = "91af5e4be765819e0bcfee7322c14374dc821e35e72fa663a830bbc7dc199eac" dependencies = [ "bumpalo", "proc-macro2", @@ -3270,9 +3281,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.122" +version = "0.2.116" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a929b2c61f11ba3e9bc35b50c1f25cb38e0e892c0c231ae2b8cf78d5dad4437" +checksum = "c9bf0406a78f02f336bf1e451799cca198e8acde4ffa278f0fb20487b150a633" dependencies = [ "unicode-ident", ] @@ -3313,9 +3324,9 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.99" +version = "0.3.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d621441cfc37b84979402712047321980c178f299193a3589d05b99e8763436" +checksum = "749466a37ee189057f54748b200186b59a03417a117267baf3fd89cecc9fb837" dependencies = [ "js-sys", "wasm-bindgen", @@ -3339,9 +3350,9 @@ checksum = "5f20c57d8d7db6d3b86154206ae5d8fba62dd39573114de97c2cb0578251f8e1" [[package]] name = "webpki-roots" -version = "1.0.7" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52f5ee44c96cf55f1b349600768e3ece3a8f26010c05265ab73f945bb1a2eb9d" +checksum = "22cfaf3c063993ff62e73cb4311efde4db1efb31ab78a3e5c457939ad5cc0bed" dependencies = [ "rustls-pki-types", ] @@ -3541,9 +3552,9 @@ checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650" [[package]] name = "winnow" -version = "1.0.3" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0592e1c9d151f854e6fd382574c3a0855250e1d9b2f99d9281c6e6391af352f1" +checksum = "09dac053f1cd375980747450bfc7250c264eaae0583872e845c0c7cd578872b5" [[package]] name = "wit-bindgen" @@ -3554,12 +3565,6 @@ dependencies = [ "wit-bindgen-rust-macro", ] -[[package]] -name = "wit-bindgen" -version = "0.57.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ebf944e87a7c253233ad6766e082e3cd714b5d03812acc24c318f549614536e" - [[package]] name = "wit-bindgen-core" version = "0.51.0" @@ -3641,15 +3646,15 @@ dependencies = [ [[package]] name = "writeable" -version = "0.6.3" +version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ffae5123b2d3fc086436f8834ae3ab053a283cfac8fe0a0b8eaae044768a4c4" +checksum = "9edde0db4769d2dc68579893f2306b26c6ecfbe0ef499b013d731b7b9247e0b9" [[package]] name = "yoke" -version = "0.8.2" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abe8c5fda708d9ca3df187cae8bfb9ceda00dd96231bed36e445a1a48e66f9ca" +checksum = "72d6e5c6afb84d73944e5cedb052c4680d5657337201555f9f2a16b7406d4954" dependencies = [ "stable_deref_trait", "yoke-derive", @@ -3658,9 +3663,9 @@ dependencies = [ [[package]] name = "yoke-derive" -version = "0.8.2" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de844c262c8848816172cef550288e7dc6c7b7814b4ee56b3e1553f275f1858e" +checksum = "b659052874eb698efe5b9e8cf382204678a0086ebf46982b79d6ca3182927e5d" dependencies = [ "proc-macro2", "quote", @@ -3690,18 +3695,18 @@ dependencies = [ [[package]] name = "zerofrom" -version = "0.1.8" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ec05a11813ea801ff6d75110ad09cd0824ddba17dfe17128ea0d5f68e6c5272" +checksum = "50cc42e0333e05660c3587f3bf9d0478688e15d870fab3346451ce7f8c9fbea5" dependencies = [ "zerofrom-derive", ] [[package]] name = "zerofrom-derive" -version = "0.1.7" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11532158c46691caf0f2593ea8358fed6bbf68a0315e80aae9bd41fbade684a1" +checksum = "d71e5d6e06ab090c67b5e44993ec16b72dcbaabc526db883a360057678b48502" dependencies = [ "proc-macro2", "quote", @@ -3731,9 +3736,9 @@ dependencies = [ [[package]] name = "zerotrie" -version = "0.2.4" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f9152d31db0792fa83f70fb2f83148effb5c1f5b8c7686c3459e361d9bc20bf" +checksum = "2a59c17a5562d507e4b54960e8569ebee33bee890c70aa3fe7b97e85a9fd7851" dependencies = [ "displaydoc", "yoke", @@ -3742,9 +3747,9 @@ dependencies = [ [[package]] name = "zerovec" -version = "0.11.6" +version = "0.11.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90f911cbc359ab6af17377d242225f4d75119aec87ea711a880987b18cd7b239" +checksum = "6c28719294829477f525be0186d13efa9a3c602f7ec202ca9e353d310fb9a002" dependencies = [ "yoke", "zerofrom", @@ -3753,9 +3758,9 @@ dependencies = [ [[package]] name = "zerovec-derive" -version = "0.11.3" +version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "625dc425cab0dca6dc3c3319506e6593dcb08a9f387ea3b284dbd52a92c40555" +checksum = "eadce39539ca5cb3985590102671f2567e659fca9666581ad3411d59207951f3" dependencies = [ "proc-macro2", "quote", diff --git a/src/commands.rs b/src/commands.rs index 21a7eaae..c1ee182a 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -380,7 +380,7 @@ pub enum OfflineWalletSubCommand { /// Adds a recipient to the transaction. // Clap Doesn't support complex vector parsing https://github.com/clap-rs/clap/issues/1704. // Address and amount parsing is done at run time in handler function. - #[arg(env = "ADDRESS:SAT", long = "to", required = true, value_parser = parse_recipient)] + #[arg(env = "ADDRESS:SAT", long = "to", value_parser = parse_recipient)] recipients: Vec<(ScriptBuf, u64)>, #[cfg(feature = "dns_payment")] /// Adds DNS recipients to the transaction diff --git a/src/dns_payment_instructions.rs b/src/dns_payment_instructions.rs index 6dd13eed..fc7f616f 100644 --- a/src/dns_payment_instructions.rs +++ b/src/dns_payment_instructions.rs @@ -4,8 +4,9 @@ use bitcoin_payment_instructions::{ PaymentMethodType, amount, dns_resolver::DNSHrnResolver, }; use core::{net::SocketAddr, str::FromStr}; +use tokio::time::timeout; -use crate::{error::BDKCliError as Error, utils::shorten}; +use crate::error::BDKCliError as Error; #[derive(Debug)] pub struct ResolvedPaymentInfo { @@ -24,7 +25,7 @@ impl ResolvedPaymentInfo { .iter() .map(|pm| match pm { PaymentMethod::LightningBolt11(bolt11) => { - format!("Bolt 11 invoice ({})", shorten(bolt11, 20, 15)) + format!("Bolt 11 invoice ({})", bolt11) } PaymentMethod::LightningBolt12(offer) => format!("Bolt 12 invoice ({})", offer), PaymentMethod::OnChain(address) => format!("On chain ({})", address), @@ -58,7 +59,12 @@ pub(crate) async fn parse_dns_instructions( ParseError::HrnResolutionError("Unable to create socket from provided address") })?; let resolver = DNSHrnResolver(sock_addr); - let instructions = PaymentInstructions::parse(hrn, network, &resolver, true).await?; + let instructions = timeout( + std::time::Duration::from_secs(30), + PaymentInstructions::parse(hrn, network, &resolver, true), + ) + .await + .map_err(|_| ParseError::HrnResolutionError("Resolution request timed out"))??; Ok((resolver, instructions)) } @@ -104,11 +110,11 @@ pub async fn process_instructions( let min_amount = instructions .min_amt() - .map(|amnt| Amount::from_sat(amnt.milli_sats())); + .map(|amnt| Amount::from_sat(amnt.sats_rounding_up())); let max_amount = instructions .max_amt() - .map(|amnt| Amount::from_sat(amnt.milli_sats())); + .map(|amnt| Amount::from_sat(amnt.sats_rounding_up())); if min_amount.is_some_and(|min| amount_to_send < min) { return Err(Error::Generic( diff --git a/src/handlers.rs b/src/handlers.rs index b8b157d1..cd213871 100644 --- a/src/handlers.rs +++ b/src/handlers.rs @@ -537,6 +537,9 @@ pub async fn handle_offline_wallet_subcommand( } } CreateTx { + #[cfg(feature = "dns_payment")] + mut recipients, + #[cfg(not(feature = "dns_payment"))] recipients, #[cfg(feature = "dns_payment")] dns_recipients, @@ -555,6 +558,25 @@ pub async fn handle_offline_wallet_subcommand( } => { let mut tx_builder = wallet.build_tx(); + #[cfg(feature = "dns_payment")] + for recipient in dns_recipients { + log::info!("Resolving DNS instructions for recipient {}", recipient.0); + let amount = Amount::from_sat(recipient.1); + let (resolver, instructions) = + parse_dns_instructions(&recipient.0, cli_opts.network, &dns_resolver) + .await + .map_err(|e| Error::Generic(format!("Parsing error occured {e:#?}")))?; + let payment = process_instructions(amount, &instructions, resolver).await?; + + recipients.push((payment.0.into(), payment.1.to_sat())); + } + + if recipients.is_empty() { + return Err(Error::Generic( + "Either --to or --to_dns parameters must be specified".to_string(), + )); + } + if send_all { if recipients.len() == 1 { tx_builder.drain_wallet().drain_to(recipients[0].0.clone()); @@ -564,25 +586,10 @@ pub async fn handle_offline_wallet_subcommand( )); } } else { - #[allow(unused_mut)] - let mut recipients: Vec<_> = recipients + let recipients: Vec<_> = recipients .into_iter() .map(|(script, amount)| (script, Amount::from_sat(amount))) .collect(); - - #[cfg(feature = "dns_payment")] - for recipient in dns_recipients { - println!("Resolving DNS instructions for recipient {}", recipient.0); - let amount = Amount::from_sat(recipient.1); - let (resolver, instructions) = - parse_dns_instructions(&recipient.0, cli_opts.network, &dns_resolver) - .await - .map_err(|e| Error::Generic(format!("Parsing error occured {e:#?}")))?; - let payment = process_instructions(amount, &instructions, resolver).await?; - - recipients.push((payment.0.into(), payment.1)); - } - tx_builder.set_recipients(recipients); }