Skip to content

Commit

Permalink
Re-add lnurl module after fixing imports on bindings
Browse files Browse the repository at this point in the history
cargo fmt
  • Loading branch information
erdemyerebasmaz committed Jun 24, 2024
1 parent 215d567 commit 4b31137
Show file tree
Hide file tree
Showing 11 changed files with 1,269 additions and 332 deletions.
12 changes: 7 additions & 5 deletions libs/sdk-core/src/binding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use std::future::Future;
use std::sync::Arc;

use crate::frb_generated::StreamSink;
use crate::lnurl::pay::LnUrlPayResult;
use anyhow::{anyhow, Result};
use log::{Level, LevelFilter, Metadata, Record};
use once_cell::sync::{Lazy, OnceCell};
Expand All @@ -26,6 +27,7 @@ pub use sdk_common::prelude::{
LocaleOverrides, LocalizedName, MessageSuccessActionData, Network, Rate, RouteHint,
RouteHintHop, SuccessActionProcessed, Symbol, UrlSuccessActionData,
};
use sdk_common::prelude::{LnUrlPayError, LnUrlWithdrawError};
use tokio::sync::Mutex;

use crate::breez_services::{self, BreezEvent, BreezServices, EventListener};
Expand Down Expand Up @@ -171,7 +173,7 @@ pub enum _InputType {
#[frb(mirror(BitcoinAddressData))]
pub struct _BitcoinAddressData {
pub address: String,
pub network: crate::prelude::Network,
pub network: Network,
pub amount_sat: Option<u64>,
pub label: Option<String>,
pub message: Option<String>,
Expand Down Expand Up @@ -561,19 +563,19 @@ pub fn receive_payment(req: ReceivePaymentRequest) -> Result<ReceivePaymentRespo
/* LNURL API's */

/// See [BreezServices::lnurl_pay]
pub fn lnurl_pay(req: LnUrlPayRequest) -> Result<crate::lnurl::pay::LnUrlPayResult> {
pub fn lnurl_pay(req: LnUrlPayRequest) -> Result<LnUrlPayResult> {
block_on(async { get_breez_services().await?.lnurl_pay(req).await })
.map_err(anyhow::Error::new::<crate::LnUrlPayError>)
.map_err(anyhow::Error::new::<LnUrlPayError>)
}

/// See [BreezServices::lnurl_withdraw]
pub fn lnurl_withdraw(req: LnUrlWithdrawRequest) -> Result<LnUrlWithdrawResult> {
block_on(async { get_breez_services().await?.lnurl_withdraw(req).await })
.map_err(anyhow::Error::new::<crate::LnUrlWithdrawError>)
.map_err(anyhow::Error::new::<LnUrlWithdrawError>)
}

/// See [BreezServices::lnurl_auth]
pub fn lnurl_auth(req_data: crate::LnUrlAuthRequestData) -> Result<LnUrlCallbackStatus> {
pub fn lnurl_auth(req_data: LnUrlAuthRequestData) -> Result<LnUrlCallbackStatus> {
block_on(async { get_breez_services().await?.lnurl_auth(req_data).await })
.map_err(anyhow::Error::new::<LnUrlAuthError>)
}
Expand Down
196 changes: 154 additions & 42 deletions libs/sdk-core/src/frb_generated.io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
// Section: imports

use super::*;
use crate::binding::*;
use crate::breez_services::EventListener;
use flutter_rust_bridge::for_generated::byteorder::{NativeEndian, ReadBytesExt, WriteBytesExt};
use flutter_rust_bridge::for_generated::{transform_result_dco, Lifetimeable, Lockable};
Expand All @@ -24,29 +23,6 @@ impl CstDecode<flutter_rust_bridge::for_generated::anyhow::Error>
unimplemented!()
}
}
impl CstDecode<LnUrlPayResult> for usize {
// Codec=Cst (C-struct based), see doc to use other codecs
fn cst_decode(self) -> LnUrlPayResult {
flutter_rust_bridge::for_generated::rust_auto_opaque_decode_owned(CstDecode::<
RustOpaqueNom<flutter_rust_bridge::for_generated::RustAutoOpaqueInner<LnUrlPayResult>>,
>::cst_decode(
self
))
}
}
impl
CstDecode<
RustOpaqueNom<flutter_rust_bridge::for_generated::RustAutoOpaqueInner<LnUrlPayResult>>,
> for usize
{
// Codec=Cst (C-struct based), see doc to use other codecs
fn cst_decode(
self,
) -> RustOpaqueNom<flutter_rust_bridge::for_generated::RustAutoOpaqueInner<LnUrlPayResult>>
{
unsafe { decode_rust_opaque_nom(self as _) }
}
}
impl
CstDecode<
StreamSink<crate::breez_services::BreezEvent, flutter_rust_bridge::for_generated::DcoCodec>,
Expand Down Expand Up @@ -307,6 +283,13 @@ impl CstDecode<crate::binding::LnUrlErrorData> for *mut wire_cst_ln_url_error_da
CstDecode::<crate::binding::LnUrlErrorData>::cst_decode(*wrap).into()
}
}
impl CstDecode<crate::binding::LnUrlPayErrorData> for *mut wire_cst_ln_url_pay_error_data {
// Codec=Cst (C-struct based), see doc to use other codecs
fn cst_decode(self) -> crate::binding::LnUrlPayErrorData {
let wrap = unsafe { flutter_rust_bridge::for_generated::box_from_leak_ptr(self) };
CstDecode::<crate::binding::LnUrlPayErrorData>::cst_decode(*wrap).into()
}
}
impl CstDecode<crate::binding::LnUrlPayRequest> for *mut wire_cst_ln_url_pay_request {
// Codec=Cst (C-struct based), see doc to use other codecs
fn cst_decode(self) -> crate::binding::LnUrlPayRequest {
Expand All @@ -321,6 +304,13 @@ impl CstDecode<crate::binding::LnUrlPayRequestData> for *mut wire_cst_ln_url_pay
CstDecode::<crate::binding::LnUrlPayRequestData>::cst_decode(*wrap).into()
}
}
impl CstDecode<crate::lnurl::pay::LnUrlPaySuccessData> for *mut wire_cst_ln_url_pay_success_data {
// Codec=Cst (C-struct based), see doc to use other codecs
fn cst_decode(self) -> crate::lnurl::pay::LnUrlPaySuccessData {
let wrap = unsafe { flutter_rust_bridge::for_generated::box_from_leak_ptr(self) };
CstDecode::<crate::lnurl::pay::LnUrlPaySuccessData>::cst_decode(*wrap).into()
}
}
impl CstDecode<crate::binding::LnUrlWithdrawRequest> for *mut wire_cst_ln_url_withdraw_request {
// Codec=Cst (C-struct based), see doc to use other codecs
fn cst_decode(self) -> crate::binding::LnUrlWithdrawRequest {
Expand Down Expand Up @@ -1083,6 +1073,15 @@ impl CstDecode<crate::binding::LnUrlErrorData> for wire_cst_ln_url_error_data {
}
}
}
impl CstDecode<crate::binding::LnUrlPayErrorData> for wire_cst_ln_url_pay_error_data {
// Codec=Cst (C-struct based), see doc to use other codecs
fn cst_decode(self) -> crate::binding::LnUrlPayErrorData {
crate::binding::LnUrlPayErrorData {
payment_hash: self.payment_hash.cst_decode(),
reason: self.reason.cst_decode(),
}
}
}
impl CstDecode<crate::binding::LnUrlPayRequest> for wire_cst_ln_url_pay_request {
// Codec=Cst (C-struct based), see doc to use other codecs
fn cst_decode(self) -> crate::binding::LnUrlPayRequest {
Expand Down Expand Up @@ -1110,6 +1109,41 @@ impl CstDecode<crate::binding::LnUrlPayRequestData> for wire_cst_ln_url_pay_requ
}
}
}
impl CstDecode<crate::lnurl::pay::LnUrlPayResult> for wire_cst_ln_url_pay_result {
// Codec=Cst (C-struct based), see doc to use other codecs
fn cst_decode(self) -> crate::lnurl::pay::LnUrlPayResult {
match self.tag {
0 => {
let ans = unsafe { self.kind.EndpointSuccess };
crate::lnurl::pay::LnUrlPayResult::EndpointSuccess {
data: ans.data.cst_decode(),
}
}
1 => {
let ans = unsafe { self.kind.EndpointError };
crate::lnurl::pay::LnUrlPayResult::EndpointError {
data: ans.data.cst_decode(),
}
}
2 => {
let ans = unsafe { self.kind.PayError };
crate::lnurl::pay::LnUrlPayResult::PayError {
data: ans.data.cst_decode(),
}
}
_ => unreachable!(),
}
}
}
impl CstDecode<crate::lnurl::pay::LnUrlPaySuccessData> for wire_cst_ln_url_pay_success_data {
// Codec=Cst (C-struct based), see doc to use other codecs
fn cst_decode(self) -> crate::lnurl::pay::LnUrlPaySuccessData {
crate::lnurl::pay::LnUrlPaySuccessData {
payment: self.payment.cst_decode(),
success_action: self.success_action.cst_decode(),
}
}
}
impl CstDecode<crate::binding::LnUrlWithdrawRequest> for wire_cst_ln_url_withdraw_request {
// Codec=Cst (C-struct based), see doc to use other codecs
fn cst_decode(self) -> crate::binding::LnUrlWithdrawRequest {
Expand Down Expand Up @@ -2236,6 +2270,19 @@ impl Default for wire_cst_ln_url_error_data {
Self::new_with_null_ptr()
}
}
impl NewWithNullPtr for wire_cst_ln_url_pay_error_data {
fn new_with_null_ptr() -> Self {
Self {
payment_hash: core::ptr::null_mut(),
reason: core::ptr::null_mut(),
}
}
}
impl Default for wire_cst_ln_url_pay_error_data {
fn default() -> Self {
Self::new_with_null_ptr()
}
}
impl NewWithNullPtr for wire_cst_ln_url_pay_request {
fn new_with_null_ptr() -> Self {
Self {
Expand Down Expand Up @@ -2271,6 +2318,32 @@ impl Default for wire_cst_ln_url_pay_request_data {
Self::new_with_null_ptr()
}
}
impl NewWithNullPtr for wire_cst_ln_url_pay_result {
fn new_with_null_ptr() -> Self {
Self {
tag: -1,
kind: LnUrlPayResultKind { nil__: () },
}
}
}
impl Default for wire_cst_ln_url_pay_result {
fn default() -> Self {
Self::new_with_null_ptr()
}
}
impl NewWithNullPtr for wire_cst_ln_url_pay_success_data {
fn new_with_null_ptr() -> Self {
Self {
payment: Default::default(),
success_action: core::ptr::null_mut(),
}
}
}
impl Default for wire_cst_ln_url_pay_success_data {
fn default() -> Self {
Self::new_with_null_ptr()
}
}
impl NewWithNullPtr for wire_cst_ln_url_withdraw_request {
fn new_with_null_ptr() -> Self {
Self {
Expand Down Expand Up @@ -3597,24 +3670,6 @@ pub extern "C" fn frbgen_breez_sdk_wire__crate__binding__unregister_webhook(
wire__crate__binding__unregister_webhook_impl(port_, webhook_url)
}

#[no_mangle]
pub extern "C" fn frbgen_breez_sdk_rust_arc_increment_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerLnUrlPayResult(
ptr: *const std::ffi::c_void,
) {
unsafe {
StdArc::<flutter_rust_bridge::for_generated::RustAutoOpaqueInner< LnUrlPayResult>>::increment_strong_count(ptr as _);
}
}

#[no_mangle]
pub extern "C" fn frbgen_breez_sdk_rust_arc_decrement_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerLnUrlPayResult(
ptr: *const std::ffi::c_void,
) {
unsafe {
StdArc::<flutter_rust_bridge::for_generated::RustAutoOpaqueInner< LnUrlPayResult>>::decrement_strong_count(ptr as _);
}
}

#[no_mangle]
pub extern "C" fn frbgen_breez_sdk_cst_new_box_autoadd_aes_success_action_data_decrypted(
) -> *mut wire_cst_aes_success_action_data_decrypted {
Expand Down Expand Up @@ -3779,6 +3834,14 @@ pub extern "C" fn frbgen_breez_sdk_cst_new_box_autoadd_ln_url_error_data(
)
}

#[no_mangle]
pub extern "C" fn frbgen_breez_sdk_cst_new_box_autoadd_ln_url_pay_error_data(
) -> *mut wire_cst_ln_url_pay_error_data {
flutter_rust_bridge::for_generated::new_leak_box_ptr(
wire_cst_ln_url_pay_error_data::new_with_null_ptr(),
)
}

#[no_mangle]
pub extern "C" fn frbgen_breez_sdk_cst_new_box_autoadd_ln_url_pay_request(
) -> *mut wire_cst_ln_url_pay_request {
Expand All @@ -3795,6 +3858,14 @@ pub extern "C" fn frbgen_breez_sdk_cst_new_box_autoadd_ln_url_pay_request_data(
)
}

#[no_mangle]
pub extern "C" fn frbgen_breez_sdk_cst_new_box_autoadd_ln_url_pay_success_data(
) -> *mut wire_cst_ln_url_pay_success_data {
flutter_rust_bridge::for_generated::new_leak_box_ptr(
wire_cst_ln_url_pay_success_data::new_with_null_ptr(),
)
}

#[no_mangle]
pub extern "C" fn frbgen_breez_sdk_cst_new_box_autoadd_ln_url_withdraw_request(
) -> *mut wire_cst_ln_url_withdraw_request {
Expand Down Expand Up @@ -4714,6 +4785,12 @@ pub struct wire_cst_ln_url_error_data {
}
#[repr(C)]
#[derive(Clone, Copy)]
pub struct wire_cst_ln_url_pay_error_data {
payment_hash: *mut wire_cst_list_prim_u_8_strict,
reason: *mut wire_cst_list_prim_u_8_strict,
}
#[repr(C)]
#[derive(Clone, Copy)]
pub struct wire_cst_ln_url_pay_request {
data: wire_cst_ln_url_pay_request_data,
amount_msat: u64,
Expand All @@ -4735,6 +4812,41 @@ pub struct wire_cst_ln_url_pay_request_data {
}
#[repr(C)]
#[derive(Clone, Copy)]
pub struct wire_cst_ln_url_pay_result {
tag: i32,
kind: LnUrlPayResultKind,
}
#[repr(C)]
#[derive(Clone, Copy)]
pub union LnUrlPayResultKind {
EndpointSuccess: wire_cst_LnUrlPayResult_EndpointSuccess,
EndpointError: wire_cst_LnUrlPayResult_EndpointError,
PayError: wire_cst_LnUrlPayResult_PayError,
nil__: (),
}
#[repr(C)]
#[derive(Clone, Copy)]
pub struct wire_cst_LnUrlPayResult_EndpointSuccess {
data: *mut wire_cst_ln_url_pay_success_data,
}
#[repr(C)]
#[derive(Clone, Copy)]
pub struct wire_cst_LnUrlPayResult_EndpointError {
data: *mut wire_cst_ln_url_error_data,
}
#[repr(C)]
#[derive(Clone, Copy)]
pub struct wire_cst_LnUrlPayResult_PayError {
data: *mut wire_cst_ln_url_pay_error_data,
}
#[repr(C)]
#[derive(Clone, Copy)]
pub struct wire_cst_ln_url_pay_success_data {
payment: wire_cst_payment,
success_action: *mut wire_cst_success_action_processed,
}
#[repr(C)]
#[derive(Clone, Copy)]
pub struct wire_cst_ln_url_withdraw_request {
data: wire_cst_ln_url_withdraw_request_data,
amount_msat: u64,
Expand Down
Loading

0 comments on commit 4b31137

Please sign in to comment.