Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add WebLN::send_multi_payment #2

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion webln-js/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ default = []
[dependencies]
console_error_panic_hook = { version = "0.1", optional = true }
js-sys.workspace = true
webln = { version = "0.1", path = "../webln", default-features = false }
webln = { version = "0.2", path = "../webln", default-features = false }
wasm-bindgen.workspace = true
wasm-bindgen-futures.workspace = true

Expand Down
17 changes: 17 additions & 0 deletions webln-js/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@

extern crate alloc;

use alloc::string::String;
use alloc::vec::Vec;
use core::ops::Deref;

use send_payment::JsSendMultiPaymentResponse;
use wasm_bindgen::prelude::*;
use webln::WebLN;

Expand Down Expand Up @@ -115,6 +118,20 @@ impl JsWebLN {
.into())
}

/// Request that the user sends multiple payments.
#[wasm_bindgen(js_name = sendMultiPayment)]
pub async fn send_multi_payment(
&self,
invoices: Vec<String>,
) -> Result<JsSendMultiPaymentResponse> {
Ok(self
.inner
.send_multi_payment(invoices)
.await
.map_err(into_err)?
.into())
}

/// Request that the user sends a payment for an invoice.
/// The payment will only be initiated and will not wait for a preimage to be returned.
/// This is useful when paying HOLD Invoices. There is no guarantee that the payment will be successfully sent to the receiver.
Expand Down
6 changes: 3 additions & 3 deletions webln-js/src/request_invoice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ impl From<RequestInvoiceResponse> for JsRequestInvoiceResponse {

#[wasm_bindgen(js_class = RequestInvoiceResponse)]
impl JsRequestInvoiceResponse {
#[wasm_bindgen(getter)]
pub fn invoice(&self) -> String {
self.inner.invoice.clone()
#[wasm_bindgen(getter, js_name = paymentRequest)]
pub fn payment_request(&self) -> String {
self.inner.payment_request.clone()
}
}
87 changes: 86 additions & 1 deletion webln-js/src/send_payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
// Distributed under the MIT software license

use alloc::string::String;
use alloc::vec::Vec;

use wasm_bindgen::prelude::*;
use webln::SendPaymentResponse;
use webln::{
SendMultiPaymentError, SendMultiPaymentResponse, SendMultiPaymentSingle, SendPaymentResponse,
};

#[wasm_bindgen(js_name = SendPaymentResponse)]
pub struct JsSendPaymentResponse {
Expand All @@ -24,3 +27,85 @@ impl JsSendPaymentResponse {
self.inner.preimage.clone()
}
}

#[wasm_bindgen(js_name = SendMultiPaymentSingle)]
pub struct JsSendMultiPaymentSingle {
inner: SendMultiPaymentSingle,
}

#[wasm_bindgen(js_class = SendMultiPaymentSingle)]
impl JsSendMultiPaymentSingle {
#[wasm_bindgen(getter, js_name = paymentRequest)]
pub fn payment_request(&self) -> String {
self.inner.payment_request.clone()
}

#[wasm_bindgen(getter)]
pub fn response(&self) -> JsSendPaymentResponse {
self.inner.response.clone().into()
}
}

impl From<SendMultiPaymentSingle> for JsSendMultiPaymentSingle {
fn from(inner: SendMultiPaymentSingle) -> Self {
Self { inner }
}
}

#[wasm_bindgen(js_name = SendMultiPaymentError)]
pub struct JsSendMultiPaymentError {
inner: SendMultiPaymentError,
}

#[wasm_bindgen(js_class = SendMultiPaymentError)]
impl JsSendMultiPaymentError {
#[wasm_bindgen(getter, js_name = paymentRequest)]
pub fn payment_request(&self) -> String {
self.inner.payment_request.clone()
}

#[wasm_bindgen(getter)]
pub fn message(&self) -> String {
self.inner.message.clone()
}
}

impl From<SendMultiPaymentError> for JsSendMultiPaymentError {
fn from(inner: SendMultiPaymentError) -> Self {
Self { inner }
}
}

#[wasm_bindgen(js_name = SendMultiPaymentResponse)]
pub struct JsSendMultiPaymentResponse {
inner: SendMultiPaymentResponse,
}

impl From<SendMultiPaymentResponse> for JsSendMultiPaymentResponse {
fn from(inner: SendMultiPaymentResponse) -> Self {
Self { inner }
}
}

#[wasm_bindgen(js_class = SendMultiPaymentResponse)]
impl JsSendMultiPaymentResponse {
#[wasm_bindgen(getter)]
pub fn payments(&self) -> Vec<JsSendMultiPaymentSingle> {
self.inner
.payments
.iter()
.cloned()
.map(|e| e.into())
.collect()
}

#[wasm_bindgen(getter)]
pub fn errors(&self) -> Vec<JsSendMultiPaymentError> {
self.inner
.errors
.iter()
.cloned()
.map(|e| e.into())
.collect()
}
}
4 changes: 2 additions & 2 deletions webln/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "webln"
version = "0.1.0"
version = "0.2.0"
edition = "2021"
description = "WebLN - Lightning Web Standard"
authors.workspace = true
Expand All @@ -17,7 +17,7 @@ std = ["secp256k1/std", "wasm-bindgen/std"]

[dependencies]
js-sys.workspace = true
secp256k1 = { version = "0.27", default-features = false }
secp256k1 = { version = "0.28", default-features = false }
wasm-bindgen.workspace = true
wasm-bindgen-futures.workspace = true
web-sys = { version = "0.3", default-features = false, features = ["Window"] }
Loading
Loading