Skip to content

Commit c2d8cbf

Browse files
committed
ffi(nostr): add Tag::public_key and Tag::event
1 parent 604bb44 commit c2d8cbf

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

bindings/nostr-ffi/bindings-python/examples/tags.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66

77
tag = Tag.parse(["p", other_user_pk.to_hex()])
88
# OR
9-
tag = Tag.from_enum(TagEnum.PUB_KEY(other_user_pk.to_hex(), None))
9+
tag = Tag.from_enum(TagEnum.PUBLIC_KEY_TAG(other_user_pk, None, None, False))
10+
# OR
11+
tag = Tag.public_key(other_user_pk)
1012

1113
event = EventBuilder.new_text_note("New note from Rust Nostr python bindings", [tag]).to_event(keys)
1214
print(event.as_json())

bindings/nostr-ffi/src/event/tag.rs

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -901,17 +901,33 @@ impl Deref for Tag {
901901
#[uniffi::export]
902902
impl Tag {
903903
#[uniffi::constructor]
904-
pub fn parse(data: Vec<String>) -> Result<Arc<Self>> {
905-
Ok(Arc::new(Self {
906-
inner: tag::Tag::try_from(data)?,
907-
}))
904+
pub fn parse(data: Vec<String>) -> Result<Self> {
905+
Ok(Self {
906+
inner: tag::Tag::parse(data)?,
907+
})
908908
}
909909

910910
#[uniffi::constructor]
911-
pub fn from_enum(e: TagEnum) -> Result<Arc<Self>> {
912-
Ok(Arc::new(Self {
911+
pub fn from_enum(e: TagEnum) -> Result<Self> {
912+
Ok(Self {
913913
inner: tag::Tag::try_from(e)?,
914-
}))
914+
})
915+
}
916+
917+
/// Compose `["p", "<public-key>"]` tag
918+
#[uniffi::constructor]
919+
pub fn public_key(public_key: Arc<PublicKey>) -> Self {
920+
Self {
921+
inner: tag::Tag::public_key(**public_key),
922+
}
923+
}
924+
925+
/// Compose `["e", "<event-id>"]` tag
926+
#[uniffi::constructor]
927+
pub fn event(event_id: Arc<EventId>) -> Self {
928+
Self {
929+
inner: tag::Tag::event(**event_id),
930+
}
915931
}
916932

917933
pub fn as_enum(&self) -> TagEnum {

0 commit comments

Comments
 (0)