From 3cce42eea18803e3ec8af4ff8ce897e8c06ceb80 Mon Sep 17 00:00:00 2001 From: William Casarin Date: Thu, 25 Jan 2024 11:48:15 -0800 Subject: [PATCH] tags: add u64 decoding function This will be used for decoding expiries. --- nostrdb/NdbTagElem.swift | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/nostrdb/NdbTagElem.swift b/nostrdb/NdbTagElem.swift index 3ed18377..cf9e83e5 100644 --- a/nostrdb/NdbTagElem.swift +++ b/nostrdb/NdbTagElem.swift @@ -130,6 +130,22 @@ struct NdbTagElem: Sequence, Hashable, Equatable { return id.id } + func u64() -> UInt64? { + switch self.data() { + case .id: + return nil + case .str(let str): + var end_ptr = UnsafeMutablePointer(nil as OpaquePointer?) + let res = strtoull(str.str, &end_ptr, 10) + + if end_ptr?.pointee == 0 { + return res + } else { + return nil + } + } + } + func string() -> String { switch self.data() { case .id(let id):