commit 78468aca8c263e50cae463743536d760239cc43d
parent 9f4f40346d5c269305b0ce539467e5e720d49096
Author: William Casarin <jb55@jb55.com>
Date: Wed, 3 Dec 2025 22:49:55 -0800
ndb: add add_key, process_giftwraps, rumor note fns
These are useful for ingesting giftwraps
Signed-off-by: William Casarin <jb55@jb55.com>
Diffstat:
2 files changed, 54 insertions(+), 1 deletion(-)
diff --git a/src/ndb.rs b/src/ndb.rs
@@ -159,6 +159,19 @@ impl Ndb {
self.process_event_with(json, IngestMetadata::new().client(true))
}
+ /// Attempt to unwrap any unprocessed giftwraps
+ pub fn process_giftwraps(&self, txn: &Transaction) {
+ unsafe {
+ bindings::ndb_process_giftwraps(self.as_ptr(), txn.as_mut_ptr());
+ }
+ }
+
+ /// Add a secret key to nostrdb's note ingester threads so that
+ /// nostrdb can unwrap incoming giftwraps.
+ pub fn add_key(&self, key: &[u8; 32]) -> bool {
+ unsafe { bindings::ndb_add_key(self.as_ptr(), key as *const u8 as *mut u8) != 0 }
+ }
+
pub fn query<'a>(
&self,
txn: &'a Transaction,
diff --git a/src/note.rs b/src/note.rs
@@ -189,6 +189,43 @@ impl<'a> Note<'a> {
}
#[inline]
+ pub fn flags(&self) -> u16 {
+ unsafe { *bindings::ndb_note_flags(self.as_ptr()) }
+ }
+
+ #[inline]
+ pub fn is_rumor(&self) -> bool {
+ (self.flags() & (bindings::NDB_NOTE_FLAG_RUMOR as u16))
+ == bindings::NDB_NOTE_FLAG_RUMOR as u16
+ }
+
+ #[inline]
+ pub fn rumor_giftwrap_id(&self) -> Option<&'a [u8; 32]> {
+ unsafe {
+ let ptr = bindings::ndb_note_rumor_giftwrap_id(self.as_ptr());
+
+ if ptr.is_null() {
+ return None;
+ }
+
+ Some(&*(ptr as *const [u8; 32]))
+ }
+ }
+
+ #[inline]
+ pub fn rumor_receiver_pubkey(&self) -> Option<&'a [u8; 32]> {
+ unsafe {
+ let ptr = bindings::ndb_note_rumor_receiver_pubkey(self.as_ptr());
+
+ if ptr.is_null() {
+ return None;
+ }
+
+ Some(&*(ptr as *const [u8; 32]))
+ }
+ }
+
+ #[inline]
pub fn as_ptr(&self) -> *mut bindings::ndb_note {
match self {
Note::Owned { ptr, .. } => *ptr,
@@ -623,6 +660,9 @@ mod tests {
let json = note.json().expect("note json");
// the signature changes so 267 is everything up until the signature
- assert_eq!(&json[..267], "{\"id\":\"fb165be22c7b2518b749aabb7140c73f0887fe84475c82785700663be85ba859\",\"pubkey\":\"6c540ed060bfc2b0c5b6f09cd3ebedf980ef7bc836d69582361d20f2ad124f23\",\"created_at\":42,\"kind\":1,\"tags\":[[\"comment\",\"this is a comment\"],[\"blah\",\"something\"]],\"content\":\"this is the content\"");
+ assert_eq!(
+ &json[..267],
+ "{\"id\":\"fb165be22c7b2518b749aabb7140c73f0887fe84475c82785700663be85ba859\",\"pubkey\":\"6c540ed060bfc2b0c5b6f09cd3ebedf980ef7bc836d69582361d20f2ad124f23\",\"created_at\":42,\"kind\":1,\"tags\":[[\"comment\",\"this is a comment\"],[\"blah\",\"something\"]],\"content\":\"this is the content\""
+ );
}
}