nostrdb-rs

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

commit d7ad4a44b929157795601a68542490b4184ae657
parent 2da7d564eb25fd6e9853a38852e4e43eb92704a5
Author: William Casarin <jb55@jb55.com>
Date:   Mon, 16 Dec 2024 13:51:52 -0800

add get_profilekey_by_pubkey

This is for quickly checking for the existence of a profile and saving
the key for a faster lookup later.

Changelog-Added: Add get_profilekey_by_pubkey
Signed-off-by: William Casarin <jb55@jb55.com>

Diffstat:
Msrc/ndb.rs | 23+++++++++++++++++++++--
1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/src/ndb.rs b/src/ndb.rs @@ -297,7 +297,7 @@ impl Ndb { )) } - pub fn get_notekey_by_id(&self, txn: &Transaction, id: &[u8; 32]) -> Result<u64> { + pub fn get_notekey_by_id(&self, txn: &Transaction, id: &[u8; 32]) -> Result<NoteKey> { let res = unsafe { bindings::ndb_get_notekey_by_id( txn.as_mut_ptr(), @@ -309,7 +309,26 @@ impl Ndb { return Err(Error::NotFound); } - Ok(res) + Ok(NoteKey::new(res)) + } + + pub fn get_profilekey_by_pubkey( + &self, + txn: &Transaction, + pubkey: &[u8; 32], + ) -> Result<ProfileKey> { + let res = unsafe { + bindings::ndb_get_profilekey_by_pubkey( + txn.as_mut_ptr(), + pubkey.as_ptr() as *const ::std::os::raw::c_uchar, + ) + }; + + if res == 0 { + return Err(Error::NotFound); + } + + Ok(ProfileKey::new(res)) } pub fn get_blocks_by_key<'a>(