Switch over to use use blocks from nostrdb

This is still kind of broken until queries are switched over to nostrdb.
Will do this next

Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
William Casarin
2024-02-01 17:26:57 -08:00
committed by Daniel D’Aquino
parent 208b3331ca
commit 28a06af534
51 changed files with 1086 additions and 501 deletions

View File

@@ -206,13 +206,28 @@ class Ndb {
self.ndb = db
return true
}
func lookup_blocks_by_key_with_txn<Y>(_ key: NoteKey, txn: NdbTxn<Y>) -> NdbBlocks? {
guard let blocks = ndb_get_blocks_by_key(self.ndb.ndb, &txn.txn, key) else {
return nil
}
return NdbBlocks(ptr: blocks)
}
func lookup_blocks_by_key(_ key: NoteKey) -> NdbTxn<NdbBlocks?>? {
NdbTxn(ndb: self) { txn in
lookup_blocks_by_key_with_txn(key, txn: txn)
}
}
func lookup_note_by_key_with_txn<Y>(_ key: NoteKey, txn: NdbTxn<Y>) -> NdbNote? {
var size: Int = 0
guard let note_p = ndb_get_note_by_key(&txn.txn, key, &size) else {
return nil
}
return NdbNote(note: note_p, size: size, owned: false, key: key)
let ptr = ndb_note_ptr(ptr: note_p)
return NdbNote(note: ptr, size: size, owned: false, key: key)
}
func text_search(query: String, limit: Int = 128, order: NdbSearchOrder = .newest_first) -> [NoteKey] {
@@ -403,7 +418,8 @@ class Ndb {
let note_p = ndb_get_note_by_id(&txn.txn, baseAddress, &size, &key) else {
return nil
}
return NdbNote(note: note_p, size: size, owned: false, key: key)
let ptr = ndb_note_ptr(ptr: note_p)
return NdbNote(note: ptr, size: size, owned: false, key: key)
}
}

124
nostrdb/NdbBlock.swift Normal file
View File

@@ -0,0 +1,124 @@
//
// NdbBlock.swift
// damus
//
// Created by William Casarin on 2024-01-25.
//
import Foundation
enum NdbBlockType: UInt32 {
case hashtag = 1
case text = 2
case mention_index = 3
case mention_bech32 = 4
case url = 5
case invoice = 6
}
extension ndb_mention_bech32_block {
var bech32_type: NdbBech32Type? {
NdbBech32Type(rawValue: self.bech32.type.rawValue)
}
}
enum NdbBech32Type: UInt32 {
case note = 1
case npub = 2
case nprofile = 3
case nevent = 4
case nrelay = 5
case naddr = 6
case nsec = 7
var is_notelike: Bool {
return self == .note || self == .nevent
}
}
extension ndb_invoice_block {
func as_invoice() -> Invoice? {
let b11 = self.invoice
let invstr = self.invstr.as_str()
guard let description = convert_invoice_description(b11: b11) else {
return nil
}
let amount: Amount = b11.amount == 0 ? .any : .specific(Int64(b11.amount))
return Invoice(description: description, amount: amount, string: invstr, expiry: b11.expiry, created_at: b11.timestamp)
}
}
enum NdbBlock {
case text(ndb_str_block)
case mention(ndb_mention_bech32_block)
case hashtag(ndb_str_block)
case url(ndb_str_block)
case invoice(ndb_invoice_block)
case mention_index(UInt32)
init?(_ ptr: ndb_block_ptr) {
guard let type = NdbBlockType(rawValue: ndb_get_block_type(ptr.ptr).rawValue) else {
return nil
}
switch type {
case .hashtag: self = .hashtag(ptr.block.str)
case .text: self = .text(ptr.block.str)
case .invoice: self = .invoice(ptr.block.invoice)
case .url: self = .url(ptr.block.str)
case .mention_bech32: self = .mention(ptr.block.mention_bech32)
case .mention_index: self = .mention_index(ptr.block.mention_index)
}
}
var is_previewable: Bool {
switch self {
case .mention(let m):
switch m.bech32_type {
case .note, .nevent: return true
default: return false
}
case .invoice:
return true
case .url:
return true
default:
return false
}
}
static func convertToStringCopy(from block: str_block_t) -> String? {
guard let cString = block.str else {
return nil
}
let byteBuffer = UnsafeBufferPointer(start: cString, count: Int(block.len)).map { UInt8(bitPattern: $0) }
// Create a Swift String from the byte array
return String(bytes: byteBuffer, encoding: .utf8)
}
}
struct NdbBlocks {
private let blocks_ptr: ndb_blocks_ptr
init(ptr: OpaquePointer?) {
self.blocks_ptr = ndb_blocks_ptr(ptr: ptr)
}
var words: Int {
Int(ndb_blocks_word_count(blocks_ptr.ptr))
}
func iter(note: NdbNote) -> BlocksSequence {
BlocksSequence(note: note, blocks: self)
}
func as_ptr() -> OpaquePointer? {
return self.blocks_ptr.ptr
}
}

