Skip to content

Commit

Permalink
Rename PayOnchainAmount to PayAmount
Browse files Browse the repository at this point in the history
  • Loading branch information
dangeross committed Nov 11, 2024
1 parent 81ad0fb commit e367277
Show file tree
Hide file tree
Showing 14 changed files with 246 additions and 265 deletions.
8 changes: 4 additions & 4 deletions cli/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,8 @@ pub(crate) async fn handle_command(
}
};
let amount = match (amount_sat, drain.unwrap_or(false)) {
(Some(amount_sat), _) => Some(PayOnchainAmount::Receiver { amount_sat }),
(_, true) => Some(PayOnchainAmount::Drain),
(Some(amount_sat), _) => Some(PayAmount::Receiver { amount_sat }),
(_, true) => Some(PayAmount::Drain),
(_, _) => None,
};

Expand Down Expand Up @@ -376,8 +376,8 @@ pub(crate) async fn handle_command(
fee_rate_sat_per_vbyte,
} => {
let amount = match drain.unwrap_or(false) {
true => PayOnchainAmount::Drain,
false => PayOnchainAmount::Receiver {
true => PayAmount::Drain,
false => PayAmount::Receiver {
amount_sat: receiver_amount_sat.ok_or(anyhow::anyhow!(
"Must specify `receiver_amount_sat` if not draining"
))?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,21 +279,21 @@ typedef struct wire_cst_prepare_ln_url_pay_request {
bool *validate_success_action_url;
} wire_cst_prepare_ln_url_pay_request;

typedef struct wire_cst_PayOnchainAmount_Receiver {
typedef struct wire_cst_PayAmount_Receiver {
uint64_t amount_sat;
} wire_cst_PayOnchainAmount_Receiver;
} wire_cst_PayAmount_Receiver;

typedef union PayOnchainAmountKind {
struct wire_cst_PayOnchainAmount_Receiver Receiver;
} PayOnchainAmountKind;
typedef union PayAmountKind {
struct wire_cst_PayAmount_Receiver Receiver;
} PayAmountKind;

typedef struct wire_cst_pay_onchain_amount {
typedef struct wire_cst_pay_amount {
int32_t tag;
union PayOnchainAmountKind kind;
} wire_cst_pay_onchain_amount;
union PayAmountKind kind;
} wire_cst_pay_amount;

typedef struct wire_cst_prepare_pay_onchain_request {
struct wire_cst_pay_onchain_amount amount;
struct wire_cst_pay_amount amount;
uint32_t *fee_rate_sat_per_vbyte;
} wire_cst_prepare_pay_onchain_request;

Expand All @@ -310,7 +310,7 @@ typedef struct wire_cst_prepare_refund_request {

typedef struct wire_cst_prepare_send_request {
struct wire_cst_list_prim_u_8_strict *destination;
struct wire_cst_pay_onchain_amount *amount;
struct wire_cst_pay_amount *amount;
} wire_cst_prepare_send_request;

typedef struct wire_cst_prepare_receive_response {
Expand Down Expand Up @@ -1166,7 +1166,7 @@ struct wire_cst_ln_url_withdraw_success_data *frbgen_breez_liquid_cst_new_box_au

struct wire_cst_message_success_action_data *frbgen_breez_liquid_cst_new_box_autoadd_message_success_action_data(void);

struct wire_cst_pay_onchain_amount *frbgen_breez_liquid_cst_new_box_autoadd_pay_onchain_amount(void);
struct wire_cst_pay_amount *frbgen_breez_liquid_cst_new_box_autoadd_pay_amount(void);

struct wire_cst_pay_onchain_request *frbgen_breez_liquid_cst_new_box_autoadd_pay_onchain_request(void);

Expand Down Expand Up @@ -1255,7 +1255,7 @@ static int64_t dummy_method_to_enforce_bundling(void) {
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_cst_new_box_autoadd_ln_url_withdraw_request_data);
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_cst_new_box_autoadd_ln_url_withdraw_success_data);
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_cst_new_box_autoadd_message_success_action_data);
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_cst_new_box_autoadd_pay_onchain_amount);
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_cst_new_box_autoadd_pay_amount);
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_cst_new_box_autoadd_pay_onchain_request);
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_cst_new_box_autoadd_payment);
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_cst_new_box_autoadd_prepare_buy_bitcoin_request);
Expand Down
6 changes: 3 additions & 3 deletions lib/bindings/src/breez_sdk_liquid.udl
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ dictionary LnUrlPayRequest {

dictionary PrepareSendRequest {
string destination;
PayOnchainAmount? amount = null;
PayAmount? amount = null;
};

[Enum]
Expand Down Expand Up @@ -439,13 +439,13 @@ dictionary OnchainPaymentLimitsResponse {
};

[Enum]
interface PayOnchainAmount {
interface PayAmount {
Receiver(u64 amount_sat);
Drain();
};

dictionary PreparePayOnchainRequest {
PayOnchainAmount amount;
PayAmount amount;
u32? fee_rate_sat_per_vbyte = null;
};

Expand Down
85 changes: 40 additions & 45 deletions lib/core/src/frb_generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3180,11 +3180,11 @@ impl SseDecode for Option<crate::model::ListPaymentDetails> {
}
}

impl SseDecode for Option<crate::model::PayOnchainAmount> {
impl SseDecode for Option<crate::model::PayAmount> {
// Codec=Sse (Serialization based), see doc to use other codecs
fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self {
if (<bool>::sse_decode(deserializer)) {
return Some(<crate::model::PayOnchainAmount>::sse_decode(deserializer));
return Some(<crate::model::PayAmount>::sse_decode(deserializer));
} else {
return None;
}
Expand Down Expand Up @@ -3270,19 +3270,19 @@ impl SseDecode for Option<Vec<crate::model::PaymentType>> {
}
}

impl SseDecode for crate::model::PayOnchainAmount {
impl SseDecode for crate::model::PayAmount {
// Codec=Sse (Serialization based), see doc to use other codecs
fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self {
let mut tag_ = <i32>::sse_decode(deserializer);
match tag_ {
0 => {
let mut var_amountSat = <u64>::sse_decode(deserializer);
return crate::model::PayOnchainAmount::Receiver {
return crate::model::PayAmount::Receiver {
amount_sat: var_amountSat,
};
}
1 => {
return crate::model::PayOnchainAmount::Drain;
return crate::model::PayAmount::Drain;
}
_ => {
unimplemented!("");
Expand Down Expand Up @@ -3569,7 +3569,7 @@ impl SseDecode for crate::model::PrepareLnUrlPayResponse {
impl SseDecode for crate::model::PreparePayOnchainRequest {
// 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_amount = <crate::model::PayOnchainAmount>::sse_decode(deserializer);
let mut var_amount = <crate::model::PayAmount>::sse_decode(deserializer);
let mut var_feeRateSatPerVbyte = <Option<u32>>::sse_decode(deserializer);
return crate::model::PreparePayOnchainRequest {
amount: var_amount,
Expand Down Expand Up @@ -3650,7 +3650,7 @@ impl SseDecode for crate::model::PrepareSendRequest {
// 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_destination = <String>::sse_decode(deserializer);
let mut var_amount = <Option<crate::model::PayOnchainAmount>>::sse_decode(deserializer);
let mut var_amount = <Option<crate::model::PayAmount>>::sse_decode(deserializer);
return crate::model::PrepareSendRequest {
destination: var_destination,
amount: var_amount,
Expand Down Expand Up @@ -5180,27 +5180,22 @@ impl flutter_rust_bridge::IntoIntoDart<crate::model::OnchainPaymentLimitsRespons
}
}
// Codec=Dco (DartCObject based), see doc to use other codecs
impl flutter_rust_bridge::IntoDart for crate::model::PayOnchainAmount {
impl flutter_rust_bridge::IntoDart for crate::model::PayAmount {
fn into_dart(self) -> flutter_rust_bridge::for_generated::DartAbi {
match self {
crate::model::PayOnchainAmount::Receiver { amount_sat } => {
crate::model::PayAmount::Receiver { amount_sat } => {
[0.into_dart(), amount_sat.into_into_dart().into_dart()].into_dart()
}
crate::model::PayOnchainAmount::Drain => [1.into_dart()].into_dart(),
crate::model::PayAmount::Drain => [1.into_dart()].into_dart(),
_ => {
unimplemented!("");
}
}
}
}
impl flutter_rust_bridge::for_generated::IntoDartExceptPrimitive
for crate::model::PayOnchainAmount
{
}
impl flutter_rust_bridge::IntoIntoDart<crate::model::PayOnchainAmount>
for crate::model::PayOnchainAmount
{
fn into_into_dart(self) -> crate::model::PayOnchainAmount {
impl flutter_rust_bridge::for_generated::IntoDartExceptPrimitive for crate::model::PayAmount {}
impl flutter_rust_bridge::IntoIntoDart<crate::model::PayAmount> for crate::model::PayAmount {
fn into_into_dart(self) -> crate::model::PayAmount {
self
}
}
Expand Down Expand Up @@ -6990,12 +6985,12 @@ impl SseEncode for Option<crate::model::ListPaymentDetails> {
}
}

impl SseEncode for Option<crate::model::PayOnchainAmount> {
impl SseEncode for Option<crate::model::PayAmount> {
// Codec=Sse (Serialization based), see doc to use other codecs
fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) {
<bool>::sse_encode(self.is_some(), serializer);
if let Some(value) = self {
<crate::model::PayOnchainAmount>::sse_encode(value, serializer);
<crate::model::PayAmount>::sse_encode(value, serializer);
}
}
}
Expand Down Expand Up @@ -7070,15 +7065,15 @@ impl SseEncode for Option<Vec<crate::model::PaymentType>> {
}
}

impl SseEncode for crate::model::PayOnchainAmount {
impl SseEncode for crate::model::PayAmount {
// Codec=Sse (Serialization based), see doc to use other codecs
fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) {
match self {
crate::model::PayOnchainAmount::Receiver { amount_sat } => {
crate::model::PayAmount::Receiver { amount_sat } => {
<i32>::sse_encode(0, serializer);
<u64>::sse_encode(amount_sat, serializer);
}
crate::model::PayOnchainAmount::Drain => {
crate::model::PayAmount::Drain => {
<i32>::sse_encode(1, serializer);
}
_ => {
Expand Down Expand Up @@ -7337,7 +7332,7 @@ impl SseEncode for crate::model::PrepareLnUrlPayResponse {
impl SseEncode for crate::model::PreparePayOnchainRequest {
// Codec=Sse (Serialization based), see doc to use other codecs
fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) {
<crate::model::PayOnchainAmount>::sse_encode(self.amount, serializer);
<crate::model::PayAmount>::sse_encode(self.amount, serializer);
<Option<u32>>::sse_encode(self.fee_rate_sat_per_vbyte, serializer);
}
}
Expand Down Expand Up @@ -7390,7 +7385,7 @@ impl SseEncode for crate::model::PrepareSendRequest {
// 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.destination, serializer);
<Option<crate::model::PayOnchainAmount>>::sse_encode(self.amount, serializer);
<Option<crate::model::PayAmount>>::sse_encode(self.amount, serializer);
}
}

Expand Down Expand Up @@ -8057,11 +8052,11 @@ mod io {
CstDecode::<crate::bindings::MessageSuccessActionData>::cst_decode(*wrap).into()
}
}
impl CstDecode<crate::model::PayOnchainAmount> for *mut wire_cst_pay_onchain_amount {
impl CstDecode<crate::model::PayAmount> for *mut wire_cst_pay_amount {
// Codec=Cst (C-struct based), see doc to use other codecs
fn cst_decode(self) -> crate::model::PayOnchainAmount {
fn cst_decode(self) -> crate::model::PayAmount {
let wrap = unsafe { flutter_rust_bridge::for_generated::box_from_leak_ptr(self) };
CstDecode::<crate::model::PayOnchainAmount>::cst_decode(*wrap).into()
CstDecode::<crate::model::PayAmount>::cst_decode(*wrap).into()
}
}
impl CstDecode<crate::model::PayOnchainRequest> for *mut wire_cst_pay_onchain_request {
Expand Down Expand Up @@ -8912,17 +8907,17 @@ mod io {
}
}
}
impl CstDecode<crate::model::PayOnchainAmount> for wire_cst_pay_onchain_amount {
impl CstDecode<crate::model::PayAmount> for wire_cst_pay_amount {
// Codec=Cst (C-struct based), see doc to use other codecs
fn cst_decode(self) -> crate::model::PayOnchainAmount {
fn cst_decode(self) -> crate::model::PayAmount {
match self.tag {
0 => {
let ans = unsafe { self.kind.Receiver };
crate::model::PayOnchainAmount::Receiver {
crate::model::PayAmount::Receiver {
amount_sat: ans.amount_sat.cst_decode(),
}
}
1 => crate::model::PayOnchainAmount::Drain,
1 => crate::model::PayAmount::Drain,
_ => unreachable!(),
}
}
Expand Down Expand Up @@ -10064,15 +10059,15 @@ mod io {
Self::new_with_null_ptr()
}
}
impl NewWithNullPtr for wire_cst_pay_onchain_amount {
impl NewWithNullPtr for wire_cst_pay_amount {
fn new_with_null_ptr() -> Self {
Self {
tag: -1,
kind: PayOnchainAmountKind { nil__: () },
kind: PayAmountKind { nil__: () },
}
}
}
impl Default for wire_cst_pay_onchain_amount {
impl Default for wire_cst_pay_amount {
fn default() -> Self {
Self::new_with_null_ptr()
}
Expand Down Expand Up @@ -11137,10 +11132,10 @@ mod io {
}

#[no_mangle]
pub extern "C" fn frbgen_breez_liquid_cst_new_box_autoadd_pay_onchain_amount(
) -> *mut wire_cst_pay_onchain_amount {
pub extern "C" fn frbgen_breez_liquid_cst_new_box_autoadd_pay_amount(
) -> *mut wire_cst_pay_amount {
flutter_rust_bridge::for_generated::new_leak_box_ptr(
wire_cst_pay_onchain_amount::new_with_null_ptr(),
wire_cst_pay_amount::new_with_null_ptr(),
)
}

Expand Down Expand Up @@ -12078,19 +12073,19 @@ mod io {
}
#[repr(C)]
#[derive(Clone, Copy)]
pub struct wire_cst_pay_onchain_amount {
pub struct wire_cst_pay_amount {
tag: i32,
kind: PayOnchainAmountKind,
kind: PayAmountKind,
}
#[repr(C)]
#[derive(Clone, Copy)]
pub union PayOnchainAmountKind {
Receiver: wire_cst_PayOnchainAmount_Receiver,
pub union PayAmountKind {
Receiver: wire_cst_PayAmount_Receiver,
nil__: (),
}
#[repr(C)]
#[derive(Clone, Copy)]
pub struct wire_cst_PayOnchainAmount_Receiver {
pub struct wire_cst_PayAmount_Receiver {
amount_sat: u64,
}
#[repr(C)]
Expand Down Expand Up @@ -12253,7 +12248,7 @@ mod io {
#[repr(C)]
#[derive(Clone, Copy)]
pub struct wire_cst_prepare_pay_onchain_request {
amount: wire_cst_pay_onchain_amount,
amount: wire_cst_pay_amount,
fee_rate_sat_per_vbyte: *mut u32,
}
#[repr(C)]
Expand Down Expand Up @@ -12294,7 +12289,7 @@ mod io {
#[derive(Clone, Copy)]
pub struct wire_cst_prepare_send_request {
destination: *mut wire_cst_list_prim_u_8_strict,
amount: *mut wire_cst_pay_onchain_amount,
amount: *mut wire_cst_pay_amount,
}
#[repr(C)]
#[derive(Clone, Copy)]
Expand Down
6 changes: 3 additions & 3 deletions lib/core/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ pub struct PrepareSendRequest {

/// Should only be set when paying directly onchain or to a BIP21 URI
/// where no amount is specified, or when the caller wishes to drain
pub amount: Option<PayOnchainAmount>,
pub amount: Option<PayAmount>,
}

/// Specifies the supported destinations which can be payed by the SDK
Expand Down Expand Up @@ -384,7 +384,7 @@ pub struct SendPaymentResponse {
}

#[derive(Debug, Serialize, Clone)]
pub enum PayOnchainAmount {
pub enum PayAmount {
/// The amount in satoshi that will be received
Receiver { amount_sat: u64 },
/// Indicates that all available funds should be sent
Expand All @@ -394,7 +394,7 @@ pub enum PayOnchainAmount {
/// An argument when calling [crate::sdk::LiquidSdk::prepare_pay_onchain].
#[derive(Debug, Serialize, Clone)]
pub struct PreparePayOnchainRequest {
pub amount: PayOnchainAmount,
pub amount: PayAmount,
/// The optional fee rate of the Bitcoin claim transaction in sat/vB. Defaults to the swapper estimated claim fee.
pub fee_rate_sat_per_vbyte: Option<u32>,
}
Expand Down
Loading

0 comments on commit e367277

Please sign in to comment.