commit 1489a5aee49996d8a6a54b4c3c9c8397e3e8d40f
parent c1262af50b4462590ae7687de5bc32d4ebddd9d8
Author: William Casarin <jb55@jb55.com>
Date: Wed, 24 Apr 2024 10:44:28 -0700
profile: add get_profile_by_key
if we already did a pubkey lookup and cached the result
Signed-off-by: William Casarin <jb55@jb55.com>
Diffstat:
1 file changed, 25 insertions(+), 0 deletions(-)
diff --git a/src/ndb.rs b/src/ndb.rs
@@ -178,6 +178,31 @@ impl Ndb {
}
}
+ pub fn get_profile_by_key<'a>(
+ &self,
+ transaction: &'a Transaction,
+ key: ProfileKey,
+ ) -> Result<ProfileRecord<'a>> {
+ let mut len: usize = 0;
+
+ let profile_record_ptr = unsafe {
+ bindings::ndb_get_profile_by_key(transaction.as_mut_ptr(), key.as_u64(), &mut len)
+ };
+
+ if profile_record_ptr.is_null() {
+ // Handle null pointer (e.g., note not found or error occurred)
+ return Err(Error::NotFound);
+ }
+
+ // Convert the raw pointer to a Note instance
+ Ok(ProfileRecord::new_transactional(
+ profile_record_ptr,
+ len,
+ key,
+ transaction,
+ ))
+ }
+
pub fn get_profile_by_pubkey<'a>(
&self,
transaction: &'a Transaction,