Skip to main content

tap_msg/
utils.rs

1//! Utility functions for TAP core
2//!
3//! This module provides utility functions used throughout the TAP core library.
4
5pub mod memo_hash;
6pub mod name_hash;
7
8use crate::error::Error;
9use crate::Result;
10use std::time::SystemTime;
11
12pub use memo_hash::{
13    encode_binary_memo, encode_text_memo, tap_memo_hash, verify_binary_memo, verify_text_memo,
14};
15pub use name_hash::{hash_name, NameHashable};
16
17/// Gets the current time as a unix timestamp (seconds since the epoch)
18///
19/// # Returns
20///
21/// * `Result<u64>` - The current time as a unix timestamp, or an error if
22///   the system time cannot be determined.
23pub fn get_current_time() -> Result<u64> {
24    SystemTime::now()
25        .duration_since(SystemTime::UNIX_EPOCH)
26        .map_err(|e| Error::ParseError(format!("Failed to get current time: {}", e)))
27        .map(|duration| duration.as_secs())
28}