View File

@@ -0,0 +1,59 @@
//
// NdbBlockIterator.swift
// damus
//
// Created by William Casarin on 2024-01-25.
//
import Foundation
struct BlocksIterator: IteratorProtocol {
typealias Element = NdbBlock
var done: Bool
var iter: ndb_block_iterator
var note: NdbNote
mutating func next() -> NdbBlock? {
guard iter.blocks != nil,
let ptr = ndb_blocks_iterate_next(&iter) else {
done = true
return nil
}
let block_ptr = ndb_block_ptr(ptr: ptr)
return NdbBlock(block_ptr)
}
init(note: NdbNote, blocks: NdbBlocks) {
let content = ndb_note_content(note.note.ptr)
self.iter = ndb_block_iterator(content: content, blocks: nil, block: ndb_block(), p: nil)
ndb_blocks_iterate_start(content, blocks.as_ptr(), &self.iter)
self.done = false
self.note = note
}
}
struct BlocksSequence: Sequence {
let blocks: NdbBlocks
let note: NdbNote
init(note: NdbNote, blocks: NdbBlocks) {
self.blocks = blocks
self.note = note
}
func makeIterator() -> BlocksIterator {
return .init(note: note, blocks: blocks)
}
func collect() -> [NdbBlock] {
var xs = [NdbBlock]()
for x in self {
xs.append(x)
}
return xs
}
}

View File

