Skip to content

Commit

Permalink
Add messages to keysends
Browse files Browse the repository at this point in the history
  • Loading branch information
benthecarman committed Sep 29, 2023
1 parent 9a8affc commit 63501c7
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
3 changes: 0 additions & 3 deletions mutiny-core/src/background.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ use lightning::{log_error, log_trace};
#[cfg(not(feature = "std"))]
extern crate alloc;

// extern crate lightning;
// extern crate lightning_rapid_gossip_sync;

use lightning::chain;
use lightning::chain::chaininterface::{BroadcasterInterface, FeeEstimator};
use lightning::chain::chainmonitor::{ChainMonitor, Persist};
Expand Down
17 changes: 15 additions & 2 deletions mutiny-core/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1152,6 +1152,7 @@ impl<S: MutinyStorage> Node<S> {
&self,
to_node: PublicKey,
amt_sats: u64,
message: Option<String>,
labels: Vec<String>,
payment_id: PaymentId,
) -> Result<MutinyInvoice, MutinyError> {
Expand All @@ -1173,7 +1174,17 @@ impl<S: MutinyStorage> Node<S> {
max_total_routing_fee_msat: None,
};

let recipient_onion = RecipientOnionFields::secret_only(payment_secret);
let recipient_onion = if let Some(msg) = message {
// keysend messages are encoded as TLV type 34349334
RecipientOnionFields::secret_only(payment_secret)
.with_custom_tlvs(vec![(34349334, msg.encode())])
.map_err(|_| {
log_error!(self.logger, "could not encode keysend message");
MutinyError::InvoiceCreationFailed
})?
} else {
RecipientOnionFields::secret_only(payment_secret)
};

let pay_result = self.channel_manager.send_spontaneous_payment_with_retry(
Some(preimage),
Expand Down Expand Up @@ -1219,6 +1230,7 @@ impl<S: MutinyStorage> Node<S> {
&self,
to_node: PublicKey,
amt_sats: u64,
message: Option<String>,
labels: Vec<String>,
timeout_secs: Option<u64>,
) -> Result<MutinyInvoice, MutinyError> {
Expand All @@ -1227,7 +1239,8 @@ impl<S: MutinyStorage> Node<S> {
let payment_id = PaymentId(entropy);

// initiate payment
let pay = self.init_keysend_payment(to_node, amt_sats, labels.clone(), payment_id)?;
let pay =
self.init_keysend_payment(to_node, amt_sats, message, labels.clone(), payment_id)?;

let timeout: u64 = timeout_secs.unwrap_or(DEFAULT_PAYMENT_TIMEOUT);
let payment_hash = PaymentHash(pay.payment_hash.into_inner());
Expand Down
3 changes: 2 additions & 1 deletion mutiny-core/src/nodemanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1685,11 +1685,12 @@ impl<S: MutinyStorage> NodeManager<S> {
from_node: &PublicKey,
to_node: PublicKey,
amt_sats: u64,
message: Option<String>,
labels: Vec<String>,
) -> Result<MutinyInvoice, MutinyError> {
let node = self.get_node(from_node).await?;
log_debug!(self.logger, "Keysending to {to_node}");
node.keysend_with_timeout(to_node, amt_sats, labels, None)
node.keysend_with_timeout(to_node, amt_sats, message, labels, None)
.await
}

Expand Down
3 changes: 2 additions & 1 deletion mutiny-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,7 @@ impl MutinyWallet {
from_node: String,
to_node: String,
amt_sats: u64,
message: Option<String>,
labels: &JsValue, /* Vec<String> */
) -> Result<MutinyInvoice, MutinyJsError> {
let from_node = PublicKey::from_str(&from_node)?;
Expand All @@ -627,7 +628,7 @@ impl MutinyWallet {
Ok(self
.inner
.node_manager
.keysend(&from_node, to_node, amt_sats, labels)
.keysend(&from_node, to_node, amt_sats, message, labels)
.await?
.into())
}
Expand Down

0 comments on commit 63501c7

Please sign in to comment.