Skip to content
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
27 changes: 11 additions & 16 deletions Cargo.lock

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

12 changes: 11 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,17 @@ cln-plugin = "0.5"
parking_lot = "0.12"

# nostr-sdk = { git = "https://github.com/rust-nostr/nostr.git", rev = "f7122f5", features = ["nip47", "nip04", "nip44"]}
nostr-sdk = { version = "0.44", features = ["nip47", "nip04", "nip44"] }
# nostr-sdk = { version = "0.42", features = ["nip47", "nip04", "nip44"]}
nostr-sdk = { git = "https://github.com/daywalker90/nostr.git", branch = "bolt12", features = [
"nip47",
"nip04",
"nip44",
] }
# nostr-sdk = { path = "../nostr/crates/nostr-sdk", version = "0.42", features = [
# "nip47",
# "nip04",
# "nip44",
# ] }

uuid = { version = "1", features = ["v4"] }

Expand Down
5 changes: 5 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ mod nwc_invoice;
mod nwc_keysend;
mod nwc_lookups;
mod nwc_notifications;
mod nwc_offer;
mod nwc_pay;
mod parse;
mod rpc;
Expand Down Expand Up @@ -56,6 +57,10 @@ pub const WALLET_PAY_METHODS: [nip47::Method; 4] = [
nip47::Method::PayKeysend,
nip47::Method::MultiPayKeysend,
];
pub const WALLET_OFFER_READ_METHODS: [nip47::Method; 2] =
[nip47::Method::MakeOffer, nip47::Method::GetOfferInfo];
pub const WALLET_OFFER_PAY_METHODS: [nip47::Method; 2] =
[nip47::Method::PayOffer, nip47::Method::MultiPayOffer];
pub const WALLET_NOTIFICATIONS: [nip47::NotificationType; 2] = [
nip47::NotificationType::PaymentReceived,
nip47::NotificationType::PaymentSent,
Expand Down
18 changes: 18 additions & 0 deletions src/nwc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ use crate::{
nwc_invoice::make_invoice_response,
nwc_keysend::{multi_pay_keysend, pay_keysend_response},
nwc_lookups::{list_transactions_response, lookup_invoice_response},
nwc_offer::{
get_offer_info_response,
make_offer_response,
multi_pay_offer,
pay_offer_response,
},
nwc_pay::{multi_pay_invoice, pay_invoice_response},
structs::{NwcStore, PluginState},
tasks::budget_task,
Expand Down Expand Up @@ -289,6 +295,18 @@ async fn nwc_request_handler(
nip47::RequestParams::SettleHoldInvoice(settle_hold_invoice_request) => {
settle_hold_invoice_response(plugin.clone(), settle_hold_invoice_request, &label).await
}
nip47::RequestParams::MakeOffer(make_offer_request) => {
make_offer_response(plugin.clone(), make_offer_request).await
}
nip47::RequestParams::PayOffer(pay_offer_request) => {
pay_offer_response(plugin.clone(), pay_offer_request, &label).await
}
nip47::RequestParams::MultiPayOffer(multi_pay_offer_request) => {
multi_pay_offer(plugin.clone(), multi_pay_offer_request, &label).await
}
nip47::RequestParams::GetOfferInfo(get_offer_info_request) => {
get_offer_info_response(plugin.clone(), get_offer_info_request).await
}
};
for (response, id) in responses {
let content =
Expand Down
6 changes: 6 additions & 0 deletions src/nwc_lookups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,9 @@ async fn make_lookup_response_from_listinvoices(
settled_at: list_invoice.paid_at.map(Timestamp::from_secs),
metadata: None,
state: Some(state),
offer_issuer: invoice_decoded.offer_issuer,
payer_note: invoice_decoded.invreq_payer_note,
offer_id: invoice_decoded.offer_id,
})
}

Expand Down Expand Up @@ -443,6 +446,9 @@ async fn make_lookup_response_from_listpays(
settled_at: list_pay.completed_at.map(Timestamp::from_secs),
metadata: None,
state: Some(state),
offer_issuer: None,
payer_note: None,
offer_id: None,
})
}

