ndb: add pubkey to NdbNote

This commit is contained in:
William Casarin
2023-07-21 16:01:28 -07:00
parent 4da23390f8
commit 6d43754e71
4 changed files with 21 additions and 14 deletions

View File

@@ -8,11 +8,12 @@
import Foundation
struct NdbNote {
// we can have owned notes, but we can also have lmdb virtual-memory mapped notes so its optional
private var owned: Data?
let note: UnsafeMutablePointer<ndb_note>
init(notePointer: UnsafeMutablePointer<ndb_note>, data: Data?) {
self.note = notePointer
init(note: UnsafeMutablePointer<ndb_note>, data: Data?) {
self.note = note
self.owned = data
}
@@ -20,6 +21,10 @@ struct NdbNote {
Data(buffer: UnsafeBufferPointer(start: ndb_note_id(note), count: 32))
}
var pubkey: Data {
Data(buffer: UnsafeBufferPointer(start: ndb_note_pubkey(note), count: 32))
}
func tags() -> TagsSequence {
return .init(note: note)
}
@@ -37,6 +42,6 @@ struct NdbNote {
guard let note else { return nil }
// Create new Data with just the valid bytes
let validData = Data(bytes: &note.pointee, count: Int(len))
return NdbNote(notePointer: note, data: validData)
let smol_data = Data(bytes: &note.pointee, count: Int(len))
return NdbNote(note: note, data: smol_data)
}}