nostrdb-rs

nostrdb in rust!
git clone git://jb55.com/nostrdb-rs
Log | Files | Refs | Submodules | README | LICENSE

commit 2111948b078b24a1659d0bd5d8570f370269c99b
parent 253dc876986df3c3f6d28495134f3c369422632c
Author: William Casarin <jb55@jb55.com>
Date:   Thu,  2 Jan 2025 09:29:43 -0600

expose process_client_event

Signed-off-by: William Casarin <jb55@jb55.com>

Diffstat:
Msrc/ndb.rs | 20++++++++++++++++++++
1 file changed, 20 insertions(+), 0 deletions(-)

diff --git a/src/ndb.rs b/src/ndb.rs @@ -142,6 +142,26 @@ impl Ndb { Ok(()) } + /// Ingest a client-sent event in the form `["EVENT", {"id:"...}]` + /// This function returns immediately and doesn't provide any information on + /// if ingestion was successful or not. + pub fn process_client_event(&self, json: &str) -> Result<()> { + // Convert the Rust string to a C-style string + let c_json = CString::new(json).expect("CString::new failed"); + let c_json_ptr = c_json.as_ptr(); + + // Get the length of the string + let len = json.len() as libc::c_int; + + let res = unsafe { bindings::ndb_process_client_event(self.as_ptr(), c_json_ptr, len) }; + + if res == 0 { + return Err(Error::NoteProcessFailed); + } + + Ok(()) + } + pub fn query<'a>( &self, txn: &'a Transaction,