Skip to content

Commit

Permalink
Bump sdk-common, propagate changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ok300 committed Nov 14, 2024
1 parent f9b9d54 commit 10fbefa
Show file tree
Hide file tree
Showing 13 changed files with 60 additions and 51 deletions.
2 changes: 1 addition & 1 deletion cli/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 lib/Cargo.lock

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

Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ typedef struct wire_cst_amount {
} wire_cst_amount;

typedef struct wire_cst_ln_offer {
struct wire_cst_list_prim_u_8_strict *bolt12;
struct wire_cst_list_prim_u_8_strict *offer;
struct wire_cst_list_String *chains;
struct wire_cst_amount *min_amount;
struct wire_cst_list_prim_u_8_strict *description;
Expand Down
2 changes: 1 addition & 1 deletion lib/bindings/src/breez_sdk_liquid.udl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ interface Amount {
};

dictionary LNOffer {
string bolt12;
string offer;
sequence<string> chains;
string? description;
string? signing_pubkey;
Expand Down
2 changes: 1 addition & 1 deletion lib/core/src/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ pub enum _Amount {

#[frb(mirror(LNOffer))]
pub struct _LNOffer {
pub bolt12: String,
pub offer: String,
pub chains: Vec<String>,
pub min_amount: Option<Amount>,
pub description: Option<String>,
Expand Down
16 changes: 8 additions & 8 deletions lib/core/src/frb_generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1858,7 +1858,7 @@ const _: fn() = || {
}
{
let LNOffer = None::<crate::bindings::LNOffer>.unwrap();
let _: String = LNOffer.bolt12;
let _: String = LNOffer.offer;
let _: Vec<String> = LNOffer.chains;
let _: Option<crate::bindings::Amount> = LNOffer.min_amount;
let _: Option<String> = LNOffer.description;
Expand Down Expand Up @@ -2790,15 +2790,15 @@ impl SseDecode for crate::bindings::LNInvoice {
impl SseDecode for crate::bindings::LNOffer {
// Codec=Sse (Serialization based), see doc to use other codecs
fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self {
let mut var_bolt12 = <String>::sse_decode(deserializer);
let mut var_offer = <String>::sse_decode(deserializer);
let mut var_chains = <Vec<String>>::sse_decode(deserializer);
let mut var_minAmount = <Option<crate::bindings::Amount>>::sse_decode(deserializer);
let mut var_description = <Option<String>>::sse_decode(deserializer);
let mut var_absoluteExpiry = <Option<u64>>::sse_decode(deserializer);
let mut var_issuer = <Option<String>>::sse_decode(deserializer);
let mut var_signingPubkey = <Option<String>>::sse_decode(deserializer);
return crate::bindings::LNOffer {
bolt12: var_bolt12,
offer: var_offer,
chains: var_chains,
min_amount: var_minAmount,
description: var_description,
Expand Down Expand Up @@ -4814,7 +4814,7 @@ impl flutter_rust_bridge::IntoIntoDart<FrbWrapper<crate::bindings::LNInvoice>>
impl flutter_rust_bridge::IntoDart for FrbWrapper<crate::bindings::LNOffer> {
fn into_dart(self) -> flutter_rust_bridge::for_generated::DartAbi {
[
self.0.bolt12.into_into_dart().into_dart(),
self.0.offer.into_into_dart().into_dart(),
self.0.chains.into_into_dart().into_dart(),
self.0.min_amount.into_into_dart().into_dart(),
self.0.description.into_into_dart().into_dart(),
Expand Down Expand Up @@ -6837,7 +6837,7 @@ impl SseEncode for crate::bindings::LNInvoice {
impl SseEncode for crate::bindings::LNOffer {
// Codec=Sse (Serialization based), see doc to use other codecs
fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) {
<String>::sse_encode(self.bolt12, serializer);
<String>::sse_encode(self.offer, serializer);
<Vec<String>>::sse_encode(self.chains, serializer);
<Option<crate::bindings::Amount>>::sse_encode(self.min_amount, serializer);
<Option<String>>::sse_encode(self.description, serializer);
Expand Down Expand Up @@ -8851,7 +8851,7 @@ mod io {
// Codec=Cst (C-struct based), see doc to use other codecs
fn cst_decode(self) -> crate::bindings::LNOffer {
crate::bindings::LNOffer {
bolt12: self.bolt12.cst_decode(),
offer: self.offer.cst_decode(),
chains: self.chains.cst_decode(),
min_amount: self.min_amount.cst_decode(),
description: self.description.cst_decode(),
Expand Down Expand Up @@ -10124,7 +10124,7 @@ mod io {
impl NewWithNullPtr for wire_cst_ln_offer {
fn new_with_null_ptr() -> Self {
Self {
bolt12: core::ptr::null_mut(),
offer: core::ptr::null_mut(),
chains: core::ptr::null_mut(),
min_amount: core::ptr::null_mut(),
description: core::ptr::null_mut(),
Expand Down Expand Up @@ -12162,7 +12162,7 @@ mod io {
#[repr(C)]
#[derive(Clone, Copy)]
pub struct wire_cst_ln_offer {
bolt12: *mut wire_cst_list_prim_u_8_strict,
offer: *mut wire_cst_list_prim_u_8_strict,
chains: *mut wire_cst_list_String,
min_amount: *mut wire_cst_amount,
description: *mut wire_cst_list_prim_u_8_strict,
Expand Down
47 changes: 28 additions & 19 deletions lib/core/src/sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,7 @@ impl LiquidSdk {
} => {
let bolt12_invoice = self
.swapper
.get_bolt12_invoice(&offer.bolt12, *receiver_amount_sat)?;
.get_bolt12_invoice(&offer.offer, *receiver_amount_sat)?;
self.pay_bolt12_invoice(&bolt12_invoice, *fees_sat).await
}
}
Expand Down Expand Up @@ -2585,31 +2585,40 @@ impl LiquidSdk {
/// Parses a string into an [InputType]. See [input_parser::parse].
pub async fn parse(input: &str) -> Result<InputType, PaymentError> {
if let Ok(offer) = input.parse::<Offer>() {
// TODO This conversion (between lightning-v0.0.125 to -v0.0.118 Amount types)
// won't be needed when Liquid SDK uses the same lightning crate version as sdk-common
let min_amount = offer
.amount()
.map(|amount| match amount {
::lightning::offers::offer::Amount::Bitcoin { amount_msats } => {
Ok(Amount::Bitcoin {
amount_msat: amount_msats,
})
}
::lightning::offers::offer::Amount::Currency {
iso4217_code,
amount,
} => Ok(Amount::Currency {
iso4217_code: String::from_utf8(iso4217_code.to_vec()).map_err(|_| {
anyhow!("Expecting a valid ISO 4217 character sequence")
})?,
fractional_amount: amount,
}),
})
.transpose()
.map_err(|e: anyhow::Error| {
PaymentError::generic(&format!("Failed to reconstruct amount: {e:?}"))
})?;

return Ok(InputType::Bolt12Offer {
offer: LNOffer {
bolt12: input.to_string(),
offer: input.to_string(),
chains: offer
.chains()
.iter()
.map(|chain| chain.to_string())
.collect(),
// TODO This conversion (between lightning-v0.0.125 to -v0.0.118 Amount types)
// won't be needed when Liquid SDK uses the same lightning crate version as sdk-common
min_amount: offer.amount().map(|amount| match amount {
::lightning::offers::offer::Amount::Bitcoin { amount_msats } => {
Amount::Bitcoin {
amount_msat: amount_msats,
}
}
::lightning::offers::offer::Amount::Currency {
iso4217_code,
amount,
} => Amount::Currency {
iso4217_code: String::from_utf8(iso4217_code.to_vec())
.expect("Expecting a valid ISO 4217 character sequence"),
fractional_amount: amount,
},
}),
min_amount,
description: offer.description().map(|d| d.to_string()),
absolute_expiry: offer.absolute_expiry().map(|expiry| expiry.as_secs()),
issuer: offer.issuer().map(|s| s.to_string()),
Expand Down
8 changes: 4 additions & 4 deletions packages/dart/lib/src/bindings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ class LNInvoice {
}

class LNOffer {
final String bolt12;
final String offer;
final List<String> chains;
final Amount? minAmount;
final String? description;
Expand All @@ -429,7 +429,7 @@ class LNOffer {
final String? signingPubkey;

const LNOffer({
required this.bolt12,
required this.offer,
required this.chains,
this.minAmount,
this.description,
Expand All @@ -440,7 +440,7 @@ class LNOffer {

@override
int get hashCode =>
bolt12.hashCode ^
offer.hashCode ^
chains.hashCode ^
minAmount.hashCode ^
description.hashCode ^
Expand All @@ -453,7 +453,7 @@ class LNOffer {
identical(this, other) ||
other is LNOffer &&
runtimeType == other.runtimeType &&
bolt12 == other.bolt12 &&
offer == other.offer &&
chains == other.chains &&
minAmount == other.minAmount &&
description == other.description &&
Expand Down
8 changes: 4 additions & 4 deletions packages/dart/lib/src/frb_generated.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1997,7 +1997,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
final arr = raw as List<dynamic>;
if (arr.length != 7) throw Exception('unexpected arr length: expect 7 but see ${arr.length}');
return LNOffer(
bolt12: dco_decode_String(arr[0]),
offer: dco_decode_String(arr[0]),
chains: dco_decode_list_String(arr[1]),
minAmount: dco_decode_opt_box_autoadd_amount(arr[2]),
description: dco_decode_opt_String(arr[3]),
Expand Down Expand Up @@ -3916,15 +3916,15 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
@protected
LNOffer sse_decode_ln_offer(SseDeserializer deserializer) {
// Codec=Sse (Serialization based), see doc to use other codecs
var var_bolt12 = sse_decode_String(deserializer);
var var_offer = sse_decode_String(deserializer);
var var_chains = sse_decode_list_String(deserializer);
var var_minAmount = sse_decode_opt_box_autoadd_amount(deserializer);
var var_description = sse_decode_opt_String(deserializer);
var var_absoluteExpiry = sse_decode_opt_box_autoadd_u_64(deserializer);
var var_issuer = sse_decode_opt_String(deserializer);
var var_signingPubkey = sse_decode_opt_String(deserializer);
return LNOffer(
bolt12: var_bolt12,
offer: var_offer,
chains: var_chains,
minAmount: var_minAmount,
description: var_description,
Expand Down Expand Up @@ -5818,7 +5818,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
@protected
void sse_encode_ln_offer(LNOffer self, SseSerializer serializer) {
// Codec=Sse (Serialization based), see doc to use other codecs
sse_encode_String(self.bolt12, serializer);
sse_encode_String(self.offer, serializer);
sse_encode_list_String(self.chains, serializer);
sse_encode_opt_box_autoadd_amount(self.minAmount, serializer);
sse_encode_opt_String(self.description, serializer);
Expand Down
4 changes: 2 additions & 2 deletions packages/dart/lib/src/frb_generated.io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2307,7 +2307,7 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {

@protected
void cst_api_fill_to_wire_ln_offer(LNOffer apiObj, wire_cst_ln_offer wireObj) {
wireObj.bolt12 = cst_encode_String(apiObj.bolt12);
wireObj.offer = cst_encode_String(apiObj.offer);
wireObj.chains = cst_encode_list_String(apiObj.chains);
wireObj.min_amount = cst_encode_opt_box_autoadd_amount(apiObj.minAmount);
wireObj.description = cst_encode_opt_String(apiObj.description);
Expand Down Expand Up @@ -5444,7 +5444,7 @@ final class wire_cst_amount extends ffi.Struct {
}

final class wire_cst_ln_offer extends ffi.Struct {
external ffi.Pointer<wire_cst_list_prim_u_8_strict> bolt12;
external ffi.Pointer<wire_cst_list_prim_u_8_strict> offer;

external ffi.Pointer<wire_cst_list_String> chains;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -568,26 +568,26 @@ fun asLnOffer(lnOffer: ReadableMap): LnOffer? {
if (!validateMandatoryFields(
lnOffer,
arrayOf(
"bolt12",
"offer",
"chains",
),
)
) {
return null
}
val bolt12 = lnOffer.getString("bolt12")!!
val offer = lnOffer.getString("offer")!!
val chains = lnOffer.getArray("chains")?.let { asStringList(it) }!!
val description = if (hasNonNullKey(lnOffer, "description")) lnOffer.getString("description") else null
val signingPubkey = if (hasNonNullKey(lnOffer, "signingPubkey")) lnOffer.getString("signingPubkey") else null
val minAmount = if (hasNonNullKey(lnOffer, "minAmount")) lnOffer.getMap("minAmount")?.let { asAmount(it) } else null
val absoluteExpiry = if (hasNonNullKey(lnOffer, "absoluteExpiry")) lnOffer.getDouble("absoluteExpiry").toULong() else null
val issuer = if (hasNonNullKey(lnOffer, "issuer")) lnOffer.getString("issuer") else null
return LnOffer(bolt12, chains, description, signingPubkey, minAmount, absoluteExpiry, issuer)
return LnOffer(offer, chains, description, signingPubkey, minAmount, absoluteExpiry, issuer)
}

fun readableMapOf(lnOffer: LnOffer): ReadableMap =
readableMapOf(
"bolt12" to lnOffer.bolt12,
"offer" to lnOffer.offer,
"chains" to readableArrayOf(lnOffer.chains),
"description" to lnOffer.description,
"signingPubkey" to lnOffer.signingPubkey,
Expand Down
8 changes: 4 additions & 4 deletions packages/react-native/ios/BreezSDKLiquidMapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -666,8 +666,8 @@ enum BreezSDKLiquidMapper {
}

static func asLnOffer(lnOffer: [String: Any?]) throws -> LnOffer {
guard let bolt12 = lnOffer["bolt12"] as? String else {
throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "bolt12", typeName: "LnOffer"))
guard let offer = lnOffer["offer"] as? String else {
throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "offer", typeName: "LnOffer"))
}
guard let chains = lnOffer["chains"] as? [String] else {
throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "chains", typeName: "LnOffer"))
Expand Down Expand Up @@ -706,12 +706,12 @@ enum BreezSDKLiquidMapper {
issuer = issuerTmp
}

return LnOffer(bolt12: bolt12, chains: chains, description: description, signingPubkey: signingPubkey, minAmount: minAmount, absoluteExpiry: absoluteExpiry, issuer: issuer)
return LnOffer(offer: offer, chains: chains, description: description, signingPubkey: signingPubkey, minAmount: minAmount, absoluteExpiry: absoluteExpiry, issuer: issuer)
}

static func dictionaryOf(lnOffer: LnOffer) -> [String: Any?] {
return [
"bolt12": lnOffer.bolt12,
"offer": lnOffer.offer,
"chains": lnOffer.chains,
"description": lnOffer.description == nil ? nil : lnOffer.description,
"signingPubkey": lnOffer.signingPubkey == nil ? nil : lnOffer.signingPubkey,
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export interface LnInvoice {
}

export interface LnOffer {
bolt12: string
offer: string
chains: string[]
description?: string
signingPubkey?: string
Expand Down

0 comments on commit 10fbefa

Please sign in to comment.