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

Expand InputType with new variant: Bolt12 offer #1121

Merged
merged 12 commits into from
Nov 19, 2024
1 change: 1 addition & 0 deletions libs/sdk-bindings/src/breez_sdk.udl
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,7 @@ dictionary RecommendedFees {
interface InputType {
BitcoinAddress(BitcoinAddressData address);
Bolt11(LNInvoice invoice);
Bolt12(string offer);
ok300 marked this conversation as resolved.
Show resolved Hide resolved
NodeId(string node_id);
Url(string url);
LnUrlPay(LnUrlPayRequestData data);
Expand Down
23 changes: 23 additions & 0 deletions libs/sdk-common/src/input_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use ::bip21::Uri;
use anyhow::{anyhow, Result};
use bitcoin::bech32;
use bitcoin::bech32::FromBase32;
use lightning::offers::offer::Offer;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use LnUrlRequestData::*;
Expand Down Expand Up @@ -185,6 +186,12 @@ pub async fn parse(input: &str) -> Result<InputType> {
return Ok(InputType::Bolt11 { invoice });
}

if let Ok(offer) = input.parse::<Offer>() {
return Ok(InputType::Bolt12 {
offer: offer.to_string(),
});
}

// Public key serialized in compressed form (66 hex chars)
if let Ok(_node_id) = bitcoin::secp256k1::PublicKey::from_str(input) {
return Ok(InputType::NodeId {
Expand Down Expand Up @@ -418,6 +425,9 @@ pub enum InputType {
Bolt11 {
invoice: LNInvoice,
},
Bolt12 {
offer: String,
},
NodeId {
node_id: String,
},
Expand Down Expand Up @@ -926,6 +936,19 @@ pub(crate) mod tests {
Ok(())
}

#[tokio::test]
async fn test_bolt12_offer() -> Result<()> {
let bolt12_offer = "lno1pqpzwyq2p32x2um5ypmx2cm5dae8x93pqthvwfzadd7jejes8q9lhc4rvjxd022zv5l44g6qah82ru5rdpnpj";

assert!(matches!(
parse(bolt12_offer).await?,
InputType::Bolt12 { offer }
if offer == bolt12_offer
));

Ok(())
}

#[tokio::test]
async fn test_url() -> Result<()> {
assert!(matches!(
Expand Down
1 change: 1 addition & 0 deletions libs/sdk-core/src/binding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ pub struct _LnUrlWithdrawRequestData {
pub enum _InputType {
BitcoinAddress { address: BitcoinAddressData },
Bolt11 { invoice: LNInvoice },
Bolt12 { offer: String },
NodeId { node_id: String },
Url { url: String },
LnUrlPay { data: LnUrlPayRequestData },
Expand Down
16 changes: 10 additions & 6 deletions libs/sdk-core/src/bridge_generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1025,6 +1025,9 @@ const _: fn() = || {
InputType::Bolt11 { invoice } => {
let _: LNInvoice = invoice;
}
InputType::Bolt12 { offer } => {
let _: String = offer;
}
InputType::NodeId { node_id } => {
let _: String = node_id;
}
Expand Down Expand Up @@ -1613,17 +1616,18 @@ impl support::IntoDart for mirror_InputType {
InputType::Bolt11 { invoice } => {
vec![1.into_dart(), invoice.into_into_dart().into_dart()]
}
InputType::Bolt12 { offer } => vec![2.into_dart(), offer.into_into_dart().into_dart()],
InputType::NodeId { node_id } => {
vec![2.into_dart(), node_id.into_into_dart().into_dart()]
vec![3.into_dart(), node_id.into_into_dart().into_dart()]
}
InputType::Url { url } => vec![3.into_dart(), url.into_into_dart().into_dart()],
InputType::LnUrlPay { data } => vec![4.into_dart(), data.into_into_dart().into_dart()],
InputType::Url { url } => vec![4.into_dart(), url.into_into_dart().into_dart()],
InputType::LnUrlPay { data } => vec![5.into_dart(), data.into_into_dart().into_dart()],
InputType::LnUrlWithdraw { data } => {
vec![5.into_dart(), data.into_into_dart().into_dart()]
vec![6.into_dart(), data.into_into_dart().into_dart()]
}
InputType::LnUrlAuth { data } => vec![6.into_dart(), data.into_into_dart().into_dart()],
InputType::LnUrlAuth { data } => vec![7.into_dart(), data.into_into_dart().into_dart()],
InputType::LnUrlError { data } => {
vec![7.into_dart(), data.into_into_dart().into_dart()]
vec![8.into_dart(), data.into_into_dart().into_dart()]
}
}
.into_dart()
Expand Down
17 changes: 12 additions & 5 deletions libs/sdk-flutter/lib/bridge_generated.dart
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,9 @@ sealed class InputType with _$InputType {
const factory InputType.bolt11({
required LNInvoice invoice,
}) = InputType_Bolt11;
const factory InputType.bolt12({
required String offer,
}) = InputType_Bolt12;
const factory InputType.nodeId({
required String nodeId,
}) = InputType_NodeId;
Expand Down Expand Up @@ -3421,26 +3424,30 @@ class BreezSdkCoreImpl implements BreezSdkCore {
invoice: _wire2api_box_autoadd_ln_invoice(raw[1]),
);
case 2:
return InputType_Bolt12(
offer: _wire2api_String(raw[1]),
);
case 3:
return InputType_NodeId(
nodeId: _wire2api_String(raw[1]),
);
case 3:
case 4:
return InputType_Url(
url: _wire2api_String(raw[1]),
);
case 4:
case 5:
return InputType_LnUrlPay(
data: _wire2api_box_autoadd_ln_url_pay_request_data(raw[1]),
);
case 5:
case 6:
return InputType_LnUrlWithdraw(
data: _wire2api_box_autoadd_ln_url_withdraw_request_data(raw[1]),
);
case 6:
case 7:
return InputType_LnUrlAuth(
data: _wire2api_box_autoadd_ln_url_auth_request_data(raw[1]),
);
case 7:
case 8:
return InputType_LnUrlError(
data: _wire2api_box_autoadd_ln_url_error_data(raw[1]),
);
Expand Down
Loading
Loading