utils.rs 595 B

12345678910111213141516171819202122
  1. //! Utils
  2. use bitcoin::hashes::sha256::Hash as Sha256;
  3. use bitcoin::hashes::Hash;
  4. use rand::prelude::*;
  5. use regex::Regex;
  6. pub fn extract_url_from_error(error: &str) -> Option<String> {
  7. let regex = Regex::new(r"https?://[^\s]+").unwrap();
  8. if let Some(capture) = regex.captures(error) {
  9. return Some(capture[0].to_owned());
  10. }
  11. None
  12. }
  13. pub fn random_hash() -> Vec<u8> {
  14. let mut rng = rand::thread_rng();
  15. let mut random_bytes = [0u8; Sha256::LEN];
  16. rng.fill_bytes(&mut random_bytes);
  17. let hash = Sha256::hash(&random_bytes);
  18. hash.to_byte_array().to_vec()
  19. }