@@ -47,7 +47,7 @@ class NdbNote: Codable, Equatable, Hashable {
private(set) var owned: Bool
let count: Int
let key: NoteKey?
let note: UnsafeMutablePointer<ndb_note>
let note: ndb_note_ptr
// cached stuff (TODO: remove these)
var decrypted_content: String? = nil
@@ -58,7 +58,7 @@ class NdbNote: Codable, Equatable, Hashable {
}
}
init(note: UnsafeMutablePointer<ndb_note>, size: Int, owned: Bool, key: NoteKey?) {
init(note: ndb_note_ptr, size: Int, owned: Bool, key: NoteKey?) {
self.note = note
self.owned = owned
self.count = size
@@ -80,9 +80,9 @@ class NdbNote: Codable, Equatable, Hashable {
}
let buf = malloc(self.count)!
memcpy(buf, &self.note.pointee, self.count)
let new_note = buf.assumingMemoryBound(to: ndb_note.self)
memcpy(buf, UnsafeRawPointer(self.note.ptr), self.count)
let new_note = ndb_note_ptr(ptr: OpaquePointer(buf))
return NdbNote(note: new_note, size: self.count, owned: true, key: self.key)
}
@@ -95,16 +95,16 @@ class NdbNote: Codable, Equatable, Hashable {
}
var content_raw: UnsafePointer<CChar> {
ndb_note_content(note)
ndb_note_content(note.ptr)
}
var content_len: UInt32 {
ndb_note_content_length(note)
ndb_note_content_length(note.ptr)
}
/// NDBTODO: make this into data
var id: NoteId {
.init(Data(bytes: ndb_note_id(note), count: 32))
.init(Data(bytes: ndb_note_id(note.ptr), count: 32))
}
var raw_note_id: UnsafeMutablePointer<UInt8> {
@@ -116,20 +116,20 @@ class NdbNote: Codable, Equatable, Hashable {
}
var sig: Signature {
.init(Data(bytes: ndb_note_sig(note), count: 64))
.init(Data(bytes: ndb_note_sig(note.ptr), count: 64))
}
/// NDBTODO: make this into data
var pubkey: Pubkey {
.init(Data(bytes: ndb_note_pubkey(note), count: 32))
.init(Data(bytes: ndb_note_pubkey(note.ptr), count: 32))
}
var created_at: UInt32 {
ndb_note_created_at(note)
ndb_note_created_at(note.ptr)
}
var kind: UInt32 {
ndb_note_kind(note)
ndb_note_kind(note.ptr)
}
var tags: TagsSequence {
@@ -144,7 +144,7 @@ class NdbNote: Codable, Equatable, Hashable {
print("\(NdbNote.notes_created) ndb_notes, \(NdbNote.total_ndb_size) bytes")
#endif
free(note)
free(UnsafeMutableRawPointer(note.ptr))
}
}
@@ -234,7 +234,7 @@ class NdbNote: Codable, Equatable, Hashable {
let buflen = MAX_NOTE_SIZE
let buf = malloc(buflen)
ndb_builder_init(&builder, buf, Int32(buflen))
ndb_builder_init(&builder, buf, buflen)
var pk_raw = noteConstructionMaterial.pubkey.bytes
@@ -262,9 +262,27 @@ class NdbNote: Codable, Equatable, Hashable {
return nil
}
var n = UnsafeMutablePointer<ndb_note>?(nil)
var n = ndb_note_ptr()
var the_kp: ndb_keypair? = nil
if let sec = keypair.privkey {
var kp = ndb_keypair()
memcpy(&kp.secret.0, sec.id.bytes, 32);
if ndb_create_keypair(&kp) <= 0 {
print("bad keypair")
} else {
the_kp = kp
}
}
var len: Int32 = 0
if var the_kp {
len = ndb_builder_finalize(&builder, &n.ptr, &the_kp)
} else {
len = ndb_builder_finalize(&builder, &n.ptr, nil)
}
switch noteConstructionMaterial {
case .keypair(let keypair):
@@ -328,7 +346,7 @@ class NdbNote: Codable, Equatable, Hashable {
return nil
}
self.note = r.assumingMemoryBound(to: ndb_note.self)
self.note = ndb_note_ptr(ptr: OpaquePointer(r))
self.key = nil
}
@@ -352,9 +370,9 @@ class NdbNote: Codable, Equatable, Hashable {
//guard var json_cstr = json.cString(using: .utf8) else { return nil }
//json_cs
var note: UnsafeMutablePointer<ndb_note>?
let len = ndb_note_from_json(json, Int32(json_len), &note, data, Int32(bufsize))
var note = ndb_note_ptr()
let len = ndb_note_from_json(json, Int32(json_len), &note.ptr, data, Int32(bufsize))
if len == 0 {
free(data)
@@ -362,10 +380,9 @@ class NdbNote: Codable, Equatable, Hashable {
}
// Create new Data with just the valid bytes
guard let note_data = realloc(data, Int(len)) else { return nil }
let new_note = note_data.assumingMemoryBound(to: ndb_note.self)
return NdbNote(note: new_note, size: Int(len), owned: true, key: nil)
guard let new_note = realloc(data, Int(len)) else { return nil }
let new_note_ptr = ndb_note_ptr(ptr: OpaquePointer(new_note))
return NdbNote(note: new_note_ptr, size: Int(len), owned: true, key: nil)
}
func get_inner_event() -> NdbNote? {
@@ -397,7 +414,7 @@ extension NdbNote {
var should_show_event: Bool {
return !too_big
}
func is_hellthread(max_pubkeys: Int) -> Bool {
switch known_kind {
case .text, .boost, .like, .zap:
@@ -407,10 +424,6 @@ extension NdbNote {
}
}
func get_blocks(keypair: Keypair) -> Blocks {
return parse_note_content(content: .init(note: self, keypair: keypair))
}
// TODO: References iterator
public var referenced_ids: References<NoteId> {
References<NoteId>(tags: self.tags)
@@ -451,7 +464,7 @@ extension NdbNote {
public var references: References<RefId> {
References<RefId>(tags: self.tags)
}
func thread_reply() -> ThreadReply? {
if self.known_kind != .highlight {
return ThreadReply(tags: self.tags)
@@ -463,6 +476,21 @@ extension NdbNote {
return ThreadReply(tags: self.tags)?.reply.note_id
}
func blocks(ndb: Ndb) -> NdbTxn<NdbBlocks>? {
let blocks_txn = NdbTxn<NdbBlocks?>(ndb: ndb) { txn in
guard let key = ndb.lookup_note_key_with_txn(self.id, txn: txn) else {
return nil
}
return ndb.lookup_blocks_by_key_with_txn(key, txn: txn)
}
guard let blocks_txn else {
return nil
}
return blocks_txn.collect()
}
func get_content(_ keypair: Keypair) -> String {
if known_kind == .dm {
return decrypted(keypair: keypair) ?? "*failed to decrypt content*"
@@ -482,10 +510,6 @@ extension NdbNote {
return content
}
func blocks(_ keypair: Keypair) -> Blocks {
return get_blocks(keypair: keypair)
}
// NDBTODO: switch this to operating on bytes not strings
func decrypted(keypair: Keypair) -> String? {
if let decrypted_content {
@@ -526,34 +550,22 @@ extension NdbNote {
return self.referenced_ids.last
}
// NDBTODO: id -> data
/*
public func references(id: String, key: AsciiCharacter) -> Bool {
var matcher: (Reference) -> Bool = { ref in ref.ref_id.matches_str(id) }
if id.count == 64, let decoded = hex_decode(id) {
matcher = { ref in ref.ref_id.matches_id(decoded) }
}
for ref in References(tags: self.tags) {
if ref.key == key && matcher(ref) {
return true
}
}
return false
}
*/
func is_reply() -> Bool {
return thread_reply() != nil
}
func note_language(_ keypair: Keypair) -> String? {
func note_language(ndb: Ndb, _ keypair: Keypair) -> String? {
assert(!Thread.isMainThread, "This function must not be run on the main thread.")
// Rely on Apple's NLLanguageRecognizer to tell us which language it thinks the note is in
// and filter on only the text portions of the content as URLs and hashtags confuse the language recognizer.
let originalBlocks = self.blocks(keypair).blocks
let originalOnlyText = originalBlocks.compactMap {
/*
guard let blocks_txn = self.blocks(ndb: ndb) else {
return nil
}
let blocks = blocks_txn.unsafeUnownedValue
let originalOnlyText = blocks.blocks(note: self).compactMap {
if case .text(let txt) = $0 {
// Replacing right single quotation marks () with "typewriter or ASCII apostrophes" (')
// as a workaround to get Apple's language recognizer to predict language the correctly.
@@ -580,6 +592,9 @@ extension NdbNote {
}
}
.joined(separator: " ")
*/
let originalOnlyText = self.get_content(keypair)
// If there is no text, there's nothing to use to detect language.
guard !originalOnlyText.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty else {

View File

@@ -25,7 +25,7 @@ struct NdbStrIter: IteratorProtocol {
}
init(tag: NdbTagElem) {
self.str = ndb_tag_str(tag.note.note, tag.tag, tag.index)
self.str = ndb_tag_str(tag.note.note.ptr, tag.tag.ptr, tag.index)
self.ind = 0
self.tag = tag
}
@@ -33,7 +33,7 @@ struct NdbStrIter: IteratorProtocol {
struct NdbTagElem: Sequence, Hashable, Equatable {
let note: NdbNote
let tag: UnsafeMutablePointer<ndb_tag>
let tag: ndb_tag_ptr
let index: Int32
let str: ndb_str
@@ -59,11 +59,11 @@ struct NdbTagElem: Sequence, Hashable, Equatable {
return memcmp(lhs.str.str, rhs.str.str, r) == 0
}
init(note: NdbNote, tag: UnsafeMutablePointer<ndb_tag>, index: Int32) {
init(note: NdbNote, tag: ndb_tag_ptr, index: Int32) {
self.note = note
self.tag = tag
self.index = index
self.str = ndb_tag_str(note.note, tag, index)
self.str = ndb_tag_str(note.note.ptr, tag.ptr, index)
}
var is_id: Bool {

View File

@@ -21,10 +21,10 @@ import Foundation
/// ```
struct TagSequence: Sequence {
let note: NdbNote
let tag: UnsafeMutablePointer<ndb_tag>
let tag: ndb_tag_ptr
var count: UInt16 {
tag.pointee.count
ndb_tag_count(tag.ptr)
}
func strings() -> [String] {
@@ -46,7 +46,7 @@ struct TagIterator: IteratorProtocol {
typealias Element = NdbTagElem
mutating func next() -> NdbTagElem? {
guard index < tag.pointee.count else { return nil }
guard index < ndb_tag_count(tag.ptr) else { return nil }
let el = NdbTagElem(note: note, tag: tag, index: index)
index += 1
@@ -56,13 +56,13 @@ struct TagIterator: IteratorProtocol {
var index: Int32
let note: NdbNote
var tag: UnsafeMutablePointer<ndb_tag>
var tag: ndb_tag_ptr
var count: UInt16 {
tag.pointee.count
ndb_tag_count(tag.ptr)
}
init(note: NdbNote, tag: UnsafeMutablePointer<ndb_tag>) {
init(note: NdbNote, tag: ndb_tag_ptr) {
self.note = note
self.tag = tag
self.index = 0

View File

@@ -20,16 +20,13 @@ struct TagsIterator: IteratorProtocol {
return nil
}
return TagSequence(note: note, tag: self.iter.tag)
}
var count: UInt16 {
return note.note.pointee.tags.count
let tag_ptr = ndb_tag_ptr(ptr: self.iter.tag)
return TagSequence(note: note, tag: tag_ptr)
}
init(note: NdbNote) {
self.iter = ndb_iterator()
ndb_tags_iterate_start(note.note, &self.iter)
ndb_tags_iterate_start(note.note.ptr, &self.iter)
self.done = false
self.note = note
}
@@ -39,7 +36,8 @@ struct TagsSequence: Encodable, Sequence {
let note: NdbNote
var count: UInt16 {
note.note.pointee.tags.count
let tags_ptr = ndb_note_tags(note.note.ptr)
return ndb_tags_count(tags_ptr)
}
func strings() -> [[String]] {
@@ -70,7 +68,8 @@ struct TagsSequence: Encodable, Sequence {
}
precondition(false, "sequence subscript oob")
// it seems like the compiler needs this or it gets bitchy
return .init(note: .init(note: .allocate(capacity: 1), size: 0, owned: true, key: nil), tag: .allocate(capacity: 1))
let nil_ptr = OpaquePointer(bitPattern: 0)
return .init(note: .init(note: .init(ptr: nil_ptr), size: 0, owned: true, key: nil), tag: .init(ptr: nil_ptr))
}
func makeIterator() -> TagsIterator {

View File

@@ -21,6 +21,10 @@ class NdbTxn<T> {
var generation: Int
var name: String
static func pure(ndb: Ndb, val: T) -> NdbTxn<T> {
.init(ndb: ndb, txn: ndb_txn(), val: val, generation: ndb.generation, inherited: true, name: "pure_txn")
}
init?(ndb: Ndb, with: (NdbTxn<T>) -> T = { _ in () }, name: String? = nil) {
guard !ndb.is_closed else { return nil }
self.name = name ?? "txn"

View File

@@ -5,9 +5,9 @@
/* Common FlatBuffers build functionality for C. */
#include "flatcc/flatcc_prologue.h"
#include "flatcc_prologue.h"
#ifndef FLATBUILDER_H
#include "flatcc/flatcc_builder.h"
#include "flatcc_builder.h"
#endif
typedef flatcc_builder_t flatbuffers_builder_t;
typedef flatcc_builder_ref_t flatbuffers_ref_t;
@@ -681,5 +681,5 @@ __flatbuffers_build_scalar(flatbuffers_, flatbuffers_double, double)
__flatbuffers_build_string(flatbuffers_)
__flatbuffers_build_buffer(flatbuffers_)
#include "flatcc/flatcc_epilogue.h"
#include "flatcc_epilogue.h"
#endif /* FLATBUFFERS_COMMON_BUILDER_H */

View File

@@ -5,8 +5,8 @@
/* Common FlatBuffers read functionality for C. */
#include "flatcc/flatcc_prologue.h"
#include "flatcc/flatcc_flatbuffers.h"
#include "flatcc_prologue.h"
#include "flatcc_flatbuffers.h"
#define __flatbuffers_read_scalar_at_byteoffset(N, p, o) N ## _read_from_pe((uint8_t *)(p) + (o))
@@ -574,5 +574,5 @@ static inline N ## _ ## K ## t N ## _as_typed_root(const void *buffer__tmp)\
#define __flatbuffers_struct_as_root(N) __flatbuffers_buffer_as_root(N, struct_)
#define __flatbuffers_table_as_root(N) __flatbuffers_buffer_as_root(N, table_)
#include "flatcc/flatcc_epilogue.h"
#include "flatcc_epilogue.h"
#endif /* FLATBUFFERS_COMMON_H */

View File

@@ -9,7 +9,7 @@
#ifndef FLATBUFFERS_COMMON_BUILDER_H
#include "flatbuffers_common_builder.h"
#endif
#include "flatcc/flatcc_prologue.h"
#include "flatcc_prologue.h"
#ifndef flatbuffers_identifier
#define flatbuffers_identifier 0
#endif
@@ -65,5 +65,5 @@ static NdbEventMeta_ref_t NdbEventMeta_clone(flatbuffers_builder_t *B, NdbEventM
__flatbuffers_memoize_end(B, t, NdbEventMeta_end(B));
}
#include "flatcc/flatcc_epilogue.h"
#include "flatcc_epilogue.h"
#endif /* META_BUILDER_H */

View File

@@ -6,11 +6,11 @@
#ifndef FLATBUFFERS_COMMON_READER_H
#include "flatbuffers_common_reader.h"
#endif
#include "flatcc/flatcc_flatbuffers.h"
#include "flatcc_flatbuffers.h"
#ifndef __alignas_is_defined
#include <stdalign.h>
#endif
#include "flatcc/flatcc_prologue.h"
#include "flatcc_prologue.h"
#ifndef flatbuffers_identifier
#define flatbuffers_identifier 0
#endif
@@ -54,5 +54,5 @@ __flatbuffers_define_scalar_field(4, NdbEventMeta, zaps, flatbuffers_int32, int3
__flatbuffers_define_scalar_field(5, NdbEventMeta, zap_total, flatbuffers_int64, int64_t, INT64_C(0))
#include "flatcc/flatcc_epilogue.h"
#include "flatcc_epilogue.h"
#endif /* META_READER_H */

View File

@@ -9,7 +9,7 @@
#ifndef FLATBUFFERS_COMMON_BUILDER_H
#include "flatbuffers_common_builder.h"
#endif
#include "flatcc/flatcc_prologue.h"
#include "flatcc_prologue.h"
#ifndef flatbuffers_identifier
#define flatbuffers_identifier 0
#endif
@@ -127,5 +127,5 @@ static NdbProfileRecord_ref_t NdbProfileRecord_clone(flatbuffers_builder_t *B, N
__flatbuffers_memoize_end(B, t, NdbProfileRecord_end(B));
}
#include "flatcc/flatcc_epilogue.h"
#include "flatcc_epilogue.h"
#endif /* PROFILE_BUILDER_H */

View File

@@ -3,8 +3,8 @@
/* Generated by flatcc 0.6.1 FlatBuffers schema compiler for C by dvide.com */
#include "flatcc/flatcc_json_parser.h"
#include "flatcc/flatcc_prologue.h"
#include "flatcc_json_parser.h"
#include "flatcc_prologue.h"
/*
* Parses the default root table or struct of the schema and constructs a FlatBuffer.
@@ -408,5 +408,5 @@ static int profile_parse_json(flatcc_builder_t *B, flatcc_json_parser_t *ctx,
return 0;
}
#include "flatcc/flatcc_epilogue.h"
#include "flatcc_epilogue.h"
#endif /* PROFILE_JSON_PARSER_H */

View File

@@ -6,11 +6,11 @@
#ifndef FLATBUFFERS_COMMON_READER_H
#include "flatbuffers_common_reader.h"
#endif
#include "flatcc/flatcc_flatbuffers.h"
#include "flatcc_flatbuffers.h"
#ifndef __alignas_is_defined
#include <stdalign.h>
#endif
#include "flatcc/flatcc_prologue.h"
#include "flatcc_prologue.h"
#ifndef flatbuffers_identifier
#define flatbuffers_identifier 0
#endif
@@ -89,5 +89,5 @@ __flatbuffers_define_scalar_field(2, NdbProfileRecord, note_key, flatbuffers_uin
__flatbuffers_define_string_field(3, NdbProfileRecord, lnurl, 0)
#include "flatcc/flatcc_epilogue.h"
#include "flatcc_epilogue.h"
#endif /* PROFILE_READER_H */

View File

@@ -6,8 +6,8 @@
#ifndef PROFILE_READER_H
#include "profile_reader.h"
#endif
#include "flatcc/flatcc_verifier.h"
#include "flatcc/flatcc_prologue.h"
#include "flatcc_verifier.h"
#include "flatcc_prologue.h"
static int NdbProfile_verify_table(flatcc_table_verifier_descriptor_t *td);
static int NdbProfileRecord_verify_table(flatcc_table_verifier_descriptor_t *td);
@@ -80,5 +80,5 @@ static inline int NdbProfileRecord_verify_as_root_with_type_hash(const void *buf
return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &NdbProfileRecord_verify_table);
}
#include "flatcc/flatcc_epilogue.h"
#include "flatcc_epilogue.h"
#endif /* PROFILE_VERIFIER_H */

View File

@@ -2,8 +2,6 @@
// swiftlint:disable all
// swiftformat:disable all
import FlatBuffers
public struct NdbEventMeta: FlatBufferObject, Verifiable {
static func validateVersion() { FlatBuffersVersion_23_5_26() }

View File

@@ -2,8 +2,6 @@
// swiftlint:disable all
// swiftformat:disable all
import FlatBuffers
public struct NdbProfile: FlatBufferObject, Verifiable {
static func validateVersion() { FlatBuffersVersion_23_5_26() }

View File

@@ -133,7 +133,8 @@ static struct bolt11 *decode_fail(struct bolt11 *b11, char **fail,
va_list ap;
va_start(ap, fmt);
*fail = tal_vfmt(tal_parent(b11), fmt, ap);
if (fail)
*fail = tal_vfmt(tal_parent(b11), fmt, ap);
va_end(ap);
return tal_free(b11);
}

View File

@@ -5,8 +5,8 @@
// Created by William Casarin on 2023-04-09.
//
#include "nostr_bech32.h"
#include <stdlib.h>
#include "nostr_bech32.h"
#include "cursor.h"
#include "str_block.h"
#include "ccan/endian/endian.h"
@@ -151,12 +151,12 @@ static int parse_nostr_bech32_nevent(struct cursor *cur, struct bech32_nevent *n
static int parse_nostr_bech32_naddr(struct cursor *cur, struct bech32_naddr *naddr) {
struct nostr_tlv tlv;
int i;
int i, has_kind;
has_kind = 0;
naddr->identifier.str = NULL;
naddr->identifier.len = 0;
naddr->pubkey = NULL;
naddr->has_kind = 0;
naddr->relays.num_relays = 0;
for (i = 0; i < MAX_TLVS; i++) {
@@ -183,7 +183,7 @@ static int parse_nostr_bech32_naddr(struct cursor *cur, struct bech32_naddr *nad
}
}
return naddr->identifier.str != NULL;
return naddr->identifier.str != NULL && has_kind;
}
static int parse_nostr_bech32_nprofile(struct cursor *cur, struct bech32_nprofile *nprofile) {

View File

@@ -384,7 +384,6 @@ struct bech32_naddr {
struct ndb_str_block identifier;
const unsigned char *pubkey;
uint32_t kind;
int has_kind;
};
struct bech32_nrelay {