+#[cfg(feature = "std")]
+pub(super) fn is_expired(created_at: Duration, relative_expiry: Duration) -> bool {
+ let absolute_expiry = created_at.checked_add(relative_expiry);
+ match absolute_expiry {
+ Some(seconds_from_epoch) => match SystemTime::UNIX_EPOCH.elapsed() {
+ Ok(elapsed) => elapsed > seconds_from_epoch,
+ Err(_) => false,
+ },
+ None => false,
+ }
+}
+
+pub(super) fn filter_fallbacks(
+ chain: ChainHash, fallbacks: &Vec<FallbackAddress>
+) -> Vec<Address> {
+ let network = if chain == ChainHash::using_genesis_block(Network::Bitcoin) {
+ Network::Bitcoin
+ } else if chain == ChainHash::using_genesis_block(Network::Testnet) {
+ Network::Testnet
+ } else if chain == ChainHash::using_genesis_block(Network::Signet) {
+ Network::Signet
+ } else if chain == ChainHash::using_genesis_block(Network::Regtest) {
+ Network::Regtest
+ } else {
+ return Vec::new()
+ };
+
+ let to_valid_address = |address: &FallbackAddress| {
+ let version = match WitnessVersion::try_from(address.version) {
+ Ok(version) => version,
+ Err(_) => return None,
+ };
+
+ let program = address.program.clone();
+ let witness_program = match WitnessProgram::new(version, program) {
+ Ok(witness_program) => witness_program,
+ Err(_) => return None,
+ };
+ Some(Address::new(network, Payload::WitnessProgram(witness_program)))
+ };
+
+ fallbacks.iter().filter_map(to_valid_address).collect()
+}
+