From 47028b85a5c9e5c29b05fe2b28ccc593ed0c00f7 Mon Sep 17 00:00:00 2001 From: Rusted Moon Date: Wed, 31 Jan 2024 17:27:54 +0100 Subject: [PATCH] js(nostr): add `EventBuilder::job_feedback` --- bindings/nostr-js/src/event/builder.rs | 22 +++++++++++++++ bindings/nostr-js/src/nips/mod.rs | 1 + bindings/nostr-js/src/nips/nip90.rs | 38 ++++++++++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 bindings/nostr-js/src/nips/nip90.rs diff --git a/bindings/nostr-js/src/event/builder.rs b/bindings/nostr-js/src/event/builder.rs index 3591b60fd..9dd161bee 100644 --- a/bindings/nostr-js/src/event/builder.rs +++ b/bindings/nostr-js/src/event/builder.rs @@ -13,6 +13,7 @@ use crate::error::{into_err, Result}; use crate::key::{JsKeys, JsPublicKey}; use crate::nips::nip57::JsZapRequestData; use crate::nips::nip65::JsRelayListItem; +use crate::nips::nip90::JsDataVendingMachineStatus; use crate::types::{JsContact, JsMetadata}; #[wasm_bindgen(js_name = EventBuilder)] @@ -301,4 +302,25 @@ impl JsEventBuilder { .map_err(into_err)?, }) } + + #[wasm_bindgen(js_name = jobFeedback)] + pub fn job_feedback( + job_request: &JsEvent, + status: JsDataVendingMachineStatus, + extra_info: Option, + amount_millisats: u64, + bolt11: Option, + payload: Option, + ) -> Self { + Self { + builder: EventBuilder::job_feedback( + job_request.deref(), + status.into(), + extra_info, + amount_millisats, + bolt11, + payload, + ), + } + } } diff --git a/bindings/nostr-js/src/nips/mod.rs b/bindings/nostr-js/src/nips/mod.rs index 16504c981..681c61689 100644 --- a/bindings/nostr-js/src/nips/mod.rs +++ b/bindings/nostr-js/src/nips/mod.rs @@ -14,3 +14,4 @@ pub mod nip46; pub mod nip47; pub mod nip57; pub mod nip65; +pub mod nip90; diff --git a/bindings/nostr-js/src/nips/nip90.rs b/bindings/nostr-js/src/nips/nip90.rs new file mode 100644 index 000000000..79f30b7bd --- /dev/null +++ b/bindings/nostr-js/src/nips/nip90.rs @@ -0,0 +1,38 @@ +// Copyright (c) 2023-2024 Rust Nostr Developers +// Distributed under the MIT software license + +use nostr::nips::nip90::DataVendingMachineStatus; +use wasm_bindgen::prelude::*; + +#[wasm_bindgen(js_name = DataVendingMachineStatus)] +pub enum JsDataVendingMachineStatus { + PaymentRequired, + Processing, + Error, + Success, + Partial, +} + +impl From for JsDataVendingMachineStatus { + fn from(value: DataVendingMachineStatus) -> Self { + match value { + DataVendingMachineStatus::PaymentRequired => Self::PaymentRequired, + DataVendingMachineStatus::Processing => Self::Processing, + DataVendingMachineStatus::Error => Self::Error, + DataVendingMachineStatus::Success => Self::Success, + DataVendingMachineStatus::Partial => Self::Partial, + } + } +} + +impl From for DataVendingMachineStatus { + fn from(value: JsDataVendingMachineStatus) -> Self { + match value { + JsDataVendingMachineStatus::PaymentRequired => Self::PaymentRequired, + JsDataVendingMachineStatus::Processing => Self::Processing, + JsDataVendingMachineStatus::Error => Self::Error, + JsDataVendingMachineStatus::Success => Self::Success, + JsDataVendingMachineStatus::Partial => Self::Partial, + } + } +}