Skip to content
This repository was archived by the owner on Feb 3, 2025. It is now read-only.

Commit

Permalink
Add util function for hodl invoice detection
Browse files Browse the repository at this point in the history
  • Loading branch information
benthecarman committed Jan 22, 2024
1 parent df91500 commit 52cdd0c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
11 changes: 4 additions & 7 deletions mutiny-core/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,9 @@ pub fn get_monitor_version(bytes: &[u8]) -> u64 {
u64::from_be_bytes(bytes[2..10].try_into().unwrap())
}

#[cfg(not(test))]
pub const HODL_INVOICE_NODES: [&str; 1] =
["031b301307574bbe9b9ac7b79cbe1700e31e544513eae0b5d7497483083f99e581"];

#[cfg(test)]
pub const HODL_INVOICE_NODES: [&str; 2] = [
/// Nodes that give hodl invoices, we want to warn users against this.
pub const HODL_INVOICE_NODES: [&str; 3] = [
"0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798", // pubkey of ONE_KEY
"031b301307574bbe9b9ac7b79cbe1700e31e544513eae0b5d7497483083f99e581",
"031b301307574bbe9b9ac7b79cbe1700e31e544513eae0b5d7497483083f99e581", // ZeusPay
"02187352cc4b1856b9604e0a79e1bc9b301be7e0c14acbbb8c29f7051d507127d7", // Robosats
];
8 changes: 8 additions & 0 deletions mutiny-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1705,6 +1705,14 @@ impl MutinyWallet {
let npub = parse_npub_or_nip05(&npub).await?;
Ok(npub.to_bech32().expect("bech32"))
}

/// If the invoice is from a node that gives hodl invoices
#[wasm_bindgen]
pub async fn is_potential_hodl_invoice(invoice: String) -> Result<bool, MutinyJsError> {
let invoice = Bolt11Invoice::from_str(&invoice)?;
Ok(mutiny_core::utils::HODL_INVOICE_NODES
.contains(&invoice.recover_payee_pub_key().to_hex().as_str()))
}
}

#[cfg(test)]
Expand Down

0 comments on commit 52cdd0c

Please sign in to comment.