Skip to content

Commit

Permalink
Add SdkEvent for refundable swap (#683)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgranhao authored Jan 21, 2025
1 parent 0cdfa20 commit 6760960
Show file tree
Hide file tree
Showing 13 changed files with 221 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,10 @@ typedef struct wire_cst_SdkEvent_PaymentPending {
struct wire_cst_payment *details;
} wire_cst_SdkEvent_PaymentPending;

typedef struct wire_cst_SdkEvent_PaymentRefundable {
struct wire_cst_payment *details;
} wire_cst_SdkEvent_PaymentRefundable;

typedef struct wire_cst_SdkEvent_PaymentRefunded {
struct wire_cst_payment *details;
} wire_cst_SdkEvent_PaymentRefunded;
Expand All @@ -568,6 +572,7 @@ typedef struct wire_cst_SdkEvent_PaymentWaitingFeeAcceptance {
typedef union SdkEventKind {
struct wire_cst_SdkEvent_PaymentFailed PaymentFailed;
struct wire_cst_SdkEvent_PaymentPending PaymentPending;
struct wire_cst_SdkEvent_PaymentRefundable PaymentRefundable;
struct wire_cst_SdkEvent_PaymentRefunded PaymentRefunded;
struct wire_cst_SdkEvent_PaymentRefundPending PaymentRefundPending;
struct wire_cst_SdkEvent_PaymentSucceeded PaymentSucceeded;
Expand Down
1 change: 1 addition & 0 deletions lib/bindings/src/breez_sdk_liquid.udl
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,7 @@ dictionary RefundResponse {
interface SdkEvent {
PaymentFailed(Payment details);
PaymentPending(Payment details);
PaymentRefundable(Payment details);
PaymentRefunded(Payment details);
PaymentRefundPending(Payment details);
PaymentSucceeded(Payment details);
Expand Down
69 changes: 47 additions & 22 deletions lib/core/src/frb_generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4304,35 +4304,41 @@ impl SseDecode for crate::model::SdkEvent {
}
2 => {
let mut var_details = <crate::model::Payment>::sse_decode(deserializer);
return crate::model::SdkEvent::PaymentRefunded {
return crate::model::SdkEvent::PaymentRefundable {
details: var_details,
};
}
3 => {
let mut var_details = <crate::model::Payment>::sse_decode(deserializer);
return crate::model::SdkEvent::PaymentRefundPending {
return crate::model::SdkEvent::PaymentRefunded {
details: var_details,
};
}
4 => {
let mut var_details = <crate::model::Payment>::sse_decode(deserializer);
return crate::model::SdkEvent::PaymentSucceeded {
return crate::model::SdkEvent::PaymentRefundPending {
details: var_details,
};
}
5 => {
let mut var_details = <crate::model::Payment>::sse_decode(deserializer);
return crate::model::SdkEvent::PaymentWaitingConfirmation {
return crate::model::SdkEvent::PaymentSucceeded {
details: var_details,
};
}
6 => {
let mut var_details = <crate::model::Payment>::sse_decode(deserializer);
return crate::model::SdkEvent::PaymentWaitingFeeAcceptance {
return crate::model::SdkEvent::PaymentWaitingConfirmation {
details: var_details,
};
}
7 => {
let mut var_details = <crate::model::Payment>::sse_decode(deserializer);
return crate::model::SdkEvent::PaymentWaitingFeeAcceptance {
details: var_details,
};
}
8 => {
return crate::model::SdkEvent::Synced;
}
_ => {
Expand Down Expand Up @@ -6622,22 +6628,25 @@ impl flutter_rust_bridge::IntoDart for crate::model::SdkEvent {
crate::model::SdkEvent::PaymentPending { details } => {
[1.into_dart(), details.into_into_dart().into_dart()].into_dart()
}
crate::model::SdkEvent::PaymentRefunded { details } => {
crate::model::SdkEvent::PaymentRefundable { details } => {
[2.into_dart(), details.into_into_dart().into_dart()].into_dart()
}
crate::model::SdkEvent::PaymentRefundPending { details } => {
crate::model::SdkEvent::PaymentRefunded { details } => {
[3.into_dart(), details.into_into_dart().into_dart()].into_dart()
}
crate::model::SdkEvent::PaymentSucceeded { details } => {
crate::model::SdkEvent::PaymentRefundPending { details } => {
[4.into_dart(), details.into_into_dart().into_dart()].into_dart()
}
crate::model::SdkEvent::PaymentWaitingConfirmation { details } => {
crate::model::SdkEvent::PaymentSucceeded { details } => {
[5.into_dart(), details.into_into_dart().into_dart()].into_dart()
}
crate::model::SdkEvent::PaymentWaitingFeeAcceptance { details } => {
crate::model::SdkEvent::PaymentWaitingConfirmation { details } => {
[6.into_dart(), details.into_into_dart().into_dart()].into_dart()
}
crate::model::SdkEvent::Synced => [7.into_dart()].into_dart(),
crate::model::SdkEvent::PaymentWaitingFeeAcceptance { details } => {
[7.into_dart(), details.into_into_dart().into_dart()].into_dart()
}
crate::model::SdkEvent::Synced => [8.into_dart()].into_dart(),
_ => {
unimplemented!("");
}
Expand Down Expand Up @@ -8493,28 +8502,32 @@ impl SseEncode for crate::model::SdkEvent {
<i32>::sse_encode(1, serializer);
<crate::model::Payment>::sse_encode(details, serializer);
}
crate::model::SdkEvent::PaymentRefunded { details } => {
crate::model::SdkEvent::PaymentRefundable { details } => {
<i32>::sse_encode(2, serializer);
<crate::model::Payment>::sse_encode(details, serializer);
}
crate::model::SdkEvent::PaymentRefundPending { details } => {
crate::model::SdkEvent::PaymentRefunded { details } => {
<i32>::sse_encode(3, serializer);
<crate::model::Payment>::sse_encode(details, serializer);
}
crate::model::SdkEvent::PaymentSucceeded { details } => {
crate::model::SdkEvent::PaymentRefundPending { details } => {
<i32>::sse_encode(4, serializer);
<crate::model::Payment>::sse_encode(details, serializer);
}
crate::model::SdkEvent::PaymentWaitingConfirmation { details } => {
crate::model::SdkEvent::PaymentSucceeded { details } => {
<i32>::sse_encode(5, serializer);
<crate::model::Payment>::sse_encode(details, serializer);
}
crate::model::SdkEvent::PaymentWaitingFeeAcceptance { details } => {
crate::model::SdkEvent::PaymentWaitingConfirmation { details } => {
<i32>::sse_encode(6, serializer);
<crate::model::Payment>::sse_encode(details, serializer);
}
crate::model::SdkEvent::Synced => {
crate::model::SdkEvent::PaymentWaitingFeeAcceptance { details } => {
<i32>::sse_encode(7, serializer);
<crate::model::Payment>::sse_encode(details, serializer);
}
crate::model::SdkEvent::Synced => {
<i32>::sse_encode(8, serializer);
}
_ => {
unimplemented!("");
Expand Down Expand Up @@ -10543,36 +10556,42 @@ mod io {
}
}
2 => {
let ans = unsafe { self.kind.PaymentRefundable };
crate::model::SdkEvent::PaymentRefundable {
details: ans.details.cst_decode(),
}
}
3 => {
let ans = unsafe { self.kind.PaymentRefunded };
crate::model::SdkEvent::PaymentRefunded {
details: ans.details.cst_decode(),
}
}
3 => {
4 => {
let ans = unsafe { self.kind.PaymentRefundPending };
crate::model::SdkEvent::PaymentRefundPending {
details: ans.details.cst_decode(),
}
}
4 => {
5 => {
let ans = unsafe { self.kind.PaymentSucceeded };
crate::model::SdkEvent::PaymentSucceeded {
details: ans.details.cst_decode(),
}
}
5 => {
6 => {
let ans = unsafe { self.kind.PaymentWaitingConfirmation };
crate::model::SdkEvent::PaymentWaitingConfirmation {
details: ans.details.cst_decode(),
}
}
6 => {
7 => {
let ans = unsafe { self.kind.PaymentWaitingFeeAcceptance };
crate::model::SdkEvent::PaymentWaitingFeeAcceptance {
details: ans.details.cst_decode(),
}
}
7 => crate::model::SdkEvent::Synced,
8 => crate::model::SdkEvent::Synced,
_ => unreachable!(),
}
}
Expand Down Expand Up @@ -14048,6 +14067,7 @@ mod io {
pub union SdkEventKind {
PaymentFailed: wire_cst_SdkEvent_PaymentFailed,
PaymentPending: wire_cst_SdkEvent_PaymentPending,
PaymentRefundable: wire_cst_SdkEvent_PaymentRefundable,
PaymentRefunded: wire_cst_SdkEvent_PaymentRefunded,
PaymentRefundPending: wire_cst_SdkEvent_PaymentRefundPending,
PaymentSucceeded: wire_cst_SdkEvent_PaymentSucceeded,
Expand All @@ -14067,6 +14087,11 @@ mod io {
}
#[repr(C)]
#[derive(Clone, Copy)]
pub struct wire_cst_SdkEvent_PaymentRefundable {
details: *mut wire_cst_payment,
}
#[repr(C)]
#[derive(Clone, Copy)]
pub struct wire_cst_SdkEvent_PaymentRefunded {
details: *mut wire_cst_payment,
}
Expand Down
1 change: 1 addition & 0 deletions lib/core/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ pub trait EventListener: Send + Sync {
pub enum SdkEvent {
PaymentFailed { details: Payment },
PaymentPending { details: Payment },
PaymentRefundable { details: Payment },
PaymentRefunded { details: Payment },
PaymentRefundPending { details: Payment },
PaymentSucceeded { details: Payment },
Expand Down
6 changes: 6 additions & 0 deletions lib/core/src/sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,12 @@ impl LiquidSdk {
})
.await?;
}
Refundable => {
self.notify_event_listeners(SdkEvent::PaymentRefundable {
details: payment,
})
.await?
}
RefundPending => {
// The swap state has changed to RefundPending
self.notify_event_listeners(SdkEvent::PaymentRefundPending {
Expand Down
42 changes: 26 additions & 16 deletions packages/dart/lib/src/frb_generated.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3105,26 +3105,30 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
details: dco_decode_box_autoadd_payment(raw[1]),
);
case 2:
return SdkEvent_PaymentRefunded(
return SdkEvent_PaymentRefundable(
details: dco_decode_box_autoadd_payment(raw[1]),
);
case 3:
return SdkEvent_PaymentRefundPending(
return SdkEvent_PaymentRefunded(
details: dco_decode_box_autoadd_payment(raw[1]),
);
case 4:
return SdkEvent_PaymentSucceeded(
return SdkEvent_PaymentRefundPending(
details: dco_decode_box_autoadd_payment(raw[1]),
);
case 5:
return SdkEvent_PaymentWaitingConfirmation(
return SdkEvent_PaymentSucceeded(
details: dco_decode_box_autoadd_payment(raw[1]),
);
case 6:
return SdkEvent_PaymentWaitingFeeAcceptance(
return SdkEvent_PaymentWaitingConfirmation(
details: dco_decode_box_autoadd_payment(raw[1]),
);
case 7:
return SdkEvent_PaymentWaitingFeeAcceptance(
details: dco_decode_box_autoadd_payment(raw[1]),
);
case 8:
return SdkEvent_Synced();
default:
throw Exception("unreachable");
Expand Down Expand Up @@ -5265,20 +5269,23 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
return SdkEvent_PaymentPending(details: var_details);
case 2:
var var_details = sse_decode_box_autoadd_payment(deserializer);
return SdkEvent_PaymentRefunded(details: var_details);
return SdkEvent_PaymentRefundable(details: var_details);
case 3:
var var_details = sse_decode_box_autoadd_payment(deserializer);
return SdkEvent_PaymentRefundPending(details: var_details);
return SdkEvent_PaymentRefunded(details: var_details);
case 4:
var var_details = sse_decode_box_autoadd_payment(deserializer);
return SdkEvent_PaymentSucceeded(details: var_details);
return SdkEvent_PaymentRefundPending(details: var_details);
case 5:
var var_details = sse_decode_box_autoadd_payment(deserializer);
return SdkEvent_PaymentWaitingConfirmation(details: var_details);
return SdkEvent_PaymentSucceeded(details: var_details);
case 6:
var var_details = sse_decode_box_autoadd_payment(deserializer);
return SdkEvent_PaymentWaitingFeeAcceptance(details: var_details);
return SdkEvent_PaymentWaitingConfirmation(details: var_details);
case 7:
var var_details = sse_decode_box_autoadd_payment(deserializer);
return SdkEvent_PaymentWaitingFeeAcceptance(details: var_details);
case 8:
return SdkEvent_Synced();
default:
throw UnimplementedError('');
Expand Down Expand Up @@ -7195,23 +7202,26 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
case SdkEvent_PaymentPending(details: final details):
sse_encode_i_32(1, serializer);
sse_encode_box_autoadd_payment(details, serializer);
case SdkEvent_PaymentRefunded(details: final details):
case SdkEvent_PaymentRefundable(details: final details):
sse_encode_i_32(2, serializer);
sse_encode_box_autoadd_payment(details, serializer);
case SdkEvent_PaymentRefundPending(details: final details):
case SdkEvent_PaymentRefunded(details: final details):
sse_encode_i_32(3, serializer);
sse_encode_box_autoadd_payment(details, serializer);
case SdkEvent_PaymentSucceeded(details: final details):
case SdkEvent_PaymentRefundPending(details: final details):
sse_encode_i_32(4, serializer);
sse_encode_box_autoadd_payment(details, serializer);
case SdkEvent_PaymentWaitingConfirmation(details: final details):
case SdkEvent_PaymentSucceeded(details: final details):
sse_encode_i_32(5, serializer);
sse_encode_box_autoadd_payment(details, serializer);
case SdkEvent_PaymentWaitingFeeAcceptance(details: final details):
case SdkEvent_PaymentWaitingConfirmation(details: final details):
sse_encode_i_32(6, serializer);
sse_encode_box_autoadd_payment(details, serializer);
case SdkEvent_Synced():
case SdkEvent_PaymentWaitingFeeAcceptance(details: final details):
sse_encode_i_32(7, serializer);
sse_encode_box_autoadd_payment(details, serializer);
case SdkEvent_Synced():
sse_encode_i_32(8, serializer);
}
}

Expand Down
Loading

0 comments on commit 6760960

Please sign in to comment.