]> git.bitcoin.ninja Git - lightning-resolver/commitdiff
Update to latest rust-lightning/dnssec-validator and fix warnings
authorMatt Corallo <git@bluematt.me>
Wed, 10 Jul 2024 14:20:33 +0000 (14:20 +0000)
committerMatt Corallo <git@bluematt.me>
Wed, 10 Jul 2024 14:20:33 +0000 (14:20 +0000)
Cargo.toml
src/lib.rs

index 00560d8c7449937ab968c73b386503df78a9af86..e89c30868fadbc67ec9de5e4d72b5a94042d1176 100644 (file)
@@ -8,8 +8,8 @@ domain_resolver = ["lightning/std", "tokio/rt", "dnssec-prover/std"]
 name_resolver = ["dnssec-prover/validation", "lightning/no-std", "hex-conservative/alloc"]
 
 [dependencies]
-lightning = { version = "0.0.121", default-features = false }
-dnssec-prover = { version = "0.3", default-features = false }
+lightning = { version = "0.0.123", default-features = false }
+dnssec-prover = { version = "0.6", default-features = false }
 tokio = { version = "1.0", default-features = false, optional = true }
 hex-conservative = { version = "0.1", default-features = false, optional = true }
 
index e5d22409e6f49f363879eb53ef935593481207ba..2fe669041727b0bd2e7a86fb3edad1f346a6d321 100644 (file)
@@ -10,6 +10,7 @@ use std::sync::Mutex; // XXX: wont work without, should support no-std
 extern crate alloc;
 extern crate core;
 
+#[cfg(feature = "name_resolver")]
 use core::str::FromStr;
 
 #[cfg(feature = "domain_resolver")]
@@ -25,6 +26,7 @@ use dnssec_prover::query::build_txt_proof;
 use lightning::onion_message::packet::OnionMessageContents;
 use lightning::util::ser::{Readable, Writeable, Writer};
 use lightning::ln::msgs::DecodeError;
+#[cfg(feature = "name_resolver")]
 use lightning::offers::offer::Offer;
 
 #[cfg(any(feature = "domain_resolver", feature = "name_resolver"))]
@@ -297,8 +299,8 @@ mod name_resolver {
                                                        {
                                                                const URI_PREFIX: &str = "bitcoin:";
                                                                let mut candidate_records = resolved_rrs.iter()
-                                                                       .filter_map(|rr| if let RR::Txt(txt) = rr { Some(&txt.data) } else { None })
-                                                                       .filter_map(|data| if let Ok(s) = core::str::from_utf8(data) { Some(s) } else { None })
+                                                                       .filter_map(|rr| if let RR::Txt(txt) = rr { Some(txt.data.as_vec()) } else { None })
+                                                                       .filter_map(|data| if let Ok(s) = String::from_utf8(data) { Some(s) } else { None })
                                                                        .filter(|data_string| data_string.len() > URI_PREFIX.len())
                                                                        .filter(|data_string| data_string[..URI_PREFIX.len()].eq_ignore_ascii_case(URI_PREFIX));
                                                                let txt_record =
@@ -392,4 +394,34 @@ mod test {
                assert!(payer.handle_custom_message(response).is_none());
                offer_ref.lock().unwrap().take().unwrap();
        }
+
+       #[test]
+       fn bast() {
+               let secp_ctx = Secp256k1::new();
+               let dummy_pk = PublicKey::from_slice(&[2; 33]).unwrap();
+
+               let resolver = OMDomainResolver::new("1.1.1.1:53".parse().unwrap());
+
+               let resolver_keys = KeysManager::new(&[0; 32], 42, 43);
+               let resolver_dest = Destination::Node(dummy_pk);
+               let payer_path =
+                       BlindedPath::one_hop_for_message(dummy_pk, &resolver_keys, &secp_ctx).unwrap();
+               let now = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap().as_secs();
+               let payer = OMNameResolver::new(resolver_dest.clone(), payer_path.clone(), now as u32, 1);
+
+               let resolved_offer = Arc::new(Mutex::new(None));
+               let offer_ref = Arc::clone(&resolved_offer);
+               let resolve_offer = Box::new(move |offer| *resolved_offer.lock().unwrap() = offer);
+               payer.resolve_name("me@t-bast.xyz".to_owned(), resolve_offer).unwrap();
+               let mut msgs = payer.release_pending_custom_messages();
+               assert_eq!(msgs.len(), 1);
+
+               let msg = msgs.pop().unwrap();
+               assert_eq!(msg.destination, resolver_dest);
+               assert_eq!(msg.reply_path, Some(payer_path));
+               let response = resolver.handle_custom_message(msg.contents).unwrap();
+
+               assert!(payer.handle_custom_message(response).is_none());
+               offer_ref.lock().unwrap().take().unwrap();
+       }
 }