Expand Down
94 changes: 42 additions & 52 deletions src/nwc_notifications.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ fn make_payment_received_from_listinvoices(
settled_at,
metadata: None,
state: Some(state),
offer_issuer: invoice_decoded.offer_issuer,
payer_note: invoice_decoded.invreq_payer_note,
offer_id: invoice_decoded.offer_id,
}),
};

Expand Down Expand Up @@ -236,9 +239,6 @@ async fn make_payment_sent_from_listpays(
&String::new()
};

let description;
let description_hash;
let amount;
let created_at = Timestamp::from_secs(pay.created_at);
let preimage = hex::encode(
pay.preimage
Expand All @@ -247,59 +247,46 @@ async fn make_payment_sent_from_listpays(
);
let settled_at = Timestamp::from_secs(pay.completed_at.unwrap());

if invstring.is_empty() {
description = pay.description.clone();
description_hash = None;
amount = if let Some(amt) = pay.amount_msat {
amt.msat()
} else {
// Amount missing but required
0
}
} else {
let invoice_decoded = rpc
.call_typed(&DecodeRequest {
string: invstring.clone(),
})
.await?;
let invoice_decoded = rpc
.call_typed(&DecodeRequest {
string: invstring.clone(),
})
.await?;

let not_invoice_err = Err(anyhow!(NOT_INV_ERR.to_owned()));
let not_invoice_err = Err(anyhow!(NOT_INV_ERR.to_owned()));

if !invoice_decoded.valid {
return not_invoice_err;
}
if !invoice_decoded.valid {
return not_invoice_err;
}

description = match invoice_decoded.item_type {
cln_rpc::model::responses::DecodeType::BOLT12_INVOICE => {
invoice_decoded.offer_description
}
cln_rpc::model::responses::DecodeType::BOLT11_INVOICE => invoice_decoded.description,
_ => return not_invoice_err,
};
description_hash = match invoice_decoded.item_type {
cln_rpc::model::responses::DecodeType::BOLT12_INVOICE => None,
cln_rpc::model::responses::DecodeType::BOLT11_INVOICE => {
invoice_decoded.description_hash.map(|h| h.to_string())
}
_ => return not_invoice_err,
};
amount = match invoice_decoded.item_type {
cln_rpc::model::responses::DecodeType::BOLT12_INVOICE => {
invoice_decoded.invoice_amount_msat.unwrap().msat()
}
cln_rpc::model::responses::DecodeType::BOLT11_INVOICE => {
if let Some(amt) = invoice_decoded.amount_msat {
amt.msat()
} else if let Some(a) = pay.amount_msat {
a.msat()
} else {
// amount: `any` but have to put a value...
0
}
let description = match invoice_decoded.item_type {
cln_rpc::model::responses::DecodeType::BOLT12_INVOICE => invoice_decoded.offer_description,
cln_rpc::model::responses::DecodeType::BOLT11_INVOICE => invoice_decoded.description,
_ => return not_invoice_err,
};
let description_hash = match invoice_decoded.item_type {
cln_rpc::model::responses::DecodeType::BOLT12_INVOICE => None,
cln_rpc::model::responses::DecodeType::BOLT11_INVOICE => {
invoice_decoded.description_hash.map(|h| h.to_string())
}
_ => return not_invoice_err,
};
let amount = match invoice_decoded.item_type {
cln_rpc::model::responses::DecodeType::BOLT12_INVOICE => {
invoice_decoded.invoice_amount_msat.unwrap().msat()
}
cln_rpc::model::responses::DecodeType::BOLT11_INVOICE => {
if let Some(amt) = invoice_decoded.amount_msat {
amt.msat()
} else if let Some(a) = pay.amount_msat {
a.msat()
} else {
// amount: `any` but have to put a value...
0
}
_ => return not_invoice_err,
};
}
}
_ => return not_invoice_err,
};

let fees_paid = if let Some(amt_sent) = pay.amount_sent_msat {
amt_sent.msat() - amount
Expand Down Expand Up @@ -329,6 +316,9 @@ async fn make_payment_sent_from_listpays(
settled_at,
metadata: None,
state: Some(state),
offer_issuer: invoice_decoded.offer_issuer,
payer_note: invoice_decoded.invreq_payer_note,
offer_id: invoice_decoded.offer_id,
}),
};

Expand Down
Loading
Loading