diff --git a/damus.xcodeproj/project.pbxproj b/damus.xcodeproj/project.pbxproj index faff283a..4bd5b2ac 100644 --- a/damus.xcodeproj/project.pbxproj +++ b/damus.xcodeproj/project.pbxproj @@ -278,6 +278,7 @@ 4CE879552996BAB900F758CC /* RelayPaidDetail.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CE879542996BAB900F758CC /* RelayPaidDetail.swift */; }; 4CE879582996C45300F758CC /* ZapsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CE879572996C45300F758CC /* ZapsView.swift */; }; 4CE8795B2996C47A00F758CC /* ZapsModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CE8795A2996C47A00F758CC /* ZapsModel.swift */; }; + 4CE9FBBA2A6B3C63007E485C /* nostrdb.c in Sources */ = {isa = PBXBuildFile; fileRef = 4CE9FBB82A6B3B26007E485C /* nostrdb.c */; }; 4CEE2AED2805B22500AB5EEF /* NostrRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CEE2AEC2805B22500AB5EEF /* NostrRequest.swift */; }; 4CEE2AF1280B216B00AB5EEF /* EventDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CEE2AF0280B216B00AB5EEF /* EventDetailView.swift */; }; 4CEE2AF3280B25C500AB5EEF /* ProfilePicView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CEE2AF2280B25C500AB5EEF /* ProfilePicView.swift */; }; @@ -772,6 +773,8 @@ 4CE879542996BAB900F758CC /* RelayPaidDetail.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RelayPaidDetail.swift; sourceTree = ""; }; 4CE879572996C45300F758CC /* ZapsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ZapsView.swift; sourceTree = ""; }; 4CE8795A2996C47A00F758CC /* ZapsModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ZapsModel.swift; sourceTree = ""; }; + 4CE9FBB82A6B3B26007E485C /* nostrdb.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = nostrdb.c; sourceTree = ""; }; + 4CE9FBB92A6B3B26007E485C /* nostrdb.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = nostrdb.h; sourceTree = ""; }; 4CEE2AE72804F57C00AB5EEF /* libsecp256k1.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libsecp256k1.a; sourceTree = ""; }; 4CEE2AEC2805B22500AB5EEF /* NostrRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NostrRequest.swift; sourceTree = ""; }; 4CEE2AF0280B216B00AB5EEF /* EventDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventDetailView.swift; sourceTree = ""; }; @@ -907,8 +910,6 @@ 4CA9276F2A2A5D470098A105 /* parser.h */, 4CA9276E2A2A5D110098A105 /* wasm.c */, 4CA9276D2A2A5D110098A105 /* wasm.h */, - 4C4F14A82A2A71AB0045A0B9 /* nostrscript.h */, - 4C4F14A92A2A71AB0045A0B9 /* nostrscript.c */, 4C06670928FDE64700038D2A /* damus.h */, 4C06670A28FDE64700038D2A /* damus.c */, 4C06670828FDE64700038D2A /* damus-Bridging-Header.h */, @@ -1067,6 +1068,8 @@ 4C19AE4B2A5CEF7C00C90DB7 /* primal.ts */, 4C19AE4C2A5CEF7C00C90DB7 /* NostrScript.swift */, 4C19AE502A5CEF7C00C90DB7 /* nostr.ts */, + 4C4F14A82A2A71AB0045A0B9 /* nostrscript.h */, + 4C4F14A92A2A71AB0045A0B9 /* nostrscript.c */, ); path = nostrscript; sourceTree = ""; @@ -1320,23 +1323,17 @@ 4C9054862A6AEB4500811EEC /* nostrdb */ = { isa = PBXGroup; children = ( - 4C9054892A6AEDCD00811EEC /* Tests */, 4C9054882A6AED4700811EEC /* NdbTagIterator.swift */, 4C90548A2A6AEDEE00811EEC /* NdbNote.swift */, 4C5D5C9C2A6B2CB40024563C /* AsciiCharacter.swift */, 4CDD1ADF2A6B305F001CD4DF /* NdbTagElem.swift */, 4CDD1AE12A6B3074001CD4DF /* NdbTagsIterator.swift */, + 4CE9FBB82A6B3B26007E485C /* nostrdb.c */, + 4CE9FBB92A6B3B26007E485C /* nostrdb.h */, ); path = nostrdb; sourceTree = ""; }; - 4C9054892A6AEDCD00811EEC /* Tests */ = { - isa = PBXGroup; - children = ( - ); - path = Tests; - sourceTree = ""; - }; 4C9B0DEC2A65A74000CBDA21 /* Util */ = { isa = PBXGroup; children = ( @@ -1880,6 +1877,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 4CE9FBBA2A6B3C63007E485C /* nostrdb.c in Sources */, 4C3AC79D2833036D00E1F516 /* FollowingView.swift in Sources */, 5CF72FC229B9142F00124A13 /* ShareAction.swift in Sources */, 4C8D1A6C29F1DFC200ACDF75 /* FriendIcon.swift in Sources */, diff --git a/damusTests/NDB/NdbTests.swift b/damusTests/NDB/NdbTests.swift index 803f7317..1c440a04 100644 --- a/damusTests/NDB/NdbTests.swift +++ b/damusTests/NDB/NdbTests.swift @@ -26,13 +26,13 @@ final class NdbTests: XCTestCase { let id = "20d0ff27d6fcb13de8366328c5b1a7af26bcac07f2e558fbebd5e9242e608c09" XCTAssertEqual(hex_encode(note.id), id) - XCTAssertEqual(note.tags().underestimatedCount, 786) - XCTAssertEqual(note.tags().underestimatedCount, 786) + XCTAssertEqual(note.tags().reduce(0, { sum, _ in sum + 1 }), 786) + XCTAssertEqual(note.tags().reduce(0, { sum, _ in sum + 1 }), 786) //let tags = note.tags() for tag in note.tags() { for elem in tag { - print("test_ndb_iterator \(elem.)") + print("test_ndb_iterator \(elem.string())") } } diff --git a/nostrdb/NdbNote.swift b/nostrdb/NdbNote.swift index 7e18e049..d603e78b 100644 --- a/nostrdb/NdbNote.swift +++ b/nostrdb/NdbNote.swift @@ -30,13 +30,13 @@ struct NdbNote { var note: UnsafeMutablePointer? - let len = data.withUnsafeMutableBytes { (bytes: UnsafeMutableRawBufferPointer) -> Int in - return Int(ndb_note_from_json(&json_cstr, Int32(json_cstr.count), ¬e, bytes.baseAddress, Int32(bufsize))) + let len = data.withUnsafeMutableBytes { (bytes: UnsafeMutableRawBufferPointer) in + return ndb_note_from_json(&json_cstr, Int32(json_cstr.count), ¬e, bytes.baseAddress, Int32(bufsize)) } guard let note else { return nil } // Create new Data with just the valid bytes - let validData = Data(bytes: ¬e.pointee, count: len) + let validData = Data(bytes: ¬e.pointee, count: Int(len)) return NdbNote(notePointer: note, data: validData) }} diff --git a/damus-c/nostrdb.c b/nostrdb/nostrdb.c similarity index 99% rename from damus-c/nostrdb.c rename to nostrdb/nostrdb.c index c731866e..a6232218 100644 --- a/damus-c/nostrdb.c +++ b/nostrdb/nostrdb.c @@ -231,6 +231,7 @@ static inline int ndb_builder_process_json_tags(struct ndb_json_parser *p, } + int ndb_note_from_json(const char *json, int len, struct ndb_note **note, unsigned char *buf, int bufsize) { diff --git a/damus-c/nostrdb.h b/nostrdb/nostrdb.h similarity index 100% rename from damus-c/nostrdb.h rename to nostrdb/nostrdb.h diff --git a/damus-c/nostrscript.c b/nostrscript/nostrscript.c similarity index 100% rename from damus-c/nostrscript.c rename to nostrscript/nostrscript.c diff --git a/damus-c/nostrscript.h b/nostrscript/nostrscript.h similarity index 100% rename from damus-c/nostrscript.h rename to nostrscript/nostrscript.h