Skip to content

Commit 9112168

Browse files
committed
js(nostr-sdk): add Client::send_event_builder
1 parent 1708def commit 9112168

File tree

1 file changed

+29
-1
lines changed
  • bindings/nostr-sdk-js/src/client

1 file changed

+29
-1
lines changed

bindings/nostr-sdk-js/src/client/mod.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::time::Duration;
1111
use async_utility::thread;
1212
use js_sys::Array;
1313
use nostr_js::error::{into_err, Result};
14-
use nostr_js::event::{JsEvent, JsEventArray, JsEventId, JsTag};
14+
use nostr_js::event::{JsEvent, JsEventArray, JsEventBuilder, JsEventId, JsTag};
1515
use nostr_js::key::JsPublicKey;
1616
use nostr_js::message::{JsFilter, JsRelayMessage};
1717
use nostr_js::types::{JsContact, JsMetadata};
@@ -192,6 +192,34 @@ impl JsClient {
192192
.map(|id| id.into())
193193
}
194194

195+
/// Take an [`EventBuilder`], sign it by using the [`ClientSigner`] and broadcast to all relays.
196+
///
197+
/// Rise an error if the [`ClientSigner`] is not set.
198+
#[wasm_bindgen(js_name = sendEvent)]
199+
pub async fn send_event_builder(&self, builder: &JsEventBuilder) -> Result<JsEventId> {
200+
self.inner
201+
.send_event_builder(builder.deref().clone())
202+
.await
203+
.map_err(into_err)
204+
.map(|id| id.into())
205+
}
206+
207+
/// Take an [`EventBuilder`], sign it by using the [`ClientSigner`] and broadcast to specific relays.
208+
///
209+
/// Rise an error if the [`ClientSigner`] is not set.
210+
#[wasm_bindgen(js_name = sendEventTo)]
211+
pub async fn send_event_builder_to(
212+
&self,
213+
url: String,
214+
builder: &JsEventBuilder,
215+
) -> Result<JsEventId> {
216+
self.inner
217+
.send_event_builder_to(url, builder.deref().clone())
218+
.await
219+
.map_err(into_err)
220+
.map(|id| id.into())
221+
}
222+
195223
/// Update metadata
196224
///
197225
/// <https://github.com/nostr-protocol/nips/blob/master/01.md>

0 commit comments

Comments
 (0)