Skip to content

Commit

Permalink
feat(rpc): added description_hash field
Browse files Browse the repository at this point in the history
  • Loading branch information
evd0kim authored and vincenzopalazzo committed Jun 13, 2023
1 parent e266f63 commit 6370b13
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
3 changes: 3 additions & 0 deletions rpc/src/lightningrpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ impl LightningRPC {
description: &str,
preimage: Option<&str>,
expiry: Option<u64>,
deschashonly: Option<bool>,
) -> Result<responses::Invoice, Error> {
match amount_msat {
None => self.call(
Expand All @@ -163,6 +164,7 @@ impl LightningRPC {
description,
preimage,
expiry,
deschashonly,
},
),
Some(amount_msat) => self.call(
Expand All @@ -173,6 +175,7 @@ impl LightningRPC {
description,
preimage,
expiry,
deschashonly,
},
),
}
Expand Down
4 changes: 4 additions & 0 deletions rpc/src/requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ pub struct Invoice<'a> {
pub preimage: Option<&'a str>,
#[serde(skip_serializing_if = "Option::is_none")]
pub expiry: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub deschashonly: Option<bool>,
}

/// 'invoice' command with zero amount
Expand All @@ -119,6 +121,8 @@ pub struct AnyInvoice<'a> {
pub preimage: Option<&'a str>,
#[serde(skip_serializing_if = "Option::is_none")]
pub expiry: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub deschashonly: Option<bool>,
}

/// 'delinvoice' command
Expand Down
32 changes: 31 additions & 1 deletion rpc/tests/rpc_utility_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,14 @@ fn listinvoice_by_payment_hash_test_one(lightningd: LightningRPC) {
fn generate_amountless_invoice_test_one(lightningd: LightningRPC) {
let label = format!("{}", Uuid::new_v4());
let invoice = lightningd
.invoice(None, label.as_str(), "generate an any invoice", None, None)
.invoice(
None,
label.as_str(),
"generate an any invoice",
None,
None,
None,
)
.unwrap();
let decode = lightningd.decodepay(&invoice.bolt11, None).unwrap();
assert_eq!(decode.amount_msat, None);
Expand All @@ -113,8 +120,31 @@ fn generate_invoice_with_amount_test_one(lightningd: LightningRPC) {
"generate an any invoice",
None,
None,
None,
)
.unwrap();
let decode = lightningd.decodepay(&invoice.bolt11, None).unwrap();
assert_eq!(decode.amount_msat, Some(MSat(1)));
}

#[rstest]
fn generate_invoice_with_description_hash(lightningd: LightningRPC) {
let label = format!("{}", Uuid::new_v4());
let invoice = lightningd
.invoice(
Some(1),
label.as_str(),
"description for hash",
None,
None,
Some(true),
)
.unwrap();
println!("{:?}", invoice);
let decode = lightningd.decodepay(&invoice.bolt11, None).unwrap();
assert_eq!(decode.amount_msat, Some(MSat(1)));
assert_eq!(
decode.description_hash,
Some("62af1b6b91d49301648cb3e6e5c88ced5d72a8c1db3e6711dcf89add72436479".to_string())
);
}

0 comments on commit 6370b13

Please sign in to comment.