Skip to content

Commit

Permalink
Correct comments and make address optional
Browse files Browse the repository at this point in the history
  • Loading branch information
dangeross committed Jan 8, 2025
1 parent c7500f9 commit 7f338e7
Show file tree
Hide file tree
Showing 12 changed files with 61 additions and 41 deletions.
15 changes: 9 additions & 6 deletions cli/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ pub(crate) enum Command {
#[arg(long)]
address: Option<String>,

/// The amount in satoshi to pay, in case of a direct Liquid address
/// or amount-less BIP21
/// The amount to pay, in case of a direct Liquid address or amount-less BIP21.
/// If an asset id is provided, it is the base unit of that asset depending on its
/// precision, otherwise in satoshi.
#[arg(short, long)]
receiver_amount: Option<u64>,

Expand Down Expand Up @@ -77,9 +78,9 @@ pub(crate) enum Command {
#[arg(short = 'm', long = "method")]
payment_method: Option<PaymentMethod>,

/// Amount the payer will send, in satoshi. If receiving a non Liquid Bitcoin
/// asset, this is the units of the asset to receive.
/// If not specified, it will generate a BIP21 URI/Liquid address with no amount
/// The amount the payer should send. If an asset id is provided, it is the base
/// unit of that asset depending on its precision, otherwise in satoshi.
/// If not specified, it will generate a BIP21 URI/address with no amount.
#[arg(short, long)]
payer_amount: Option<u64>,

Expand Down Expand Up @@ -530,7 +531,9 @@ pub(crate) async fn handle_command(
destination,
})
}
(None, None, Some(address)) => Some(ListPaymentDetails::Bitcoin { address }),
(None, None, Some(address)) => Some(ListPaymentDetails::Bitcoin {
address: Some(address),
}),
_ => None,
};

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 @@ -557,7 +557,7 @@ dictionary ListPaymentsRequest {
[Enum]
interface ListPaymentDetails {
Liquid(string? asset_id, string? destination);
Bitcoin(string address);
Bitcoin(string? address);
};

[Enum]
Expand Down
4 changes: 2 additions & 2 deletions lib/core/src/frb_generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2908,7 +2908,7 @@ impl SseDecode for crate::model::ListPaymentDetails {
};
}
1 => {
let mut var_address = <String>::sse_decode(deserializer);
let mut var_address = <Option<String>>::sse_decode(deserializer);
return crate::model::ListPaymentDetails::Bitcoin {
address: var_address,
};
Expand Down Expand Up @@ -7527,7 +7527,7 @@ impl SseEncode for crate::model::ListPaymentDetails {
}
crate::model::ListPaymentDetails::Bitcoin { address } => {
<i32>::sse_encode(1, serializer);
<String>::sse_encode(address, serializer);
<Option<String>>::sse_encode(address, serializer);
}
_ => {
unimplemented!("");
Expand Down
11 changes: 8 additions & 3 deletions lib/core/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -694,14 +694,19 @@ pub struct ListPaymentsRequest {
/// An argument of [ListPaymentsRequest] when calling [crate::sdk::LiquidSdk::list_payments].
#[derive(Debug, Serialize)]
pub enum ListPaymentDetails {
/// The Liquid BIP21 URI or address of the payment
/// A Liquid payment
Liquid {
/// Optional asset id
asset_id: Option<String>,
/// Optional BIP21 URI or address
destination: Option<String>,
},

/// The Bitcoin address of the payment
Bitcoin { address: String },
/// A Bitcoin payment
Bitcoin {
/// Optional address
address: Option<String>,
},
}

/// An argument when calling [crate::sdk::LiquidSdk::get_payment].
Expand Down
16 changes: 9 additions & 7 deletions lib/core/src/persist/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -854,14 +854,16 @@ fn filter_to_where_clause(req: &ListPaymentsRequest) -> (String, Vec<Box<dyn ToS
if let Some(details) = &req.details {
match details {
ListPaymentDetails::Bitcoin { address } => {
// Use the lockup address if it's incoming, else use the claim address
where_clause.push("cs.id IS NOT NULL".to_string());
where_clause.push(
"(cs.direction = 0 AND cs.lockup_address = ? OR cs.direction = 1 AND cs.claim_address = ?)"
.to_string(),
);
where_params.push(Box::new(address));
where_params.push(Box::new(address));
if let Some(address) = address {
// Use the lockup address if it's incoming, else use the claim address
where_clause.push(
"(cs.direction = 0 AND cs.lockup_address = ? OR cs.direction = 1 AND cs.claim_address = ?)"
.to_string(),
);
where_params.push(Box::new(address));
where_params.push(Box::new(address));
}
}
ListPaymentDetails::Liquid {
asset_id,
Expand Down
6 changes: 3 additions & 3 deletions packages/dart/lib/src/frb_generated.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2093,7 +2093,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
);
case 1:
return ListPaymentDetails_Bitcoin(
address: dco_decode_String(raw[1]),
address: dco_decode_opt_String(raw[1]),
);
default:
throw Exception("unreachable");
Expand Down Expand Up @@ -4219,7 +4219,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
var var_destination = sse_decode_opt_String(deserializer);
return ListPaymentDetails_Liquid(assetId: var_assetId, destination: var_destination);
case 1:
var var_address = sse_decode_String(deserializer);
var var_address = sse_decode_opt_String(deserializer);
return ListPaymentDetails_Bitcoin(address: var_address);
default:
throw UnimplementedError('');
Expand Down Expand Up @@ -6428,7 +6428,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
sse_encode_opt_String(destination, serializer);
case ListPaymentDetails_Bitcoin(address: final address):
sse_encode_i_32(1, serializer);
sse_encode_String(address, serializer);
sse_encode_opt_String(address, serializer);
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/dart/lib/src/frb_generated.io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2605,7 +2605,7 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
return;
}
if (apiObj is ListPaymentDetails_Bitcoin) {
var pre_address = cst_encode_String(apiObj.address);
var pre_address = cst_encode_opt_String(apiObj.address);
wireObj.tag = 1;
wireObj.kind.Bitcoin.address = pre_address;
return;
Expand Down
10 changes: 7 additions & 3 deletions packages/dart/lib/src/model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -451,15 +451,19 @@ enum LiquidNetwork {
sealed class ListPaymentDetails with _$ListPaymentDetails {
const ListPaymentDetails._();

/// The Liquid BIP21 URI or address of the payment
/// A Liquid payment
const factory ListPaymentDetails.liquid({
/// Optional asset id
String? assetId,

/// Optional BIP21 URI or address
String? destination,
}) = ListPaymentDetails_Liquid;

/// The Bitcoin address of the payment
/// A Bitcoin payment
const factory ListPaymentDetails.bitcoin({
required String address,
/// Optional address
String? address,
}) = ListPaymentDetails_Bitcoin;
}

Expand Down
25 changes: 16 additions & 9 deletions packages/dart/lib/src/model.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,11 @@ class __$$ListPaymentDetails_LiquidImplCopyWithImpl<$Res>
class _$ListPaymentDetails_LiquidImpl extends ListPaymentDetails_Liquid {
const _$ListPaymentDetails_LiquidImpl({this.assetId, this.destination}) : super._();

/// Optional asset id
@override
final String? assetId;

/// Optional BIP21 URI or address
@override
final String? destination;

Expand Down Expand Up @@ -243,7 +246,10 @@ abstract class ListPaymentDetails_Liquid extends ListPaymentDetails {
_$ListPaymentDetails_LiquidImpl;
const ListPaymentDetails_Liquid._() : super._();

/// Optional asset id
String? get assetId;

/// Optional BIP21 URI or address
String? get destination;

/// Create a copy of ListPaymentDetails
Expand All @@ -259,7 +265,7 @@ abstract class _$$ListPaymentDetails_BitcoinImplCopyWith<$Res> {
_$ListPaymentDetails_BitcoinImpl value, $Res Function(_$ListPaymentDetails_BitcoinImpl) then) =
__$$ListPaymentDetails_BitcoinImplCopyWithImpl<$Res>;
@useResult
$Res call({String address});
$Res call({String? address});
}

/// @nodoc
Expand All @@ -275,24 +281,25 @@ class __$$ListPaymentDetails_BitcoinImplCopyWithImpl<$Res>
@pragma('vm:prefer-inline')
@override
$Res call({
Object? address = null,
Object? address = freezed,
}) {
return _then(_$ListPaymentDetails_BitcoinImpl(
address: null == address
address: freezed == address
? _value.address
: address // ignore: cast_nullable_to_non_nullable
as String,
as String?,
));
}
}

/// @nodoc
class _$ListPaymentDetails_BitcoinImpl extends ListPaymentDetails_Bitcoin {
const _$ListPaymentDetails_BitcoinImpl({required this.address}) : super._();
const _$ListPaymentDetails_BitcoinImpl({this.address}) : super._();

/// Optional address
@override
final String address;
final String? address;

@override
String toString() {
Expand Down Expand Up @@ -320,11 +327,11 @@ class _$ListPaymentDetails_BitcoinImpl extends ListPaymentDetails_Bitcoin {
}

abstract class ListPaymentDetails_Bitcoin extends ListPaymentDetails {
const factory ListPaymentDetails_Bitcoin({required final String address}) =
_$ListPaymentDetails_BitcoinImpl;
const factory ListPaymentDetails_Bitcoin({final String? address}) = _$ListPaymentDetails_BitcoinImpl;
const ListPaymentDetails_Bitcoin._() : super._();

String get address;
/// Optional address
String? get address;

/// Create a copy of ListPaymentDetails
/// with the given fields replaced by the non-null parameter values.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3048,7 +3048,7 @@ fun asListPaymentDetails(listPaymentDetails: ReadableMap): ListPaymentDetails? {
return ListPaymentDetails.Liquid(assetId, destination)
}
if (type == "bitcoin") {
val address = listPaymentDetails.getString("address")!!
val address = if (hasNonNullKey(listPaymentDetails, "address")) listPaymentDetails.getString("address") else null
return ListPaymentDetails.Bitcoin(address)
}
return null
Expand Down
7 changes: 3 additions & 4 deletions packages/react-native/ios/BreezSDKLiquidMapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3624,9 +3624,8 @@ enum BreezSDKLiquidMapper {
return ListPaymentDetails.liquid(assetId: _assetId, destination: _destination)
}
if type == "bitcoin" {
guard let _address = listPaymentDetails["address"] as? String else {
throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "address", typeName: "ListPaymentDetails"))
}
let _address = listPaymentDetails["address"] as? String

return ListPaymentDetails.bitcoin(address: _address)
}

Expand All @@ -3649,7 +3648,7 @@ enum BreezSDKLiquidMapper {
):
return [
"type": "bitcoin",
"address": address,
"address": address == nil ? nil : address,
]
}
}
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 @@ -571,7 +571,7 @@ export type ListPaymentDetails = {
destination?: string
} | {
type: ListPaymentDetailsVariant.BITCOIN,
address: string
address?: string
}

export enum LnUrlCallbackStatusVariant {
Expand Down

0 comments on commit 7f338e7

Please sign in to comment.