mirror of
https://github.com/aljazceru/breez-sdk-liquid.git
synced 2026-01-17 13:04:20 +01:00
42 lines
1.4 KiB
Rust
42 lines
1.4 KiB
Rust
use std::str::FromStr;
|
|
use std::time::{SystemTime, UNIX_EPOCH};
|
|
|
|
use anyhow::Result;
|
|
use lwk_wollet::elements::{LockTime, LockTime::*};
|
|
|
|
use crate::error::PaymentError;
|
|
|
|
pub(crate) fn now() -> u32 {
|
|
SystemTime::now()
|
|
.duration_since(UNIX_EPOCH)
|
|
.unwrap()
|
|
.as_secs() as u32
|
|
}
|
|
|
|
pub(crate) fn json_to_pubkey(json: &str) -> Result<boltz_client::PublicKey, PaymentError> {
|
|
boltz_client::PublicKey::from_str(json).map_err(|e| PaymentError::Generic {
|
|
err: format!("Failed to deserialize PublicKey: {e:?}"),
|
|
})
|
|
}
|
|
|
|
pub(crate) fn generate_keypair() -> boltz_client::Keypair {
|
|
let secp = boltz_client::Secp256k1::new();
|
|
let mut rng = bip39::rand::rngs::OsRng;
|
|
let secret_key = lwk_wollet::secp256k1::SecretKey::new(&mut rng);
|
|
boltz_client::Keypair::from_secret_key(&secp, &secret_key)
|
|
}
|
|
|
|
pub(crate) fn decode_keypair(secret_key: &str) -> Result<boltz_client::Keypair, lwk_wollet::Error> {
|
|
let secp = boltz_client::Secp256k1::new();
|
|
let secret_key = lwk_wollet::secp256k1::SecretKey::from_str(secret_key)?;
|
|
Ok(boltz_client::Keypair::from_secret_key(&secp, &secret_key))
|
|
}
|
|
|
|
pub(crate) fn is_locktime_expired(current_locktime: LockTime, expiry_locktime: LockTime) -> bool {
|
|
match (current_locktime, expiry_locktime) {
|
|
(Blocks(n), Blocks(lock_time)) => n >= lock_time,
|
|
(Seconds(n), Seconds(lock_time)) => n >= lock_time,
|
|
_ => false, // Not using the same units
|
|
}
|
|
}
|