mirror of
https://github.com/aljazceru/breez-sdk-liquid.git
synced 2026-02-10 08:44:26 +01:00
Buy Bitcoin (#398)
* Add fiat on-ramp service * Use sdk-common MoonpayProvider * Bump flutter qr dependency * Bump sdk-common dependency
This commit is contained in:
3
cli/Cargo.lock
generated
3
cli/Cargo.lock
generated
@@ -2764,7 +2764,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "sdk-common"
|
||||
version = "0.5.0"
|
||||
source = "git+https://github.com/breez/breez-sdk?branch=main#acadf5bfe616c5d1d119910ca8a876362b1cd969"
|
||||
source = "git+https://github.com/breez/breez-sdk?branch=main#8e4f8467892837421707e0b6f935edc494fdac58"
|
||||
dependencies = [
|
||||
"aes 0.8.4",
|
||||
"anyhow",
|
||||
@@ -2786,6 +2786,7 @@ dependencies = [
|
||||
"thiserror",
|
||||
"tonic",
|
||||
"tonic-build",
|
||||
"url",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
||||
@@ -54,6 +54,13 @@ pub(crate) enum Command {
|
||||
/// Amount the payer will send, in satoshi
|
||||
payer_amount_sat: u64,
|
||||
},
|
||||
/// Generates an URL to buy bitcoin from a 3rd party provider
|
||||
BuyBitcoin {
|
||||
provider: BuyBitcoinProvider,
|
||||
|
||||
/// Amount to buy, in satoshi
|
||||
amount_sat: u64,
|
||||
},
|
||||
/// List incoming and outgoing payments
|
||||
ListPayments {
|
||||
/// The optional from unix timestamp
|
||||
@@ -293,6 +300,37 @@ pub(crate) async fn handle_command(
|
||||
result.push_str(&build_qr_text(&bip21));
|
||||
result
|
||||
}
|
||||
Command::BuyBitcoin {
|
||||
provider,
|
||||
amount_sat,
|
||||
} => {
|
||||
let prepare_res = sdk
|
||||
.prepare_buy_bitcoin(&PrepareBuyBitcoinRequest {
|
||||
provider,
|
||||
amount_sat,
|
||||
})
|
||||
.await?;
|
||||
|
||||
wait_confirmation!(
|
||||
format!(
|
||||
"Fees: {} sat. Are the fees acceptable? (y/N) ",
|
||||
prepare_res.fees_sat
|
||||
),
|
||||
"Buy Bitcoin halted"
|
||||
);
|
||||
|
||||
let url = sdk
|
||||
.buy_bitcoin(&BuyBitcoinRequest {
|
||||
prepare_res,
|
||||
redirect_url: None,
|
||||
})
|
||||
.await?;
|
||||
|
||||
let mut result = command_result!(url.clone());
|
||||
result.push('\n');
|
||||
result.push_str(&build_qr_text(&url));
|
||||
result
|
||||
}
|
||||
Command::GetInfo => {
|
||||
command_result!(sdk.get_info().await?)
|
||||
}
|
||||
|
||||
3
lib/Cargo.lock
generated
3
lib/Cargo.lock
generated
@@ -3085,7 +3085,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "sdk-common"
|
||||
version = "0.5.0"
|
||||
source = "git+https://github.com/breez/breez-sdk?branch=main#acadf5bfe616c5d1d119910ca8a876362b1cd969"
|
||||
source = "git+https://github.com/breez/breez-sdk?branch=main#8e4f8467892837421707e0b6f935edc494fdac58"
|
||||
dependencies = [
|
||||
"aes 0.8.4",
|
||||
"anyhow",
|
||||
@@ -3107,6 +3107,7 @@ dependencies = [
|
||||
"thiserror",
|
||||
"tonic",
|
||||
"tonic-build",
|
||||
"url",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
||||
@@ -46,6 +46,17 @@ typedef struct wire_cst_backup_request {
|
||||
struct wire_cst_list_prim_u_8_strict *backup_path;
|
||||
} wire_cst_backup_request;
|
||||
|
||||
typedef struct wire_cst_prepare_buy_bitcoin_response {
|
||||
int32_t provider;
|
||||
uint64_t amount_sat;
|
||||
uint64_t fees_sat;
|
||||
} wire_cst_prepare_buy_bitcoin_response;
|
||||
|
||||
typedef struct wire_cst_buy_bitcoin_request {
|
||||
struct wire_cst_prepare_buy_bitcoin_response prepare_res;
|
||||
struct wire_cst_list_prim_u_8_strict *redirect_url;
|
||||
} wire_cst_buy_bitcoin_request;
|
||||
|
||||
typedef struct wire_cst_list_payment_type {
|
||||
int32_t *ptr;
|
||||
int32_t len;
|
||||
@@ -111,6 +122,11 @@ typedef struct wire_cst_pay_onchain_request {
|
||||
struct wire_cst_prepare_pay_onchain_response prepare_res;
|
||||
} wire_cst_pay_onchain_request;
|
||||
|
||||
typedef struct wire_cst_prepare_buy_bitcoin_request {
|
||||
int32_t provider;
|
||||
uint64_t amount_sat;
|
||||
} wire_cst_prepare_buy_bitcoin_request;
|
||||
|
||||
typedef struct wire_cst_prepare_pay_onchain_request {
|
||||
uint64_t receiver_amount_sat;
|
||||
uint32_t *sat_per_vbyte;
|
||||
@@ -786,6 +802,10 @@ void frbgen_breez_liquid_wire__crate__bindings__BindingLiquidSdk_add_event_liste
|
||||
WireSyncRust2DartDco frbgen_breez_liquid_wire__crate__bindings__BindingLiquidSdk_backup(uintptr_t that,
|
||||
struct wire_cst_backup_request *req);
|
||||
|
||||
void frbgen_breez_liquid_wire__crate__bindings__BindingLiquidSdk_buy_bitcoin(int64_t port_,
|
||||
uintptr_t that,
|
||||
struct wire_cst_buy_bitcoin_request *req);
|
||||
|
||||
void frbgen_breez_liquid_wire__crate__bindings__BindingLiquidSdk_disconnect(int64_t port_,
|
||||
uintptr_t that);
|
||||
|
||||
@@ -829,6 +849,10 @@ void frbgen_breez_liquid_wire__crate__bindings__BindingLiquidSdk_pay_onchain(int
|
||||
uintptr_t that,
|
||||
struct wire_cst_pay_onchain_request *req);
|
||||
|
||||
void frbgen_breez_liquid_wire__crate__bindings__BindingLiquidSdk_prepare_buy_bitcoin(int64_t port_,
|
||||
uintptr_t that,
|
||||
struct wire_cst_prepare_buy_bitcoin_request *req);
|
||||
|
||||
void frbgen_breez_liquid_wire__crate__bindings__BindingLiquidSdk_prepare_pay_onchain(int64_t port_,
|
||||
uintptr_t that,
|
||||
struct wire_cst_prepare_pay_onchain_request *req);
|
||||
@@ -910,6 +934,8 @@ struct wire_cst_bitcoin_address_data *frbgen_breez_liquid_cst_new_box_autoadd_bi
|
||||
|
||||
bool *frbgen_breez_liquid_cst_new_box_autoadd_bool(bool value);
|
||||
|
||||
struct wire_cst_buy_bitcoin_request *frbgen_breez_liquid_cst_new_box_autoadd_buy_bitcoin_request(void);
|
||||
|
||||
struct wire_cst_connect_request *frbgen_breez_liquid_cst_new_box_autoadd_connect_request(void);
|
||||
|
||||
int64_t *frbgen_breez_liquid_cst_new_box_autoadd_i_64(int64_t value);
|
||||
@@ -942,6 +968,8 @@ struct wire_cst_pay_onchain_request *frbgen_breez_liquid_cst_new_box_autoadd_pay
|
||||
|
||||
struct wire_cst_payment *frbgen_breez_liquid_cst_new_box_autoadd_payment(void);
|
||||
|
||||
struct wire_cst_prepare_buy_bitcoin_request *frbgen_breez_liquid_cst_new_box_autoadd_prepare_buy_bitcoin_request(void);
|
||||
|
||||
struct wire_cst_prepare_pay_onchain_request *frbgen_breez_liquid_cst_new_box_autoadd_prepare_pay_onchain_request(void);
|
||||
|
||||
struct wire_cst_prepare_receive_onchain_request *frbgen_breez_liquid_cst_new_box_autoadd_prepare_receive_onchain_request(void);
|
||||
@@ -1001,6 +1029,7 @@ static int64_t dummy_method_to_enforce_bundling(void) {
|
||||
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_cst_new_box_autoadd_binding_event_listener);
|
||||
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_cst_new_box_autoadd_bitcoin_address_data);
|
||||
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_cst_new_box_autoadd_bool);
|
||||
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_cst_new_box_autoadd_buy_bitcoin_request);
|
||||
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_cst_new_box_autoadd_connect_request);
|
||||
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_cst_new_box_autoadd_i_64);
|
||||
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_cst_new_box_autoadd_list_payments_request);
|
||||
@@ -1017,6 +1046,7 @@ static int64_t dummy_method_to_enforce_bundling(void) {
|
||||
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_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);
|
||||
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_cst_new_box_autoadd_prepare_pay_onchain_request);
|
||||
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_cst_new_box_autoadd_prepare_receive_onchain_request);
|
||||
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_cst_new_box_autoadd_prepare_receive_onchain_response);
|
||||
@@ -1047,6 +1077,7 @@ static int64_t dummy_method_to_enforce_bundling(void) {
|
||||
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_rust_arc_increment_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerBindingLiquidSdk);
|
||||
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_wire__crate__bindings__BindingLiquidSdk_add_event_listener);
|
||||
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_wire__crate__bindings__BindingLiquidSdk_backup);
|
||||
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_wire__crate__bindings__BindingLiquidSdk_buy_bitcoin);
|
||||
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_wire__crate__bindings__BindingLiquidSdk_disconnect);
|
||||
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_wire__crate__bindings__BindingLiquidSdk_empty_wallet_cache);
|
||||
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_wire__crate__bindings__BindingLiquidSdk_fetch_fiat_rates);
|
||||
@@ -1060,6 +1091,7 @@ static int64_t dummy_method_to_enforce_bundling(void) {
|
||||
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_wire__crate__bindings__BindingLiquidSdk_lnurl_pay);
|
||||
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_wire__crate__bindings__BindingLiquidSdk_lnurl_withdraw);
|
||||
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_wire__crate__bindings__BindingLiquidSdk_pay_onchain);
|
||||
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_wire__crate__bindings__BindingLiquidSdk_prepare_buy_bitcoin);
|
||||
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_wire__crate__bindings__BindingLiquidSdk_prepare_pay_onchain);
|
||||
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_wire__crate__bindings__BindingLiquidSdk_prepare_receive_onchain);
|
||||
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_wire__crate__bindings__BindingLiquidSdk_prepare_receive_payment);
|
||||
|
||||
@@ -385,6 +385,26 @@ dictionary ReceiveOnchainResponse {
|
||||
string bip21;
|
||||
};
|
||||
|
||||
enum BuyBitcoinProvider {
|
||||
"Moonpay",
|
||||
};
|
||||
|
||||
dictionary PrepareBuyBitcoinRequest {
|
||||
BuyBitcoinProvider provider;
|
||||
u64 amount_sat;
|
||||
};
|
||||
|
||||
dictionary PrepareBuyBitcoinResponse {
|
||||
BuyBitcoinProvider provider;
|
||||
u64 amount_sat;
|
||||
u64 fees_sat;
|
||||
};
|
||||
|
||||
dictionary BuyBitcoinRequest {
|
||||
PrepareBuyBitcoinResponse prepare_res;
|
||||
string? redirect_url = null;
|
||||
};
|
||||
|
||||
dictionary BackupRequest {
|
||||
string? backup_path = null;
|
||||
};
|
||||
@@ -546,6 +566,12 @@ interface BindingLiquidSdk {
|
||||
[Throws=PaymentError]
|
||||
ReceiveOnchainResponse receive_onchain(PrepareReceiveOnchainResponse req);
|
||||
|
||||
[Throws=PaymentError]
|
||||
PrepareBuyBitcoinResponse prepare_buy_bitcoin(PrepareBuyBitcoinRequest req);
|
||||
|
||||
[Throws=PaymentError]
|
||||
string buy_bitcoin(BuyBitcoinRequest req);
|
||||
|
||||
[Throws=PaymentError]
|
||||
sequence<Payment> list_payments(ListPaymentsRequest req);
|
||||
|
||||
|
||||
@@ -155,6 +155,17 @@ impl BindingLiquidSdk {
|
||||
rt().block_on(self.sdk.receive_onchain(&req))
|
||||
}
|
||||
|
||||
pub fn prepare_buy_bitcoin(
|
||||
&self,
|
||||
req: PrepareBuyBitcoinRequest,
|
||||
) -> Result<PrepareBuyBitcoinResponse, PaymentError> {
|
||||
rt().block_on(self.sdk.prepare_buy_bitcoin(&req))
|
||||
}
|
||||
|
||||
pub fn buy_bitcoin(&self, req: BuyBitcoinRequest) -> Result<String, PaymentError> {
|
||||
rt().block_on(self.sdk.buy_bitcoin(&req))
|
||||
}
|
||||
|
||||
pub fn list_payments(&self, req: ListPaymentsRequest) -> Result<Vec<Payment>, PaymentError> {
|
||||
rt().block_on(self.sdk.list_payments(&req))
|
||||
}
|
||||
|
||||
@@ -164,6 +164,17 @@ impl BindingLiquidSdk {
|
||||
self.sdk.receive_onchain(&req).await
|
||||
}
|
||||
|
||||
pub async fn prepare_buy_bitcoin(
|
||||
&self,
|
||||
req: PrepareBuyBitcoinRequest,
|
||||
) -> Result<PrepareBuyBitcoinResponse, PaymentError> {
|
||||
self.sdk.prepare_buy_bitcoin(&req).await
|
||||
}
|
||||
|
||||
pub async fn buy_bitcoin(&self, req: BuyBitcoinRequest) -> Result<String, PaymentError> {
|
||||
self.sdk.buy_bitcoin(&req).await
|
||||
}
|
||||
|
||||
pub async fn list_payments(
|
||||
&self,
|
||||
req: ListPaymentsRequest,
|
||||
|
||||
65
lib/core/src/buy.rs
Normal file
65
lib/core/src/buy.rs
Normal file
@@ -0,0 +1,65 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use anyhow::{anyhow, Result};
|
||||
use async_trait::async_trait;
|
||||
use sdk_common::prelude::{BreezServer, BuyBitcoinProviderApi, MoonpayProvider};
|
||||
|
||||
use crate::{
|
||||
model::{BuyBitcoinProvider, ChainSwap, Config},
|
||||
prelude::LiquidNetwork,
|
||||
};
|
||||
|
||||
#[async_trait]
|
||||
pub(crate) trait BuyBitcoinApi: Send + Sync {
|
||||
/// Initiate buying Bitcoin and return a URL to the selected third party provider
|
||||
async fn buy_bitcoin(
|
||||
&self,
|
||||
provider: BuyBitcoinProvider,
|
||||
chain_swap: &ChainSwap,
|
||||
redirect_url: Option<String>,
|
||||
) -> Result<String>;
|
||||
}
|
||||
|
||||
pub(crate) struct BuyBitcoinService {
|
||||
config: Config,
|
||||
moonpay_provider: Arc<dyn BuyBitcoinProviderApi>,
|
||||
}
|
||||
|
||||
impl BuyBitcoinService {
|
||||
pub fn new(config: Config, breez_server: Arc<BreezServer>) -> Self {
|
||||
let moonpay_provider = Arc::new(MoonpayProvider::new(breez_server));
|
||||
Self {
|
||||
config,
|
||||
moonpay_provider,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl BuyBitcoinApi for BuyBitcoinService {
|
||||
async fn buy_bitcoin(
|
||||
&self,
|
||||
provider: BuyBitcoinProvider,
|
||||
chain_swap: &ChainSwap,
|
||||
redirect_url: Option<String>,
|
||||
) -> Result<String> {
|
||||
if self.config.network != LiquidNetwork::Mainnet {
|
||||
return Err(anyhow!("Can only buy bitcoin on Mainnet"));
|
||||
}
|
||||
|
||||
let create_response = chain_swap.get_boltz_create_response()?;
|
||||
|
||||
match provider {
|
||||
BuyBitcoinProvider::Moonpay => {
|
||||
self.moonpay_provider
|
||||
.buy_bitcoin(
|
||||
create_response.lockup_details.lockup_address,
|
||||
Some(create_response.lockup_details.amount as u64),
|
||||
None,
|
||||
redirect_url,
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -184,6 +184,13 @@ impl CstDecode<bool> for *mut bool {
|
||||
unsafe { *flutter_rust_bridge::for_generated::box_from_leak_ptr(self) }
|
||||
}
|
||||
}
|
||||
impl CstDecode<crate::model::BuyBitcoinRequest> for *mut wire_cst_buy_bitcoin_request {
|
||||
// Codec=Cst (C-struct based), see doc to use other codecs
|
||||
fn cst_decode(self) -> crate::model::BuyBitcoinRequest {
|
||||
let wrap = unsafe { flutter_rust_bridge::for_generated::box_from_leak_ptr(self) };
|
||||
CstDecode::<crate::model::BuyBitcoinRequest>::cst_decode(*wrap).into()
|
||||
}
|
||||
}
|
||||
impl CstDecode<crate::model::ConnectRequest> for *mut wire_cst_connect_request {
|
||||
// Codec=Cst (C-struct based), see doc to use other codecs
|
||||
fn cst_decode(self) -> crate::model::ConnectRequest {
|
||||
@@ -301,6 +308,15 @@ impl CstDecode<crate::model::Payment> for *mut wire_cst_payment {
|
||||
CstDecode::<crate::model::Payment>::cst_decode(*wrap).into()
|
||||
}
|
||||
}
|
||||
impl CstDecode<crate::model::PrepareBuyBitcoinRequest>
|
||||
for *mut wire_cst_prepare_buy_bitcoin_request
|
||||
{
|
||||
// Codec=Cst (C-struct based), see doc to use other codecs
|
||||
fn cst_decode(self) -> crate::model::PrepareBuyBitcoinRequest {
|
||||
let wrap = unsafe { flutter_rust_bridge::for_generated::box_from_leak_ptr(self) };
|
||||
CstDecode::<crate::model::PrepareBuyBitcoinRequest>::cst_decode(*wrap).into()
|
||||
}
|
||||
}
|
||||
impl CstDecode<crate::model::PreparePayOnchainRequest>
|
||||
for *mut wire_cst_prepare_pay_onchain_request
|
||||
{
|
||||
@@ -417,6 +433,15 @@ impl CstDecode<crate::bindings::UrlSuccessActionData> for *mut wire_cst_url_succ
|
||||
CstDecode::<crate::bindings::UrlSuccessActionData>::cst_decode(*wrap).into()
|
||||
}
|
||||
}
|
||||
impl CstDecode<crate::model::BuyBitcoinRequest> for wire_cst_buy_bitcoin_request {
|
||||
// Codec=Cst (C-struct based), see doc to use other codecs
|
||||
fn cst_decode(self) -> crate::model::BuyBitcoinRequest {
|
||||
crate::model::BuyBitcoinRequest {
|
||||
prepare_res: self.prepare_res.cst_decode(),
|
||||
redirect_url: self.redirect_url.cst_decode(),
|
||||
}
|
||||
}
|
||||
}
|
||||
impl CstDecode<crate::model::Config> for wire_cst_config {
|
||||
// Codec=Cst (C-struct based), see doc to use other codecs
|
||||
fn cst_decode(self) -> crate::model::Config {
|
||||
@@ -1133,6 +1158,25 @@ impl CstDecode<crate::error::PaymentError> for wire_cst_payment_error {
|
||||
}
|
||||
}
|
||||
}
|
||||
impl CstDecode<crate::model::PrepareBuyBitcoinRequest> for wire_cst_prepare_buy_bitcoin_request {
|
||||
// Codec=Cst (C-struct based), see doc to use other codecs
|
||||
fn cst_decode(self) -> crate::model::PrepareBuyBitcoinRequest {
|
||||
crate::model::PrepareBuyBitcoinRequest {
|
||||
provider: self.provider.cst_decode(),
|
||||
amount_sat: self.amount_sat.cst_decode(),
|
||||
}
|
||||
}
|
||||
}
|
||||
impl CstDecode<crate::model::PrepareBuyBitcoinResponse> for wire_cst_prepare_buy_bitcoin_response {
|
||||
// Codec=Cst (C-struct based), see doc to use other codecs
|
||||
fn cst_decode(self) -> crate::model::PrepareBuyBitcoinResponse {
|
||||
crate::model::PrepareBuyBitcoinResponse {
|
||||
provider: self.provider.cst_decode(),
|
||||
amount_sat: self.amount_sat.cst_decode(),
|
||||
fees_sat: self.fees_sat.cst_decode(),
|
||||
}
|
||||
}
|
||||
}
|
||||
impl CstDecode<crate::model::PreparePayOnchainRequest> for wire_cst_prepare_pay_onchain_request {
|
||||
// Codec=Cst (C-struct based), see doc to use other codecs
|
||||
fn cst_decode(self) -> crate::model::PreparePayOnchainRequest {
|
||||
@@ -1512,6 +1556,19 @@ impl Default for wire_cst_bitcoin_address_data {
|
||||
Self::new_with_null_ptr()
|
||||
}
|
||||
}
|
||||
impl NewWithNullPtr for wire_cst_buy_bitcoin_request {
|
||||
fn new_with_null_ptr() -> Self {
|
||||
Self {
|
||||
prepare_res: Default::default(),
|
||||
redirect_url: core::ptr::null_mut(),
|
||||
}
|
||||
}
|
||||
}
|
||||
impl Default for wire_cst_buy_bitcoin_request {
|
||||
fn default() -> Self {
|
||||
Self::new_with_null_ptr()
|
||||
}
|
||||
}
|
||||
impl NewWithNullPtr for wire_cst_config {
|
||||
fn new_with_null_ptr() -> Self {
|
||||
Self {
|
||||
@@ -1991,6 +2048,33 @@ impl Default for wire_cst_payment_error {
|
||||
Self::new_with_null_ptr()
|
||||
}
|
||||
}
|
||||
impl NewWithNullPtr for wire_cst_prepare_buy_bitcoin_request {
|
||||
fn new_with_null_ptr() -> Self {
|
||||
Self {
|
||||
provider: Default::default(),
|
||||
amount_sat: Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
impl Default for wire_cst_prepare_buy_bitcoin_request {
|
||||
fn default() -> Self {
|
||||
Self::new_with_null_ptr()
|
||||
}
|
||||
}
|
||||
impl NewWithNullPtr for wire_cst_prepare_buy_bitcoin_response {
|
||||
fn new_with_null_ptr() -> Self {
|
||||
Self {
|
||||
provider: Default::default(),
|
||||
amount_sat: Default::default(),
|
||||
fees_sat: Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
impl Default for wire_cst_prepare_buy_bitcoin_response {
|
||||
fn default() -> Self {
|
||||
Self::new_with_null_ptr()
|
||||
}
|
||||
}
|
||||
impl NewWithNullPtr for wire_cst_prepare_pay_onchain_request {
|
||||
fn new_with_null_ptr() -> Self {
|
||||
Self {
|
||||
@@ -2356,6 +2440,15 @@ pub extern "C" fn frbgen_breez_liquid_wire__crate__bindings__BindingLiquidSdk_ba
|
||||
wire__crate__bindings__BindingLiquidSdk_backup_impl(that, req)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn frbgen_breez_liquid_wire__crate__bindings__BindingLiquidSdk_buy_bitcoin(
|
||||
port_: i64,
|
||||
that: usize,
|
||||
req: *mut wire_cst_buy_bitcoin_request,
|
||||
) {
|
||||
wire__crate__bindings__BindingLiquidSdk_buy_bitcoin_impl(port_, that, req)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn frbgen_breez_liquid_wire__crate__bindings__BindingLiquidSdk_disconnect(
|
||||
port_: i64,
|
||||
@@ -2464,6 +2557,15 @@ pub extern "C" fn frbgen_breez_liquid_wire__crate__bindings__BindingLiquidSdk_pa
|
||||
wire__crate__bindings__BindingLiquidSdk_pay_onchain_impl(port_, that, req)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn frbgen_breez_liquid_wire__crate__bindings__BindingLiquidSdk_prepare_buy_bitcoin(
|
||||
port_: i64,
|
||||
that: usize,
|
||||
req: *mut wire_cst_prepare_buy_bitcoin_request,
|
||||
) {
|
||||
wire__crate__bindings__BindingLiquidSdk_prepare_buy_bitcoin_impl(port_, that, req)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn frbgen_breez_liquid_wire__crate__bindings__BindingLiquidSdk_prepare_pay_onchain(
|
||||
port_: i64,
|
||||
@@ -2687,6 +2789,14 @@ pub extern "C" fn frbgen_breez_liquid_cst_new_box_autoadd_bool(value: bool) -> *
|
||||
flutter_rust_bridge::for_generated::new_leak_box_ptr(value)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn frbgen_breez_liquid_cst_new_box_autoadd_buy_bitcoin_request(
|
||||
) -> *mut wire_cst_buy_bitcoin_request {
|
||||
flutter_rust_bridge::for_generated::new_leak_box_ptr(
|
||||
wire_cst_buy_bitcoin_request::new_with_null_ptr(),
|
||||
)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn frbgen_breez_liquid_cst_new_box_autoadd_connect_request(
|
||||
) -> *mut wire_cst_connect_request {
|
||||
@@ -2806,6 +2916,14 @@ pub extern "C" fn frbgen_breez_liquid_cst_new_box_autoadd_payment() -> *mut wire
|
||||
flutter_rust_bridge::for_generated::new_leak_box_ptr(wire_cst_payment::new_with_null_ptr())
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn frbgen_breez_liquid_cst_new_box_autoadd_prepare_buy_bitcoin_request(
|
||||
) -> *mut wire_cst_prepare_buy_bitcoin_request {
|
||||
flutter_rust_bridge::for_generated::new_leak_box_ptr(
|
||||
wire_cst_prepare_buy_bitcoin_request::new_with_null_ptr(),
|
||||
)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn frbgen_breez_liquid_cst_new_box_autoadd_prepare_pay_onchain_request(
|
||||
) -> *mut wire_cst_prepare_pay_onchain_request {
|
||||
@@ -3102,6 +3220,12 @@ pub struct wire_cst_bitcoin_address_data {
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct wire_cst_buy_bitcoin_request {
|
||||
prepare_res: wire_cst_prepare_buy_bitcoin_response,
|
||||
redirect_url: *mut wire_cst_list_prim_u_8_strict,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct wire_cst_config {
|
||||
liquid_electrum_url: *mut wire_cst_list_prim_u_8_strict,
|
||||
bitcoin_electrum_url: *mut wire_cst_list_prim_u_8_strict,
|
||||
@@ -3703,6 +3827,19 @@ pub struct wire_cst_PaymentError_SignerError {
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct wire_cst_prepare_buy_bitcoin_request {
|
||||
provider: i32,
|
||||
amount_sat: u64,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct wire_cst_prepare_buy_bitcoin_response {
|
||||
provider: i32,
|
||||
amount_sat: u64,
|
||||
fees_sat: u64,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct wire_cst_prepare_pay_onchain_request {
|
||||
receiver_amount_sat: u64,
|
||||
sat_per_vbyte: *mut u32,
|
||||
|
||||
@@ -39,7 +39,7 @@ flutter_rust_bridge::frb_generated_boilerplate!(
|
||||
default_rust_auto_opaque = RustAutoOpaqueNom,
|
||||
);
|
||||
pub(crate) const FLUTTER_RUST_BRIDGE_CODEGEN_VERSION: &str = "2.0.0";
|
||||
pub(crate) const FLUTTER_RUST_BRIDGE_CODEGEN_CONTENT_HASH: i32 = 749689565;
|
||||
pub(crate) const FLUTTER_RUST_BRIDGE_CODEGEN_CONTENT_HASH: i32 = -119028624;
|
||||
|
||||
// Section: executor
|
||||
|
||||
@@ -135,6 +135,55 @@ fn wire__crate__bindings__BindingLiquidSdk_backup_impl(
|
||||
},
|
||||
)
|
||||
}
|
||||
fn wire__crate__bindings__BindingLiquidSdk_buy_bitcoin_impl(
|
||||
port_: flutter_rust_bridge::for_generated::MessagePort,
|
||||
that: impl CstDecode<
|
||||
RustOpaqueNom<flutter_rust_bridge::for_generated::RustAutoOpaqueInner<BindingLiquidSdk>>,
|
||||
>,
|
||||
req: impl CstDecode<crate::model::BuyBitcoinRequest>,
|
||||
) {
|
||||
FLUTTER_RUST_BRIDGE_HANDLER.wrap_async::<flutter_rust_bridge::for_generated::DcoCodec, _, _, _>(
|
||||
flutter_rust_bridge::for_generated::TaskInfo {
|
||||
debug_name: "BindingLiquidSdk_buy_bitcoin",
|
||||
port: Some(port_),
|
||||
mode: flutter_rust_bridge::for_generated::FfiCallMode::Normal,
|
||||
},
|
||||
move || {
|
||||
let api_that = that.cst_decode();
|
||||
let api_req = req.cst_decode();
|
||||
move |context| async move {
|
||||
transform_result_dco::<_, _, crate::error::PaymentError>(
|
||||
(move || async move {
|
||||
let mut api_that_guard = None;
|
||||
let decode_indices_ =
|
||||
flutter_rust_bridge::for_generated::lockable_compute_decode_order(
|
||||
vec![flutter_rust_bridge::for_generated::LockableOrderInfo::new(
|
||||
&api_that, 0, false,
|
||||
)],
|
||||
);
|
||||
for i in decode_indices_ {
|
||||
match i {
|
||||
0 => {
|
||||
api_that_guard =
|
||||
Some(api_that.lockable_decode_async_ref().await)
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
let api_that_guard = api_that_guard.unwrap();
|
||||
let output_ok = crate::bindings::BindingLiquidSdk::buy_bitcoin(
|
||||
&*api_that_guard,
|
||||
api_req,
|
||||
)
|
||||
.await?;
|
||||
Ok(output_ok)
|
||||
})()
|
||||
.await,
|
||||
)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
fn wire__crate__bindings__BindingLiquidSdk_disconnect_impl(
|
||||
port_: flutter_rust_bridge::for_generated::MessagePort,
|
||||
that: impl CstDecode<
|
||||
@@ -729,6 +778,55 @@ fn wire__crate__bindings__BindingLiquidSdk_pay_onchain_impl(
|
||||
},
|
||||
)
|
||||
}
|
||||
fn wire__crate__bindings__BindingLiquidSdk_prepare_buy_bitcoin_impl(
|
||||
port_: flutter_rust_bridge::for_generated::MessagePort,
|
||||
that: impl CstDecode<
|
||||
RustOpaqueNom<flutter_rust_bridge::for_generated::RustAutoOpaqueInner<BindingLiquidSdk>>,
|
||||
>,
|
||||
req: impl CstDecode<crate::model::PrepareBuyBitcoinRequest>,
|
||||
) {
|
||||
FLUTTER_RUST_BRIDGE_HANDLER.wrap_async::<flutter_rust_bridge::for_generated::DcoCodec, _, _, _>(
|
||||
flutter_rust_bridge::for_generated::TaskInfo {
|
||||
debug_name: "BindingLiquidSdk_prepare_buy_bitcoin",
|
||||
port: Some(port_),
|
||||
mode: flutter_rust_bridge::for_generated::FfiCallMode::Normal,
|
||||
},
|
||||
move || {
|
||||
let api_that = that.cst_decode();
|
||||
let api_req = req.cst_decode();
|
||||
move |context| async move {
|
||||
transform_result_dco::<_, _, crate::error::PaymentError>(
|
||||
(move || async move {
|
||||
let mut api_that_guard = None;
|
||||
let decode_indices_ =
|
||||
flutter_rust_bridge::for_generated::lockable_compute_decode_order(
|
||||
vec![flutter_rust_bridge::for_generated::LockableOrderInfo::new(
|
||||
&api_that, 0, false,
|
||||
)],
|
||||
);
|
||||
for i in decode_indices_ {
|
||||
match i {
|
||||
0 => {
|
||||
api_that_guard =
|
||||
Some(api_that.lockable_decode_async_ref().await)
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
let api_that_guard = api_that_guard.unwrap();
|
||||
let output_ok = crate::bindings::BindingLiquidSdk::prepare_buy_bitcoin(
|
||||
&*api_that_guard,
|
||||
api_req,
|
||||
)
|
||||
.await?;
|
||||
Ok(output_ok)
|
||||
})()
|
||||
.await,
|
||||
)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
fn wire__crate__bindings__BindingLiquidSdk_prepare_pay_onchain_impl(
|
||||
port_: flutter_rust_bridge::for_generated::MessagePort,
|
||||
that: impl CstDecode<
|
||||
@@ -1673,6 +1771,15 @@ impl CstDecode<bool> for bool {
|
||||
self
|
||||
}
|
||||
}
|
||||
impl CstDecode<crate::model::BuyBitcoinProvider> for i32 {
|
||||
// Codec=Cst (C-struct based), see doc to use other codecs
|
||||
fn cst_decode(self) -> crate::model::BuyBitcoinProvider {
|
||||
match self {
|
||||
0 => crate::model::BuyBitcoinProvider::Moonpay,
|
||||
_ => unreachable!("Invalid variant for BuyBitcoinProvider: {}", self),
|
||||
}
|
||||
}
|
||||
}
|
||||
impl CstDecode<f64> for f64 {
|
||||
// Codec=Cst (C-struct based), see doc to use other codecs
|
||||
fn cst_decode(self) -> f64 {
|
||||
@@ -1905,6 +2012,30 @@ impl SseDecode for bool {
|
||||
}
|
||||
}
|
||||
|
||||
impl SseDecode for crate::model::BuyBitcoinProvider {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self {
|
||||
let mut inner = <i32>::sse_decode(deserializer);
|
||||
return match inner {
|
||||
0 => crate::model::BuyBitcoinProvider::Moonpay,
|
||||
_ => unreachable!("Invalid variant for BuyBitcoinProvider: {}", inner),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
impl SseDecode for crate::model::BuyBitcoinRequest {
|
||||
// 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_prepareRes =
|
||||
<crate::model::PrepareBuyBitcoinResponse>::sse_decode(deserializer);
|
||||
let mut var_redirectUrl = <Option<String>>::sse_decode(deserializer);
|
||||
return crate::model::BuyBitcoinRequest {
|
||||
prepare_res: var_prepareRes,
|
||||
redirect_url: var_redirectUrl,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
impl SseDecode for crate::model::Config {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self {
|
||||
@@ -2936,6 +3067,32 @@ impl SseDecode for crate::model::PaymentType {
|
||||
}
|
||||
}
|
||||
|
||||
impl SseDecode for crate::model::PrepareBuyBitcoinRequest {
|
||||
// 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_provider = <crate::model::BuyBitcoinProvider>::sse_decode(deserializer);
|
||||
let mut var_amountSat = <u64>::sse_decode(deserializer);
|
||||
return crate::model::PrepareBuyBitcoinRequest {
|
||||
provider: var_provider,
|
||||
amount_sat: var_amountSat,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
impl SseDecode for crate::model::PrepareBuyBitcoinResponse {
|
||||
// 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_provider = <crate::model::BuyBitcoinProvider>::sse_decode(deserializer);
|
||||
let mut var_amountSat = <u64>::sse_decode(deserializer);
|
||||
let mut var_feesSat = <u64>::sse_decode(deserializer);
|
||||
return crate::model::PrepareBuyBitcoinResponse {
|
||||
provider: var_provider,
|
||||
amount_sat: var_amountSat,
|
||||
fees_sat: var_feesSat,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
@@ -3518,6 +3675,47 @@ impl flutter_rust_bridge::IntoIntoDart<FrbWrapper<crate::bindings::BitcoinAddres
|
||||
}
|
||||
}
|
||||
// Codec=Dco (DartCObject based), see doc to use other codecs
|
||||
impl flutter_rust_bridge::IntoDart for crate::model::BuyBitcoinProvider {
|
||||
fn into_dart(self) -> flutter_rust_bridge::for_generated::DartAbi {
|
||||
match self {
|
||||
Self::Moonpay => 0.into_dart(),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
impl flutter_rust_bridge::for_generated::IntoDartExceptPrimitive
|
||||
for crate::model::BuyBitcoinProvider
|
||||
{
|
||||
}
|
||||
impl flutter_rust_bridge::IntoIntoDart<crate::model::BuyBitcoinProvider>
|
||||
for crate::model::BuyBitcoinProvider
|
||||
{
|
||||
fn into_into_dart(self) -> crate::model::BuyBitcoinProvider {
|
||||
self
|
||||
}
|
||||
}
|
||||
// Codec=Dco (DartCObject based), see doc to use other codecs
|
||||
impl flutter_rust_bridge::IntoDart for crate::model::BuyBitcoinRequest {
|
||||
fn into_dart(self) -> flutter_rust_bridge::for_generated::DartAbi {
|
||||
[
|
||||
self.prepare_res.into_into_dart().into_dart(),
|
||||
self.redirect_url.into_into_dart().into_dart(),
|
||||
]
|
||||
.into_dart()
|
||||
}
|
||||
}
|
||||
impl flutter_rust_bridge::for_generated::IntoDartExceptPrimitive
|
||||
for crate::model::BuyBitcoinRequest
|
||||
{
|
||||
}
|
||||
impl flutter_rust_bridge::IntoIntoDart<crate::model::BuyBitcoinRequest>
|
||||
for crate::model::BuyBitcoinRequest
|
||||
{
|
||||
fn into_into_dart(self) -> crate::model::BuyBitcoinRequest {
|
||||
self
|
||||
}
|
||||
}
|
||||
// Codec=Dco (DartCObject based), see doc to use other codecs
|
||||
impl flutter_rust_bridge::IntoDart for crate::model::Config {
|
||||
fn into_dart(self) -> flutter_rust_bridge::for_generated::DartAbi {
|
||||
[
|
||||
@@ -4446,6 +4644,49 @@ impl flutter_rust_bridge::IntoIntoDart<crate::model::PaymentType> for crate::mod
|
||||
}
|
||||
}
|
||||
// Codec=Dco (DartCObject based), see doc to use other codecs
|
||||
impl flutter_rust_bridge::IntoDart for crate::model::PrepareBuyBitcoinRequest {
|
||||
fn into_dart(self) -> flutter_rust_bridge::for_generated::DartAbi {
|
||||
[
|
||||
self.provider.into_into_dart().into_dart(),
|
||||
self.amount_sat.into_into_dart().into_dart(),
|
||||
]
|
||||
.into_dart()
|
||||
}
|
||||
}
|
||||
impl flutter_rust_bridge::for_generated::IntoDartExceptPrimitive
|
||||
for crate::model::PrepareBuyBitcoinRequest
|
||||
{
|
||||
}
|
||||
impl flutter_rust_bridge::IntoIntoDart<crate::model::PrepareBuyBitcoinRequest>
|
||||
for crate::model::PrepareBuyBitcoinRequest
|
||||
{
|
||||
fn into_into_dart(self) -> crate::model::PrepareBuyBitcoinRequest {
|
||||
self
|
||||
}
|
||||
}
|
||||
// Codec=Dco (DartCObject based), see doc to use other codecs
|
||||
impl flutter_rust_bridge::IntoDart for crate::model::PrepareBuyBitcoinResponse {
|
||||
fn into_dart(self) -> flutter_rust_bridge::for_generated::DartAbi {
|
||||
[
|
||||
self.provider.into_into_dart().into_dart(),
|
||||
self.amount_sat.into_into_dart().into_dart(),
|
||||
self.fees_sat.into_into_dart().into_dart(),
|
||||
]
|
||||
.into_dart()
|
||||
}
|
||||
}
|
||||
impl flutter_rust_bridge::for_generated::IntoDartExceptPrimitive
|
||||
for crate::model::PrepareBuyBitcoinResponse
|
||||
{
|
||||
}
|
||||
impl flutter_rust_bridge::IntoIntoDart<crate::model::PrepareBuyBitcoinResponse>
|
||||
for crate::model::PrepareBuyBitcoinResponse
|
||||
{
|
||||
fn into_into_dart(self) -> crate::model::PrepareBuyBitcoinResponse {
|
||||
self
|
||||
}
|
||||
}
|
||||
// Codec=Dco (DartCObject based), see doc to use other codecs
|
||||
impl flutter_rust_bridge::IntoDart for crate::model::PreparePayOnchainRequest {
|
||||
fn into_dart(self) -> flutter_rust_bridge::for_generated::DartAbi {
|
||||
[
|
||||
@@ -5103,6 +5344,29 @@ impl SseEncode for bool {
|
||||
}
|
||||
}
|
||||
|
||||
impl SseEncode for crate::model::BuyBitcoinProvider {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) {
|
||||
<i32>::sse_encode(
|
||||
match self {
|
||||
crate::model::BuyBitcoinProvider::Moonpay => 0,
|
||||
_ => {
|
||||
unimplemented!("");
|
||||
}
|
||||
},
|
||||
serializer,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
impl SseEncode for crate::model::BuyBitcoinRequest {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) {
|
||||
<crate::model::PrepareBuyBitcoinResponse>::sse_encode(self.prepare_res, serializer);
|
||||
<Option<String>>::sse_encode(self.redirect_url, serializer);
|
||||
}
|
||||
}
|
||||
|
||||
impl SseEncode for crate::model::Config {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) {
|
||||
@@ -5928,6 +6192,23 @@ impl SseEncode for crate::model::PaymentType {
|
||||
}
|
||||
}
|
||||
|
||||
impl SseEncode for crate::model::PrepareBuyBitcoinRequest {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) {
|
||||
<crate::model::BuyBitcoinProvider>::sse_encode(self.provider, serializer);
|
||||
<u64>::sse_encode(self.amount_sat, serializer);
|
||||
}
|
||||
}
|
||||
|
||||
impl SseEncode for crate::model::PrepareBuyBitcoinResponse {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) {
|
||||
<crate::model::BuyBitcoinProvider>::sse_encode(self.provider, serializer);
|
||||
<u64>::sse_encode(self.amount_sat, serializer);
|
||||
<u64>::sse_encode(self.fees_sat, serializer);
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#[cfg(feature = "frb")]
|
||||
pub(crate) mod bindings;
|
||||
pub(crate) mod buy;
|
||||
pub(crate) mod chain;
|
||||
pub(crate) mod chain_swap;
|
||||
pub mod error;
|
||||
|
||||
@@ -1019,6 +1019,35 @@ pub struct RecommendedFees {
|
||||
pub minimum_fee: u64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, EnumString, PartialEq, Serialize)]
|
||||
pub enum BuyBitcoinProvider {
|
||||
#[strum(serialize = "moonpay")]
|
||||
Moonpay,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct PrepareBuyBitcoinRequest {
|
||||
pub provider: BuyBitcoinProvider,
|
||||
pub amount_sat: u64,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize)]
|
||||
pub struct PrepareBuyBitcoinResponse {
|
||||
pub provider: BuyBitcoinProvider,
|
||||
pub amount_sat: u64,
|
||||
pub fees_sat: u64,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize)]
|
||||
pub struct BuyBitcoinRequest {
|
||||
pub prepare_res: PrepareBuyBitcoinResponse,
|
||||
|
||||
/// The optional URL to redirect to after completing the buy.
|
||||
///
|
||||
/// For Moonpay, see <https://dev.moonpay.com/docs/on-ramp-configure-user-journey-params>
|
||||
pub redirect_url: Option<String>,
|
||||
}
|
||||
|
||||
/// Internal SDK log entry used in the Uniffi and Dart bindings
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct LogEntry {
|
||||
|
||||
@@ -6,6 +6,7 @@ use anyhow::Result;
|
||||
use async_trait::async_trait;
|
||||
use boltz_client::{swaps::boltzv2::*, util::secrets::Preimage, Bolt11Invoice};
|
||||
use boltz_client::{LockTime, ToHex};
|
||||
use buy::{BuyBitcoinApi, BuyBitcoinService};
|
||||
use chain::bitcoin::HybridBitcoinChainService;
|
||||
use chain::liquid::{HybridLiquidChainService, LiquidChainService};
|
||||
use chain_swap::ESTIMATED_BTC_CLAIM_TX_VSIZE;
|
||||
@@ -60,6 +61,7 @@ pub struct LiquidSdk {
|
||||
pub(crate) send_swap_state_handler: SendSwapStateHandler,
|
||||
pub(crate) receive_swap_state_handler: ReceiveSwapStateHandler,
|
||||
pub(crate) chain_swap_state_handler: Arc<ChainSwapStateHandler>,
|
||||
pub(crate) buy_bitcoin_service: Arc<dyn BuyBitcoinApi>,
|
||||
}
|
||||
|
||||
impl LiquidSdk {
|
||||
@@ -132,7 +134,10 @@ impl LiquidSdk {
|
||||
bitcoin_chain_service.clone(),
|
||||
)?);
|
||||
|
||||
let breez_server = BreezServer::new(PRODUCTION_BREEZSERVER_URL.into(), None)?;
|
||||
let breez_server = Arc::new(BreezServer::new(PRODUCTION_BREEZSERVER_URL.into(), None)?);
|
||||
|
||||
let buy_bitcoin_service =
|
||||
Arc::new(BuyBitcoinService::new(config.clone(), breez_server.clone()));
|
||||
|
||||
let sdk = Arc::new(LiquidSdk {
|
||||
config: config.clone(),
|
||||
@@ -143,13 +148,14 @@ impl LiquidSdk {
|
||||
swapper,
|
||||
bitcoin_chain_service,
|
||||
liquid_chain_service,
|
||||
fiat_api: Arc::new(breez_server),
|
||||
fiat_api: breez_server,
|
||||
is_started: RwLock::new(false),
|
||||
shutdown_sender,
|
||||
shutdown_receiver,
|
||||
send_swap_state_handler,
|
||||
receive_swap_state_handler,
|
||||
chain_swap_state_handler,
|
||||
buy_bitcoin_service,
|
||||
});
|
||||
Ok(sdk)
|
||||
}
|
||||
@@ -1228,19 +1234,17 @@ impl LiquidSdk {
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn receive_onchain(
|
||||
async fn create_chain_swap(
|
||||
&self,
|
||||
req: &PrepareReceiveOnchainResponse,
|
||||
) -> Result<ReceiveOnchainResponse, PaymentError> {
|
||||
self.ensure_is_started().await?;
|
||||
|
||||
let payer_amount_sat = req.payer_amount_sat;
|
||||
payer_amount_sat: u64,
|
||||
fees_sat: u64,
|
||||
) -> Result<ChainSwap, PaymentError> {
|
||||
let pair = self.validate_chain_pairs(Direction::Incoming, payer_amount_sat)?;
|
||||
let claim_fees_sat = pair.fees.claim_estimate();
|
||||
let server_fees_sat = pair.fees.server();
|
||||
|
||||
ensure_sdk!(
|
||||
req.fees_sat == pair.fees.boltz(payer_amount_sat) + claim_fees_sat + server_fees_sat,
|
||||
fees_sat == pair.fees.boltz(payer_amount_sat) + claim_fees_sat + server_fees_sat,
|
||||
PaymentError::InvalidOrExpiredFees
|
||||
);
|
||||
|
||||
@@ -1274,15 +1278,14 @@ impl LiquidSdk {
|
||||
ChainSwap::from_boltz_struct_to_json(&create_response, &swap_id)?;
|
||||
|
||||
let accept_zero_conf = payer_amount_sat <= pair.limits.maximal_zero_conf;
|
||||
let receiver_amount_sat = payer_amount_sat - req.fees_sat;
|
||||
let receiver_amount_sat = payer_amount_sat - fees_sat;
|
||||
let claim_address = self.onchain_wallet.next_unused_address().await?.to_string();
|
||||
let lockup_address = create_response.lockup_details.lockup_address;
|
||||
|
||||
let swap = ChainSwap {
|
||||
id: swap_id.clone(),
|
||||
direction: Direction::Incoming,
|
||||
claim_address,
|
||||
lockup_address: lockup_address.clone(),
|
||||
lockup_address: create_response.lockup_details.lockup_address,
|
||||
timeout_block_height: create_response.lockup_details.timeout_block_height,
|
||||
preimage: preimage_str,
|
||||
payer_amount_sat,
|
||||
@@ -1301,8 +1304,21 @@ impl LiquidSdk {
|
||||
};
|
||||
self.persister.insert_chain_swap(&swap)?;
|
||||
self.status_stream.track_swap_id(&swap.id)?;
|
||||
Ok(swap)
|
||||
}
|
||||
|
||||
pub async fn receive_onchain(
|
||||
&self,
|
||||
req: &PrepareReceiveOnchainResponse,
|
||||
) -> Result<ReceiveOnchainResponse, PaymentError> {
|
||||
self.ensure_is_started().await?;
|
||||
|
||||
let swap = self
|
||||
.create_chain_swap(req.payer_amount_sat, req.fees_sat)
|
||||
.await?;
|
||||
let create_response = swap.get_boltz_create_response()?;
|
||||
let address = create_response.lockup_details.lockup_address;
|
||||
|
||||
let address = lockup_address;
|
||||
let amount = create_response.lockup_details.amount as f64 / 100_000_000.0;
|
||||
let bip21 = create_response.lockup_details.bip21.unwrap_or(format!(
|
||||
"bitcoin:{address}?amount={amount}&label=Send%20to%20L-BTC%20address"
|
||||
@@ -1351,6 +1367,39 @@ impl LiquidSdk {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn prepare_buy_bitcoin(
|
||||
&self,
|
||||
req: &PrepareBuyBitcoinRequest,
|
||||
) -> Result<PrepareBuyBitcoinResponse, PaymentError> {
|
||||
if self.config.network != LiquidNetwork::Mainnet {
|
||||
return Err(PaymentError::Generic {
|
||||
err: "Can only buy bitcoin on Mainnet".to_string(),
|
||||
});
|
||||
}
|
||||
|
||||
let res = self
|
||||
.prepare_receive_onchain(&PrepareReceiveOnchainRequest {
|
||||
payer_amount_sat: req.amount_sat,
|
||||
})
|
||||
.await?;
|
||||
Ok(PrepareBuyBitcoinResponse {
|
||||
provider: req.provider,
|
||||
amount_sat: res.payer_amount_sat,
|
||||
fees_sat: res.fees_sat,
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn buy_bitcoin(&self, req: &BuyBitcoinRequest) -> Result<String, PaymentError> {
|
||||
let swap = self
|
||||
.create_chain_swap(req.prepare_res.amount_sat, req.prepare_res.fees_sat)
|
||||
.await?;
|
||||
|
||||
Ok(self
|
||||
.buy_bitcoin_service
|
||||
.buy_bitcoin(req.prepare_res.provider, &swap, req.redirect_url.clone())
|
||||
.await?)
|
||||
}
|
||||
|
||||
/// This method fetches the chain tx data (onchain and mempool) using LWK. For every wallet tx,
|
||||
/// it inserts or updates a corresponding entry in our Payments table.
|
||||
async fn sync_payments_with_chain_data(&self, with_scan: bool) -> Result<()> {
|
||||
|
||||
@@ -7,8 +7,9 @@ use std::sync::Arc;
|
||||
use tokio::sync::{watch, Mutex, RwLock};
|
||||
|
||||
use crate::{
|
||||
chain_swap::ChainSwapStateHandler, event::EventManager, model::Config, persist::Persister,
|
||||
receive_swap::ReceiveSwapStateHandler, sdk::LiquidSdk, send_swap::SendSwapStateHandler,
|
||||
buy::BuyBitcoinService, chain_swap::ChainSwapStateHandler, event::EventManager, model::Config,
|
||||
persist::Persister, receive_swap::ReceiveSwapStateHandler, sdk::LiquidSdk,
|
||||
send_swap::SendSwapStateHandler,
|
||||
};
|
||||
|
||||
use super::{
|
||||
@@ -63,7 +64,10 @@ pub(crate) fn new_liquid_sdk(
|
||||
let event_manager = Arc::new(EventManager::new());
|
||||
let (shutdown_sender, shutdown_receiver) = watch::channel::<()>(());
|
||||
|
||||
let fiat_api = Arc::new(BreezServer::new(STAGING_BREEZSERVER_URL.into(), None)?);
|
||||
let breez_server = Arc::new(BreezServer::new(STAGING_BREEZSERVER_URL.into(), None)?);
|
||||
|
||||
let buy_bitcoin_service =
|
||||
Arc::new(BuyBitcoinService::new(config.clone(), breez_server.clone()));
|
||||
|
||||
Ok(LiquidSdk {
|
||||
config,
|
||||
@@ -74,12 +78,13 @@ pub(crate) fn new_liquid_sdk(
|
||||
swapper,
|
||||
liquid_chain_service,
|
||||
bitcoin_chain_service,
|
||||
fiat_api,
|
||||
fiat_api: breez_server,
|
||||
is_started: RwLock::new(true),
|
||||
shutdown_sender,
|
||||
shutdown_receiver,
|
||||
send_swap_state_handler,
|
||||
receive_swap_state_handler,
|
||||
chain_swap_state_handler,
|
||||
buy_bitcoin_service,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -35,6 +35,8 @@ abstract class BindingLiquidSdk implements RustOpaqueInterface {
|
||||
|
||||
void backup({required BackupRequest req});
|
||||
|
||||
Future<String> buyBitcoin({required BuyBitcoinRequest req});
|
||||
|
||||
Future<void> disconnect();
|
||||
|
||||
void emptyWalletCache();
|
||||
@@ -61,6 +63,8 @@ abstract class BindingLiquidSdk implements RustOpaqueInterface {
|
||||
|
||||
Future<SendPaymentResponse> payOnchain({required PayOnchainRequest req});
|
||||
|
||||
Future<PrepareBuyBitcoinResponse> prepareBuyBitcoin({required PrepareBuyBitcoinRequest req});
|
||||
|
||||
Future<PreparePayOnchainResponse> preparePayOnchain({required PreparePayOnchainRequest req});
|
||||
|
||||
Future<PrepareReceiveOnchainResponse> prepareReceiveOnchain({required PrepareReceiveOnchainRequest req});
|
||||
|
||||
@@ -55,7 +55,7 @@ class RustLib extends BaseEntrypoint<RustLibApi, RustLibApiImpl, RustLibWire> {
|
||||
String get codegenVersion => '2.0.0';
|
||||
|
||||
@override
|
||||
int get rustContentHash => 749689565;
|
||||
int get rustContentHash => -119028624;
|
||||
|
||||
static const kDefaultExternalLibraryLoaderConfig = ExternalLibraryLoaderConfig(
|
||||
stem: 'breez_sdk_liquid',
|
||||
@@ -69,6 +69,9 @@ abstract class RustLibApi extends BaseApi {
|
||||
|
||||
void crateBindingsBindingLiquidSdkBackup({required BindingLiquidSdk that, required BackupRequest req});
|
||||
|
||||
Future<String> crateBindingsBindingLiquidSdkBuyBitcoin(
|
||||
{required BindingLiquidSdk that, required BuyBitcoinRequest req});
|
||||
|
||||
Future<void> crateBindingsBindingLiquidSdkDisconnect({required BindingLiquidSdk that});
|
||||
|
||||
void crateBindingsBindingLiquidSdkEmptyWalletCache({required BindingLiquidSdk that});
|
||||
@@ -103,6 +106,9 @@ abstract class RustLibApi extends BaseApi {
|
||||
Future<SendPaymentResponse> crateBindingsBindingLiquidSdkPayOnchain(
|
||||
{required BindingLiquidSdk that, required PayOnchainRequest req});
|
||||
|
||||
Future<PrepareBuyBitcoinResponse> crateBindingsBindingLiquidSdkPrepareBuyBitcoin(
|
||||
{required BindingLiquidSdk that, required PrepareBuyBitcoinRequest req});
|
||||
|
||||
Future<PreparePayOnchainResponse> crateBindingsBindingLiquidSdkPreparePayOnchain(
|
||||
{required BindingLiquidSdk that, required PreparePayOnchainRequest req});
|
||||
|
||||
@@ -218,6 +224,32 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
|
||||
argNames: ["that", "req"],
|
||||
);
|
||||
|
||||
@override
|
||||
Future<String> crateBindingsBindingLiquidSdkBuyBitcoin(
|
||||
{required BindingLiquidSdk that, required BuyBitcoinRequest req}) {
|
||||
return handler.executeNormal(NormalTask(
|
||||
callFfi: (port_) {
|
||||
var arg0 =
|
||||
cst_encode_Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerBindingLiquidSdk(
|
||||
that);
|
||||
var arg1 = cst_encode_box_autoadd_buy_bitcoin_request(req);
|
||||
return wire.wire__crate__bindings__BindingLiquidSdk_buy_bitcoin(port_, arg0, arg1);
|
||||
},
|
||||
codec: DcoCodec(
|
||||
decodeSuccessData: dco_decode_String,
|
||||
decodeErrorData: dco_decode_payment_error,
|
||||
),
|
||||
constMeta: kCrateBindingsBindingLiquidSdkBuyBitcoinConstMeta,
|
||||
argValues: [that, req],
|
||||
apiImpl: this,
|
||||
));
|
||||
}
|
||||
|
||||
TaskConstMeta get kCrateBindingsBindingLiquidSdkBuyBitcoinConstMeta => const TaskConstMeta(
|
||||
debugName: "BindingLiquidSdk_buy_bitcoin",
|
||||
argNames: ["that", "req"],
|
||||
);
|
||||
|
||||
@override
|
||||
Future<void> crateBindingsBindingLiquidSdkDisconnect({required BindingLiquidSdk that}) {
|
||||
return handler.executeNormal(NormalTask(
|
||||
@@ -544,6 +576,32 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
|
||||
argNames: ["that", "req"],
|
||||
);
|
||||
|
||||
@override
|
||||
Future<PrepareBuyBitcoinResponse> crateBindingsBindingLiquidSdkPrepareBuyBitcoin(
|
||||
{required BindingLiquidSdk that, required PrepareBuyBitcoinRequest req}) {
|
||||
return handler.executeNormal(NormalTask(
|
||||
callFfi: (port_) {
|
||||
var arg0 =
|
||||
cst_encode_Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerBindingLiquidSdk(
|
||||
that);
|
||||
var arg1 = cst_encode_box_autoadd_prepare_buy_bitcoin_request(req);
|
||||
return wire.wire__crate__bindings__BindingLiquidSdk_prepare_buy_bitcoin(port_, arg0, arg1);
|
||||
},
|
||||
codec: DcoCodec(
|
||||
decodeSuccessData: dco_decode_prepare_buy_bitcoin_response,
|
||||
decodeErrorData: dco_decode_payment_error,
|
||||
),
|
||||
constMeta: kCrateBindingsBindingLiquidSdkPrepareBuyBitcoinConstMeta,
|
||||
argValues: [that, req],
|
||||
apiImpl: this,
|
||||
));
|
||||
}
|
||||
|
||||
TaskConstMeta get kCrateBindingsBindingLiquidSdkPrepareBuyBitcoinConstMeta => const TaskConstMeta(
|
||||
debugName: "BindingLiquidSdk_prepare_buy_bitcoin",
|
||||
argNames: ["that", "req"],
|
||||
);
|
||||
|
||||
@override
|
||||
Future<PreparePayOnchainResponse> crateBindingsBindingLiquidSdkPreparePayOnchain(
|
||||
{required BindingLiquidSdk that, required PreparePayOnchainRequest req}) {
|
||||
@@ -1169,6 +1227,12 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
|
||||
return raw as bool;
|
||||
}
|
||||
|
||||
@protected
|
||||
BuyBitcoinRequest dco_decode_box_autoadd_buy_bitcoin_request(dynamic raw) {
|
||||
// Codec=Dco (DartCObject based), see doc to use other codecs
|
||||
return dco_decode_buy_bitcoin_request(raw);
|
||||
}
|
||||
|
||||
@protected
|
||||
ConnectRequest dco_decode_box_autoadd_connect_request(dynamic raw) {
|
||||
// Codec=Dco (DartCObject based), see doc to use other codecs
|
||||
@@ -1265,6 +1329,12 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
|
||||
return dco_decode_payment(raw);
|
||||
}
|
||||
|
||||
@protected
|
||||
PrepareBuyBitcoinRequest dco_decode_box_autoadd_prepare_buy_bitcoin_request(dynamic raw) {
|
||||
// Codec=Dco (DartCObject based), see doc to use other codecs
|
||||
return dco_decode_prepare_buy_bitcoin_request(raw);
|
||||
}
|
||||
|
||||
@protected
|
||||
PreparePayOnchainRequest dco_decode_box_autoadd_prepare_pay_onchain_request(dynamic raw) {
|
||||
// Codec=Dco (DartCObject based), see doc to use other codecs
|
||||
@@ -1361,6 +1431,23 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
|
||||
return dco_decode_url_success_action_data(raw);
|
||||
}
|
||||
|
||||
@protected
|
||||
BuyBitcoinProvider dco_decode_buy_bitcoin_provider(dynamic raw) {
|
||||
// Codec=Dco (DartCObject based), see doc to use other codecs
|
||||
return BuyBitcoinProvider.values[raw as int];
|
||||
}
|
||||
|
||||
@protected
|
||||
BuyBitcoinRequest dco_decode_buy_bitcoin_request(dynamic raw) {
|
||||
// Codec=Dco (DartCObject based), see doc to use other codecs
|
||||
final arr = raw as List<dynamic>;
|
||||
if (arr.length != 2) throw Exception('unexpected arr length: expect 2 but see ${arr.length}');
|
||||
return BuyBitcoinRequest(
|
||||
prepareRes: dco_decode_prepare_buy_bitcoin_response(arr[0]),
|
||||
redirectUrl: dco_decode_opt_String(arr[1]),
|
||||
);
|
||||
}
|
||||
|
||||
@protected
|
||||
Config dco_decode_config(dynamic raw) {
|
||||
// Codec=Dco (DartCObject based), see doc to use other codecs
|
||||
@@ -2103,6 +2190,29 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
|
||||
return PaymentType.values[raw as int];
|
||||
}
|
||||
|
||||
@protected
|
||||
PrepareBuyBitcoinRequest dco_decode_prepare_buy_bitcoin_request(dynamic raw) {
|
||||
// Codec=Dco (DartCObject based), see doc to use other codecs
|
||||
final arr = raw as List<dynamic>;
|
||||
if (arr.length != 2) throw Exception('unexpected arr length: expect 2 but see ${arr.length}');
|
||||
return PrepareBuyBitcoinRequest(
|
||||
provider: dco_decode_buy_bitcoin_provider(arr[0]),
|
||||
amountSat: dco_decode_u_64(arr[1]),
|
||||
);
|
||||
}
|
||||
|
||||
@protected
|
||||
PrepareBuyBitcoinResponse dco_decode_prepare_buy_bitcoin_response(dynamic raw) {
|
||||
// Codec=Dco (DartCObject based), see doc to use other codecs
|
||||
final arr = raw as List<dynamic>;
|
||||
if (arr.length != 3) throw Exception('unexpected arr length: expect 3 but see ${arr.length}');
|
||||
return PrepareBuyBitcoinResponse(
|
||||
provider: dco_decode_buy_bitcoin_provider(arr[0]),
|
||||
amountSat: dco_decode_u_64(arr[1]),
|
||||
feesSat: dco_decode_u_64(arr[2]),
|
||||
);
|
||||
}
|
||||
|
||||
@protected
|
||||
PreparePayOnchainRequest dco_decode_prepare_pay_onchain_request(dynamic raw) {
|
||||
// Codec=Dco (DartCObject based), see doc to use other codecs
|
||||
@@ -2629,6 +2739,12 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
|
||||
return (sse_decode_bool(deserializer));
|
||||
}
|
||||
|
||||
@protected
|
||||
BuyBitcoinRequest sse_decode_box_autoadd_buy_bitcoin_request(SseDeserializer deserializer) {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
return (sse_decode_buy_bitcoin_request(deserializer));
|
||||
}
|
||||
|
||||
@protected
|
||||
ConnectRequest sse_decode_box_autoadd_connect_request(SseDeserializer deserializer) {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
@@ -2725,6 +2841,12 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
|
||||
return (sse_decode_payment(deserializer));
|
||||
}
|
||||
|
||||
@protected
|
||||
PrepareBuyBitcoinRequest sse_decode_box_autoadd_prepare_buy_bitcoin_request(SseDeserializer deserializer) {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
return (sse_decode_prepare_buy_bitcoin_request(deserializer));
|
||||
}
|
||||
|
||||
@protected
|
||||
PreparePayOnchainRequest sse_decode_box_autoadd_prepare_pay_onchain_request(SseDeserializer deserializer) {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
@@ -2823,6 +2945,21 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
|
||||
return (sse_decode_url_success_action_data(deserializer));
|
||||
}
|
||||
|
||||
@protected
|
||||
BuyBitcoinProvider sse_decode_buy_bitcoin_provider(SseDeserializer deserializer) {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
var inner = sse_decode_i_32(deserializer);
|
||||
return BuyBitcoinProvider.values[inner];
|
||||
}
|
||||
|
||||
@protected
|
||||
BuyBitcoinRequest sse_decode_buy_bitcoin_request(SseDeserializer deserializer) {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
var var_prepareRes = sse_decode_prepare_buy_bitcoin_response(deserializer);
|
||||
var var_redirectUrl = sse_decode_opt_String(deserializer);
|
||||
return BuyBitcoinRequest(prepareRes: var_prepareRes, redirectUrl: var_redirectUrl);
|
||||
}
|
||||
|
||||
@protected
|
||||
Config sse_decode_config(SseDeserializer deserializer) {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
@@ -3629,6 +3766,23 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
|
||||
return PaymentType.values[inner];
|
||||
}
|
||||
|
||||
@protected
|
||||
PrepareBuyBitcoinRequest sse_decode_prepare_buy_bitcoin_request(SseDeserializer deserializer) {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
var var_provider = sse_decode_buy_bitcoin_provider(deserializer);
|
||||
var var_amountSat = sse_decode_u_64(deserializer);
|
||||
return PrepareBuyBitcoinRequest(provider: var_provider, amountSat: var_amountSat);
|
||||
}
|
||||
|
||||
@protected
|
||||
PrepareBuyBitcoinResponse sse_decode_prepare_buy_bitcoin_response(SseDeserializer deserializer) {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
var var_provider = sse_decode_buy_bitcoin_provider(deserializer);
|
||||
var var_amountSat = sse_decode_u_64(deserializer);
|
||||
var var_feesSat = sse_decode_u_64(deserializer);
|
||||
return PrepareBuyBitcoinResponse(provider: var_provider, amountSat: var_amountSat, feesSat: var_feesSat);
|
||||
}
|
||||
|
||||
@protected
|
||||
PreparePayOnchainRequest sse_decode_prepare_pay_onchain_request(SseDeserializer deserializer) {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
@@ -3977,6 +4131,12 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
|
||||
return raw;
|
||||
}
|
||||
|
||||
@protected
|
||||
int cst_encode_buy_bitcoin_provider(BuyBitcoinProvider raw) {
|
||||
// Codec=Cst (C-struct based), see doc to use other codecs
|
||||
return cst_encode_i_32(raw.index);
|
||||
}
|
||||
|
||||
@protected
|
||||
double cst_encode_f_64(double raw) {
|
||||
// Codec=Cst (C-struct based), see doc to use other codecs
|
||||
@@ -4183,6 +4343,12 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
|
||||
sse_encode_bool(self, serializer);
|
||||
}
|
||||
|
||||
@protected
|
||||
void sse_encode_box_autoadd_buy_bitcoin_request(BuyBitcoinRequest self, SseSerializer serializer) {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
sse_encode_buy_bitcoin_request(self, serializer);
|
||||
}
|
||||
|
||||
@protected
|
||||
void sse_encode_box_autoadd_connect_request(ConnectRequest self, SseSerializer serializer) {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
@@ -4282,6 +4448,13 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
|
||||
sse_encode_payment(self, serializer);
|
||||
}
|
||||
|
||||
@protected
|
||||
void sse_encode_box_autoadd_prepare_buy_bitcoin_request(
|
||||
PrepareBuyBitcoinRequest self, SseSerializer serializer) {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
sse_encode_prepare_buy_bitcoin_request(self, serializer);
|
||||
}
|
||||
|
||||
@protected
|
||||
void sse_encode_box_autoadd_prepare_pay_onchain_request(
|
||||
PreparePayOnchainRequest self, SseSerializer serializer) {
|
||||
@@ -4383,6 +4556,19 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
|
||||
sse_encode_url_success_action_data(self, serializer);
|
||||
}
|
||||
|
||||
@protected
|
||||
void sse_encode_buy_bitcoin_provider(BuyBitcoinProvider self, SseSerializer serializer) {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
sse_encode_i_32(self.index, serializer);
|
||||
}
|
||||
|
||||
@protected
|
||||
void sse_encode_buy_bitcoin_request(BuyBitcoinRequest self, SseSerializer serializer) {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
sse_encode_prepare_buy_bitcoin_response(self.prepareRes, serializer);
|
||||
sse_encode_opt_String(self.redirectUrl, serializer);
|
||||
}
|
||||
|
||||
@protected
|
||||
void sse_encode_config(Config self, SseSerializer serializer) {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
@@ -5046,6 +5232,21 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
|
||||
sse_encode_i_32(self.index, serializer);
|
||||
}
|
||||
|
||||
@protected
|
||||
void sse_encode_prepare_buy_bitcoin_request(PrepareBuyBitcoinRequest self, SseSerializer serializer) {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
sse_encode_buy_bitcoin_provider(self.provider, serializer);
|
||||
sse_encode_u_64(self.amountSat, serializer);
|
||||
}
|
||||
|
||||
@protected
|
||||
void sse_encode_prepare_buy_bitcoin_response(PrepareBuyBitcoinResponse self, SseSerializer serializer) {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
sse_encode_buy_bitcoin_provider(self.provider, serializer);
|
||||
sse_encode_u_64(self.amountSat, serializer);
|
||||
sse_encode_u_64(self.feesSat, serializer);
|
||||
}
|
||||
|
||||
@protected
|
||||
void sse_encode_prepare_pay_onchain_request(PreparePayOnchainRequest self, SseSerializer serializer) {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
@@ -5343,6 +5544,9 @@ class BindingLiquidSdkImpl extends RustOpaque implements BindingLiquidSdk {
|
||||
void backup({required BackupRequest req}) =>
|
||||
RustLib.instance.api.crateBindingsBindingLiquidSdkBackup(that: this, req: req);
|
||||
|
||||
Future<String> buyBitcoin({required BuyBitcoinRequest req}) =>
|
||||
RustLib.instance.api.crateBindingsBindingLiquidSdkBuyBitcoin(that: this, req: req);
|
||||
|
||||
Future<void> disconnect() => RustLib.instance.api.crateBindingsBindingLiquidSdkDisconnect(
|
||||
that: this,
|
||||
);
|
||||
@@ -5394,6 +5598,9 @@ class BindingLiquidSdkImpl extends RustOpaque implements BindingLiquidSdk {
|
||||
Future<SendPaymentResponse> payOnchain({required PayOnchainRequest req}) =>
|
||||
RustLib.instance.api.crateBindingsBindingLiquidSdkPayOnchain(that: this, req: req);
|
||||
|
||||
Future<PrepareBuyBitcoinResponse> prepareBuyBitcoin({required PrepareBuyBitcoinRequest req}) =>
|
||||
RustLib.instance.api.crateBindingsBindingLiquidSdkPrepareBuyBitcoin(that: this, req: req);
|
||||
|
||||
Future<PreparePayOnchainResponse> preparePayOnchain({required PreparePayOnchainRequest req}) =>
|
||||
RustLib.instance.api.crateBindingsBindingLiquidSdkPreparePayOnchain(that: this, req: req);
|
||||
|
||||
|
||||
@@ -86,6 +86,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
|
||||
@protected
|
||||
bool dco_decode_box_autoadd_bool(dynamic raw);
|
||||
|
||||
@protected
|
||||
BuyBitcoinRequest dco_decode_box_autoadd_buy_bitcoin_request(dynamic raw);
|
||||
|
||||
@protected
|
||||
ConnectRequest dco_decode_box_autoadd_connect_request(dynamic raw);
|
||||
|
||||
@@ -134,6 +137,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
|
||||
@protected
|
||||
Payment dco_decode_box_autoadd_payment(dynamic raw);
|
||||
|
||||
@protected
|
||||
PrepareBuyBitcoinRequest dco_decode_box_autoadd_prepare_buy_bitcoin_request(dynamic raw);
|
||||
|
||||
@protected
|
||||
PreparePayOnchainRequest dco_decode_box_autoadd_prepare_pay_onchain_request(dynamic raw);
|
||||
|
||||
@@ -182,6 +188,12 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
|
||||
@protected
|
||||
UrlSuccessActionData dco_decode_box_autoadd_url_success_action_data(dynamic raw);
|
||||
|
||||
@protected
|
||||
BuyBitcoinProvider dco_decode_buy_bitcoin_provider(dynamic raw);
|
||||
|
||||
@protected
|
||||
BuyBitcoinRequest dco_decode_buy_bitcoin_request(dynamic raw);
|
||||
|
||||
@protected
|
||||
Config dco_decode_config(dynamic raw);
|
||||
|
||||
@@ -356,6 +368,12 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
|
||||
@protected
|
||||
PaymentType dco_decode_payment_type(dynamic raw);
|
||||
|
||||
@protected
|
||||
PrepareBuyBitcoinRequest dco_decode_prepare_buy_bitcoin_request(dynamic raw);
|
||||
|
||||
@protected
|
||||
PrepareBuyBitcoinResponse dco_decode_prepare_buy_bitcoin_response(dynamic raw);
|
||||
|
||||
@protected
|
||||
PreparePayOnchainRequest dco_decode_prepare_pay_onchain_request(dynamic raw);
|
||||
|
||||
@@ -516,6 +534,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
|
||||
@protected
|
||||
bool sse_decode_box_autoadd_bool(SseDeserializer deserializer);
|
||||
|
||||
@protected
|
||||
BuyBitcoinRequest sse_decode_box_autoadd_buy_bitcoin_request(SseDeserializer deserializer);
|
||||
|
||||
@protected
|
||||
ConnectRequest sse_decode_box_autoadd_connect_request(SseDeserializer deserializer);
|
||||
|
||||
@@ -564,6 +585,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
|
||||
@protected
|
||||
Payment sse_decode_box_autoadd_payment(SseDeserializer deserializer);
|
||||
|
||||
@protected
|
||||
PrepareBuyBitcoinRequest sse_decode_box_autoadd_prepare_buy_bitcoin_request(SseDeserializer deserializer);
|
||||
|
||||
@protected
|
||||
PreparePayOnchainRequest sse_decode_box_autoadd_prepare_pay_onchain_request(SseDeserializer deserializer);
|
||||
|
||||
@@ -614,6 +638,12 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
|
||||
@protected
|
||||
UrlSuccessActionData sse_decode_box_autoadd_url_success_action_data(SseDeserializer deserializer);
|
||||
|
||||
@protected
|
||||
BuyBitcoinProvider sse_decode_buy_bitcoin_provider(SseDeserializer deserializer);
|
||||
|
||||
@protected
|
||||
BuyBitcoinRequest sse_decode_buy_bitcoin_request(SseDeserializer deserializer);
|
||||
|
||||
@protected
|
||||
Config sse_decode_config(SseDeserializer deserializer);
|
||||
|
||||
@@ -788,6 +818,12 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
|
||||
@protected
|
||||
PaymentType sse_decode_payment_type(SseDeserializer deserializer);
|
||||
|
||||
@protected
|
||||
PrepareBuyBitcoinRequest sse_decode_prepare_buy_bitcoin_request(SseDeserializer deserializer);
|
||||
|
||||
@protected
|
||||
PrepareBuyBitcoinResponse sse_decode_prepare_buy_bitcoin_response(SseDeserializer deserializer);
|
||||
|
||||
@protected
|
||||
PreparePayOnchainRequest sse_decode_prepare_pay_onchain_request(SseDeserializer deserializer);
|
||||
|
||||
@@ -968,6 +1004,15 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
|
||||
return wire.cst_new_box_autoadd_bool(cst_encode_bool(raw));
|
||||
}
|
||||
|
||||
@protected
|
||||
ffi.Pointer<wire_cst_buy_bitcoin_request> cst_encode_box_autoadd_buy_bitcoin_request(
|
||||
BuyBitcoinRequest raw) {
|
||||
// Codec=Cst (C-struct based), see doc to use other codecs
|
||||
final ptr = wire.cst_new_box_autoadd_buy_bitcoin_request();
|
||||
cst_api_fill_to_wire_buy_bitcoin_request(raw, ptr.ref);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
@protected
|
||||
ffi.Pointer<wire_cst_connect_request> cst_encode_box_autoadd_connect_request(ConnectRequest raw) {
|
||||
// Codec=Cst (C-struct based), see doc to use other codecs
|
||||
@@ -1104,6 +1149,15 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
|
||||
return ptr;
|
||||
}
|
||||
|
||||
@protected
|
||||
ffi.Pointer<wire_cst_prepare_buy_bitcoin_request> cst_encode_box_autoadd_prepare_buy_bitcoin_request(
|
||||
PrepareBuyBitcoinRequest raw) {
|
||||
// Codec=Cst (C-struct based), see doc to use other codecs
|
||||
final ptr = wire.cst_new_box_autoadd_prepare_buy_bitcoin_request();
|
||||
cst_api_fill_to_wire_prepare_buy_bitcoin_request(raw, ptr.ref);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
@protected
|
||||
ffi.Pointer<wire_cst_prepare_pay_onchain_request> cst_encode_box_autoadd_prepare_pay_onchain_request(
|
||||
PreparePayOnchainRequest raw) {
|
||||
@@ -1478,6 +1532,12 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
|
||||
cst_api_fill_to_wire_bitcoin_address_data(apiObj, wireObj.ref);
|
||||
}
|
||||
|
||||
@protected
|
||||
void cst_api_fill_to_wire_box_autoadd_buy_bitcoin_request(
|
||||
BuyBitcoinRequest apiObj, ffi.Pointer<wire_cst_buy_bitcoin_request> wireObj) {
|
||||
cst_api_fill_to_wire_buy_bitcoin_request(apiObj, wireObj.ref);
|
||||
}
|
||||
|
||||
@protected
|
||||
void cst_api_fill_to_wire_box_autoadd_connect_request(
|
||||
ConnectRequest apiObj, ffi.Pointer<wire_cst_connect_request> wireObj) {
|
||||
@@ -1567,6 +1627,12 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
|
||||
cst_api_fill_to_wire_payment(apiObj, wireObj.ref);
|
||||
}
|
||||
|
||||
@protected
|
||||
void cst_api_fill_to_wire_box_autoadd_prepare_buy_bitcoin_request(
|
||||
PrepareBuyBitcoinRequest apiObj, ffi.Pointer<wire_cst_prepare_buy_bitcoin_request> wireObj) {
|
||||
cst_api_fill_to_wire_prepare_buy_bitcoin_request(apiObj, wireObj.ref);
|
||||
}
|
||||
|
||||
@protected
|
||||
void cst_api_fill_to_wire_box_autoadd_prepare_pay_onchain_request(
|
||||
PreparePayOnchainRequest apiObj, ffi.Pointer<wire_cst_prepare_pay_onchain_request> wireObj) {
|
||||
@@ -1649,6 +1715,13 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
|
||||
cst_api_fill_to_wire_url_success_action_data(apiObj, wireObj.ref);
|
||||
}
|
||||
|
||||
@protected
|
||||
void cst_api_fill_to_wire_buy_bitcoin_request(
|
||||
BuyBitcoinRequest apiObj, wire_cst_buy_bitcoin_request wireObj) {
|
||||
cst_api_fill_to_wire_prepare_buy_bitcoin_response(apiObj.prepareRes, wireObj.prepare_res);
|
||||
wireObj.redirect_url = cst_encode_opt_String(apiObj.redirectUrl);
|
||||
}
|
||||
|
||||
@protected
|
||||
void cst_api_fill_to_wire_config(Config apiObj, wire_cst_config wireObj) {
|
||||
wireObj.liquid_electrum_url = cst_encode_String(apiObj.liquidElectrumUrl);
|
||||
@@ -2202,6 +2275,21 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
|
||||
}
|
||||
}
|
||||
|
||||
@protected
|
||||
void cst_api_fill_to_wire_prepare_buy_bitcoin_request(
|
||||
PrepareBuyBitcoinRequest apiObj, wire_cst_prepare_buy_bitcoin_request wireObj) {
|
||||
wireObj.provider = cst_encode_buy_bitcoin_provider(apiObj.provider);
|
||||
wireObj.amount_sat = cst_encode_u_64(apiObj.amountSat);
|
||||
}
|
||||
|
||||
@protected
|
||||
void cst_api_fill_to_wire_prepare_buy_bitcoin_response(
|
||||
PrepareBuyBitcoinResponse apiObj, wire_cst_prepare_buy_bitcoin_response wireObj) {
|
||||
wireObj.provider = cst_encode_buy_bitcoin_provider(apiObj.provider);
|
||||
wireObj.amount_sat = cst_encode_u_64(apiObj.amountSat);
|
||||
wireObj.fees_sat = cst_encode_u_64(apiObj.feesSat);
|
||||
}
|
||||
|
||||
@protected
|
||||
void cst_api_fill_to_wire_prepare_pay_onchain_request(
|
||||
PreparePayOnchainRequest apiObj, wire_cst_prepare_pay_onchain_request wireObj) {
|
||||
@@ -2469,6 +2557,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
|
||||
@protected
|
||||
bool cst_encode_bool(bool raw);
|
||||
|
||||
@protected
|
||||
int cst_encode_buy_bitcoin_provider(BuyBitcoinProvider raw);
|
||||
|
||||
@protected
|
||||
double cst_encode_f_64(double raw);
|
||||
|
||||
@@ -2562,6 +2653,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
|
||||
@protected
|
||||
void sse_encode_box_autoadd_bool(bool self, SseSerializer serializer);
|
||||
|
||||
@protected
|
||||
void sse_encode_box_autoadd_buy_bitcoin_request(BuyBitcoinRequest self, SseSerializer serializer);
|
||||
|
||||
@protected
|
||||
void sse_encode_box_autoadd_connect_request(ConnectRequest self, SseSerializer serializer);
|
||||
|
||||
@@ -2613,6 +2707,10 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
|
||||
@protected
|
||||
void sse_encode_box_autoadd_payment(Payment self, SseSerializer serializer);
|
||||
|
||||
@protected
|
||||
void sse_encode_box_autoadd_prepare_buy_bitcoin_request(
|
||||
PrepareBuyBitcoinRequest self, SseSerializer serializer);
|
||||
|
||||
@protected
|
||||
void sse_encode_box_autoadd_prepare_pay_onchain_request(
|
||||
PreparePayOnchainRequest self, SseSerializer serializer);
|
||||
@@ -2664,6 +2762,12 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
|
||||
@protected
|
||||
void sse_encode_box_autoadd_url_success_action_data(UrlSuccessActionData self, SseSerializer serializer);
|
||||
|
||||
@protected
|
||||
void sse_encode_buy_bitcoin_provider(BuyBitcoinProvider self, SseSerializer serializer);
|
||||
|
||||
@protected
|
||||
void sse_encode_buy_bitcoin_request(BuyBitcoinRequest self, SseSerializer serializer);
|
||||
|
||||
@protected
|
||||
void sse_encode_config(Config self, SseSerializer serializer);
|
||||
|
||||
@@ -2841,6 +2945,12 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
|
||||
@protected
|
||||
void sse_encode_payment_type(PaymentType self, SseSerializer serializer);
|
||||
|
||||
@protected
|
||||
void sse_encode_prepare_buy_bitcoin_request(PrepareBuyBitcoinRequest self, SseSerializer serializer);
|
||||
|
||||
@protected
|
||||
void sse_encode_prepare_buy_bitcoin_response(PrepareBuyBitcoinResponse self, SseSerializer serializer);
|
||||
|
||||
@protected
|
||||
void sse_encode_prepare_pay_onchain_request(PreparePayOnchainRequest self, SseSerializer serializer);
|
||||
|
||||
@@ -3013,6 +3123,26 @@ class RustLibWire implements BaseWire {
|
||||
_wire__crate__bindings__BindingLiquidSdk_backupPtr
|
||||
.asFunction<WireSyncRust2DartDco Function(int, ffi.Pointer<wire_cst_backup_request>)>();
|
||||
|
||||
void wire__crate__bindings__BindingLiquidSdk_buy_bitcoin(
|
||||
int port_,
|
||||
int that,
|
||||
ffi.Pointer<wire_cst_buy_bitcoin_request> req,
|
||||
) {
|
||||
return _wire__crate__bindings__BindingLiquidSdk_buy_bitcoin(
|
||||
port_,
|
||||
that,
|
||||
req,
|
||||
);
|
||||
}
|
||||
|
||||
late final _wire__crate__bindings__BindingLiquidSdk_buy_bitcoinPtr = _lookup<
|
||||
ffi.NativeFunction<
|
||||
ffi.Void Function(ffi.Int64, ffi.UintPtr, ffi.Pointer<wire_cst_buy_bitcoin_request>)>>(
|
||||
'frbgen_breez_liquid_wire__crate__bindings__BindingLiquidSdk_buy_bitcoin');
|
||||
late final _wire__crate__bindings__BindingLiquidSdk_buy_bitcoin =
|
||||
_wire__crate__bindings__BindingLiquidSdk_buy_bitcoinPtr
|
||||
.asFunction<void Function(int, int, ffi.Pointer<wire_cst_buy_bitcoin_request>)>();
|
||||
|
||||
void wire__crate__bindings__BindingLiquidSdk_disconnect(
|
||||
int port_,
|
||||
int that,
|
||||
@@ -3241,6 +3371,26 @@ class RustLibWire implements BaseWire {
|
||||
_wire__crate__bindings__BindingLiquidSdk_pay_onchainPtr
|
||||
.asFunction<void Function(int, int, ffi.Pointer<wire_cst_pay_onchain_request>)>();
|
||||
|
||||
void wire__crate__bindings__BindingLiquidSdk_prepare_buy_bitcoin(
|
||||
int port_,
|
||||
int that,
|
||||
ffi.Pointer<wire_cst_prepare_buy_bitcoin_request> req,
|
||||
) {
|
||||
return _wire__crate__bindings__BindingLiquidSdk_prepare_buy_bitcoin(
|
||||
port_,
|
||||
that,
|
||||
req,
|
||||
);
|
||||
}
|
||||
|
||||
late final _wire__crate__bindings__BindingLiquidSdk_prepare_buy_bitcoinPtr = _lookup<
|
||||
ffi.NativeFunction<
|
||||
ffi.Void Function(ffi.Int64, ffi.UintPtr, ffi.Pointer<wire_cst_prepare_buy_bitcoin_request>)>>(
|
||||
'frbgen_breez_liquid_wire__crate__bindings__BindingLiquidSdk_prepare_buy_bitcoin');
|
||||
late final _wire__crate__bindings__BindingLiquidSdk_prepare_buy_bitcoin =
|
||||
_wire__crate__bindings__BindingLiquidSdk_prepare_buy_bitcoinPtr
|
||||
.asFunction<void Function(int, int, ffi.Pointer<wire_cst_prepare_buy_bitcoin_request>)>();
|
||||
|
||||
void wire__crate__bindings__BindingLiquidSdk_prepare_pay_onchain(
|
||||
int port_,
|
||||
int that,
|
||||
@@ -3686,6 +3836,16 @@ class RustLibWire implements BaseWire {
|
||||
late final _cst_new_box_autoadd_bool =
|
||||
_cst_new_box_autoadd_boolPtr.asFunction<ffi.Pointer<ffi.Bool> Function(bool)>();
|
||||
|
||||
ffi.Pointer<wire_cst_buy_bitcoin_request> cst_new_box_autoadd_buy_bitcoin_request() {
|
||||
return _cst_new_box_autoadd_buy_bitcoin_request();
|
||||
}
|
||||
|
||||
late final _cst_new_box_autoadd_buy_bitcoin_requestPtr =
|
||||
_lookup<ffi.NativeFunction<ffi.Pointer<wire_cst_buy_bitcoin_request> Function()>>(
|
||||
'frbgen_breez_liquid_cst_new_box_autoadd_buy_bitcoin_request');
|
||||
late final _cst_new_box_autoadd_buy_bitcoin_request = _cst_new_box_autoadd_buy_bitcoin_requestPtr
|
||||
.asFunction<ffi.Pointer<wire_cst_buy_bitcoin_request> Function()>();
|
||||
|
||||
ffi.Pointer<wire_cst_connect_request> cst_new_box_autoadd_connect_request() {
|
||||
return _cst_new_box_autoadd_connect_request();
|
||||
}
|
||||
@@ -3853,6 +4013,17 @@ class RustLibWire implements BaseWire {
|
||||
late final _cst_new_box_autoadd_payment =
|
||||
_cst_new_box_autoadd_paymentPtr.asFunction<ffi.Pointer<wire_cst_payment> Function()>();
|
||||
|
||||
ffi.Pointer<wire_cst_prepare_buy_bitcoin_request> cst_new_box_autoadd_prepare_buy_bitcoin_request() {
|
||||
return _cst_new_box_autoadd_prepare_buy_bitcoin_request();
|
||||
}
|
||||
|
||||
late final _cst_new_box_autoadd_prepare_buy_bitcoin_requestPtr =
|
||||
_lookup<ffi.NativeFunction<ffi.Pointer<wire_cst_prepare_buy_bitcoin_request> Function()>>(
|
||||
'frbgen_breez_liquid_cst_new_box_autoadd_prepare_buy_bitcoin_request');
|
||||
late final _cst_new_box_autoadd_prepare_buy_bitcoin_request =
|
||||
_cst_new_box_autoadd_prepare_buy_bitcoin_requestPtr
|
||||
.asFunction<ffi.Pointer<wire_cst_prepare_buy_bitcoin_request> Function()>();
|
||||
|
||||
ffi.Pointer<wire_cst_prepare_pay_onchain_request> cst_new_box_autoadd_prepare_pay_onchain_request() {
|
||||
return _cst_new_box_autoadd_prepare_pay_onchain_request();
|
||||
}
|
||||
@@ -4194,6 +4365,23 @@ final class wire_cst_backup_request extends ffi.Struct {
|
||||
external ffi.Pointer<wire_cst_list_prim_u_8_strict> backup_path;
|
||||
}
|
||||
|
||||
final class wire_cst_prepare_buy_bitcoin_response extends ffi.Struct {
|
||||
@ffi.Int32()
|
||||
external int provider;
|
||||
|
||||
@ffi.Uint64()
|
||||
external int amount_sat;
|
||||
|
||||
@ffi.Uint64()
|
||||
external int fees_sat;
|
||||
}
|
||||
|
||||
final class wire_cst_buy_bitcoin_request extends ffi.Struct {
|
||||
external wire_cst_prepare_buy_bitcoin_response prepare_res;
|
||||
|
||||
external ffi.Pointer<wire_cst_list_prim_u_8_strict> redirect_url;
|
||||
}
|
||||
|
||||
final class wire_cst_list_payment_type extends ffi.Struct {
|
||||
external ffi.Pointer<ffi.Int32> ptr;
|
||||
|
||||
@@ -4300,6 +4488,14 @@ final class wire_cst_pay_onchain_request extends ffi.Struct {
|
||||
external wire_cst_prepare_pay_onchain_response prepare_res;
|
||||
}
|
||||
|
||||
final class wire_cst_prepare_buy_bitcoin_request extends ffi.Struct {
|
||||
@ffi.Int32()
|
||||
external int provider;
|
||||
|
||||
@ffi.Uint64()
|
||||
external int amount_sat;
|
||||
}
|
||||
|
||||
final class wire_cst_prepare_pay_onchain_request extends ffi.Struct {
|
||||
@ffi.Uint64()
|
||||
external int receiver_amount_sat;
|
||||
|
||||
@@ -29,6 +29,36 @@ class BackupRequest {
|
||||
other is BackupRequest && runtimeType == other.runtimeType && backupPath == other.backupPath;
|
||||
}
|
||||
|
||||
enum BuyBitcoinProvider {
|
||||
moonpay,
|
||||
;
|
||||
}
|
||||
|
||||
class BuyBitcoinRequest {
|
||||
final PrepareBuyBitcoinResponse prepareRes;
|
||||
|
||||
/// The optional URL to redirect to after completing the buy.
|
||||
///
|
||||
/// For Moonpay, see <https://dev.moonpay.com/docs/on-ramp-configure-user-journey-params>
|
||||
final String? redirectUrl;
|
||||
|
||||
const BuyBitcoinRequest({
|
||||
required this.prepareRes,
|
||||
this.redirectUrl,
|
||||
});
|
||||
|
||||
@override
|
||||
int get hashCode => prepareRes.hashCode ^ redirectUrl.hashCode;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
other is BuyBitcoinRequest &&
|
||||
runtimeType == other.runtimeType &&
|
||||
prepareRes == other.prepareRes &&
|
||||
redirectUrl == other.redirectUrl;
|
||||
}
|
||||
|
||||
/// Configuration for the Liquid SDK
|
||||
class Config {
|
||||
final String liquidElectrumUrl;
|
||||
@@ -516,6 +546,51 @@ enum PaymentType {
|
||||
;
|
||||
}
|
||||
|
||||
class PrepareBuyBitcoinRequest {
|
||||
final BuyBitcoinProvider provider;
|
||||
final BigInt amountSat;
|
||||
|
||||
const PrepareBuyBitcoinRequest({
|
||||
required this.provider,
|
||||
required this.amountSat,
|
||||
});
|
||||
|
||||
@override
|
||||
int get hashCode => provider.hashCode ^ amountSat.hashCode;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
other is PrepareBuyBitcoinRequest &&
|
||||
runtimeType == other.runtimeType &&
|
||||
provider == other.provider &&
|
||||
amountSat == other.amountSat;
|
||||
}
|
||||
|
||||
class PrepareBuyBitcoinResponse {
|
||||
final BuyBitcoinProvider provider;
|
||||
final BigInt amountSat;
|
||||
final BigInt feesSat;
|
||||
|
||||
const PrepareBuyBitcoinResponse({
|
||||
required this.provider,
|
||||
required this.amountSat,
|
||||
required this.feesSat,
|
||||
});
|
||||
|
||||
@override
|
||||
int get hashCode => provider.hashCode ^ amountSat.hashCode ^ feesSat.hashCode;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
other is PrepareBuyBitcoinResponse &&
|
||||
runtimeType == other.runtimeType &&
|
||||
provider == other.provider &&
|
||||
amountSat == other.amountSat &&
|
||||
feesSat == other.feesSat;
|
||||
}
|
||||
|
||||
class PreparePayOnchainRequest {
|
||||
final BigInt receiverAmountSat;
|
||||
final int? satPerVbyte;
|
||||
|
||||
@@ -75,6 +75,26 @@ class FlutterBreezLiquidBindings {
|
||||
_frbgen_breez_liquid_wire__crate__bindings__BindingLiquidSdk_backupPtr
|
||||
.asFunction<WireSyncRust2DartDco Function(int, ffi.Pointer<wire_cst_backup_request>)>();
|
||||
|
||||
void frbgen_breez_liquid_wire__crate__bindings__BindingLiquidSdk_buy_bitcoin(
|
||||
int port_,
|
||||
int that,
|
||||
ffi.Pointer<wire_cst_buy_bitcoin_request> req,
|
||||
) {
|
||||
return _frbgen_breez_liquid_wire__crate__bindings__BindingLiquidSdk_buy_bitcoin(
|
||||
port_,
|
||||
that,
|
||||
req,
|
||||
);
|
||||
}
|
||||
|
||||
late final _frbgen_breez_liquid_wire__crate__bindings__BindingLiquidSdk_buy_bitcoinPtr = _lookup<
|
||||
ffi.NativeFunction<
|
||||
ffi.Void Function(ffi.Int64, ffi.UintPtr, ffi.Pointer<wire_cst_buy_bitcoin_request>)>>(
|
||||
'frbgen_breez_liquid_wire__crate__bindings__BindingLiquidSdk_buy_bitcoin');
|
||||
late final _frbgen_breez_liquid_wire__crate__bindings__BindingLiquidSdk_buy_bitcoin =
|
||||
_frbgen_breez_liquid_wire__crate__bindings__BindingLiquidSdk_buy_bitcoinPtr
|
||||
.asFunction<void Function(int, int, ffi.Pointer<wire_cst_buy_bitcoin_request>)>();
|
||||
|
||||
void frbgen_breez_liquid_wire__crate__bindings__BindingLiquidSdk_disconnect(
|
||||
int port_,
|
||||
int that,
|
||||
@@ -309,6 +329,26 @@ class FlutterBreezLiquidBindings {
|
||||
_frbgen_breez_liquid_wire__crate__bindings__BindingLiquidSdk_pay_onchainPtr
|
||||
.asFunction<void Function(int, int, ffi.Pointer<wire_cst_pay_onchain_request>)>();
|
||||
|
||||
void frbgen_breez_liquid_wire__crate__bindings__BindingLiquidSdk_prepare_buy_bitcoin(
|
||||
int port_,
|
||||
int that,
|
||||
ffi.Pointer<wire_cst_prepare_buy_bitcoin_request> req,
|
||||
) {
|
||||
return _frbgen_breez_liquid_wire__crate__bindings__BindingLiquidSdk_prepare_buy_bitcoin(
|
||||
port_,
|
||||
that,
|
||||
req,
|
||||
);
|
||||
}
|
||||
|
||||
late final _frbgen_breez_liquid_wire__crate__bindings__BindingLiquidSdk_prepare_buy_bitcoinPtr = _lookup<
|
||||
ffi.NativeFunction<
|
||||
ffi.Void Function(ffi.Int64, ffi.UintPtr, ffi.Pointer<wire_cst_prepare_buy_bitcoin_request>)>>(
|
||||
'frbgen_breez_liquid_wire__crate__bindings__BindingLiquidSdk_prepare_buy_bitcoin');
|
||||
late final _frbgen_breez_liquid_wire__crate__bindings__BindingLiquidSdk_prepare_buy_bitcoin =
|
||||
_frbgen_breez_liquid_wire__crate__bindings__BindingLiquidSdk_prepare_buy_bitcoinPtr
|
||||
.asFunction<void Function(int, int, ffi.Pointer<wire_cst_prepare_buy_bitcoin_request>)>();
|
||||
|
||||
void frbgen_breez_liquid_wire__crate__bindings__BindingLiquidSdk_prepare_pay_onchain(
|
||||
int port_,
|
||||
int that,
|
||||
@@ -769,6 +809,17 @@ class FlutterBreezLiquidBindings {
|
||||
late final _frbgen_breez_liquid_cst_new_box_autoadd_bool =
|
||||
_frbgen_breez_liquid_cst_new_box_autoadd_boolPtr.asFunction<ffi.Pointer<ffi.Bool> Function(bool)>();
|
||||
|
||||
ffi.Pointer<wire_cst_buy_bitcoin_request> frbgen_breez_liquid_cst_new_box_autoadd_buy_bitcoin_request() {
|
||||
return _frbgen_breez_liquid_cst_new_box_autoadd_buy_bitcoin_request();
|
||||
}
|
||||
|
||||
late final _frbgen_breez_liquid_cst_new_box_autoadd_buy_bitcoin_requestPtr =
|
||||
_lookup<ffi.NativeFunction<ffi.Pointer<wire_cst_buy_bitcoin_request> Function()>>(
|
||||
'frbgen_breez_liquid_cst_new_box_autoadd_buy_bitcoin_request');
|
||||
late final _frbgen_breez_liquid_cst_new_box_autoadd_buy_bitcoin_request =
|
||||
_frbgen_breez_liquid_cst_new_box_autoadd_buy_bitcoin_requestPtr
|
||||
.asFunction<ffi.Pointer<wire_cst_buy_bitcoin_request> Function()>();
|
||||
|
||||
ffi.Pointer<wire_cst_connect_request> frbgen_breez_liquid_cst_new_box_autoadd_connect_request() {
|
||||
return _frbgen_breez_liquid_cst_new_box_autoadd_connect_request();
|
||||
}
|
||||
@@ -957,6 +1008,18 @@ class FlutterBreezLiquidBindings {
|
||||
_frbgen_breez_liquid_cst_new_box_autoadd_paymentPtr
|
||||
.asFunction<ffi.Pointer<wire_cst_payment> Function()>();
|
||||
|
||||
ffi.Pointer<wire_cst_prepare_buy_bitcoin_request>
|
||||
frbgen_breez_liquid_cst_new_box_autoadd_prepare_buy_bitcoin_request() {
|
||||
return _frbgen_breez_liquid_cst_new_box_autoadd_prepare_buy_bitcoin_request();
|
||||
}
|
||||
|
||||
late final _frbgen_breez_liquid_cst_new_box_autoadd_prepare_buy_bitcoin_requestPtr =
|
||||
_lookup<ffi.NativeFunction<ffi.Pointer<wire_cst_prepare_buy_bitcoin_request> Function()>>(
|
||||
'frbgen_breez_liquid_cst_new_box_autoadd_prepare_buy_bitcoin_request');
|
||||
late final _frbgen_breez_liquid_cst_new_box_autoadd_prepare_buy_bitcoin_request =
|
||||
_frbgen_breez_liquid_cst_new_box_autoadd_prepare_buy_bitcoin_requestPtr
|
||||
.asFunction<ffi.Pointer<wire_cst_prepare_buy_bitcoin_request> Function()>();
|
||||
|
||||
ffi.Pointer<wire_cst_prepare_pay_onchain_request>
|
||||
frbgen_breez_liquid_cst_new_box_autoadd_prepare_pay_onchain_request() {
|
||||
return _frbgen_breez_liquid_cst_new_box_autoadd_prepare_pay_onchain_request();
|
||||
@@ -1334,6 +1397,23 @@ final class wire_cst_backup_request extends ffi.Struct {
|
||||
external ffi.Pointer<wire_cst_list_prim_u_8_strict> backup_path;
|
||||
}
|
||||
|
||||
final class wire_cst_prepare_buy_bitcoin_response extends ffi.Struct {
|
||||
@ffi.Int32()
|
||||
external int provider;
|
||||
|
||||
@ffi.Uint64()
|
||||
external int amount_sat;
|
||||
|
||||
@ffi.Uint64()
|
||||
external int fees_sat;
|
||||
}
|
||||
|
||||
final class wire_cst_buy_bitcoin_request extends ffi.Struct {
|
||||
external wire_cst_prepare_buy_bitcoin_response prepare_res;
|
||||
|
||||
external ffi.Pointer<wire_cst_list_prim_u_8_strict> redirect_url;
|
||||
}
|
||||
|
||||
final class wire_cst_list_payment_type extends ffi.Struct {
|
||||
external ffi.Pointer<ffi.Int32> ptr;
|
||||
|
||||
@@ -1440,6 +1520,14 @@ final class wire_cst_pay_onchain_request extends ffi.Struct {
|
||||
external wire_cst_prepare_pay_onchain_response prepare_res;
|
||||
}
|
||||
|
||||
final class wire_cst_prepare_buy_bitcoin_request extends ffi.Struct {
|
||||
@ffi.Int32()
|
||||
external int provider;
|
||||
|
||||
@ffi.Uint64()
|
||||
external int amount_sat;
|
||||
}
|
||||
|
||||
final class wire_cst_prepare_pay_onchain_request extends ffi.Struct {
|
||||
@ffi.Uint64()
|
||||
external int receiver_amount_sat;
|
||||
|
||||
@@ -114,6 +114,41 @@ fun asBitcoinAddressDataList(arr: ReadableArray): List<BitcoinAddressData> {
|
||||
return list
|
||||
}
|
||||
|
||||
fun asBuyBitcoinRequest(buyBitcoinRequest: ReadableMap): BuyBitcoinRequest? {
|
||||
if (!validateMandatoryFields(
|
||||
buyBitcoinRequest,
|
||||
arrayOf(
|
||||
"prepareRes",
|
||||
),
|
||||
)
|
||||
) {
|
||||
return null
|
||||
}
|
||||
val prepareRes = buyBitcoinRequest.getMap("prepareRes")?.let { asPrepareBuyBitcoinResponse(it) }!!
|
||||
val redirectUrl = if (hasNonNullKey(buyBitcoinRequest, "redirectUrl")) buyBitcoinRequest.getString("redirectUrl") else null
|
||||
return BuyBitcoinRequest(
|
||||
prepareRes,
|
||||
redirectUrl,
|
||||
)
|
||||
}
|
||||
|
||||
fun readableMapOf(buyBitcoinRequest: BuyBitcoinRequest): ReadableMap =
|
||||
readableMapOf(
|
||||
"prepareRes" to readableMapOf(buyBitcoinRequest.prepareRes),
|
||||
"redirectUrl" to buyBitcoinRequest.redirectUrl,
|
||||
)
|
||||
|
||||
fun asBuyBitcoinRequestList(arr: ReadableArray): List<BuyBitcoinRequest> {
|
||||
val list = ArrayList<BuyBitcoinRequest>()
|
||||
for (value in arr.toArrayList()) {
|
||||
when (value) {
|
||||
is ReadableMap -> list.add(asBuyBitcoinRequest(value)!!)
|
||||
else -> throw SdkException.Generic(errUnexpectedType("${value::class.java.name}"))
|
||||
}
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
fun asConfig(config: ReadableMap): Config? {
|
||||
if (!validateMandatoryFields(
|
||||
config,
|
||||
@@ -1227,6 +1262,82 @@ fun asPaymentList(arr: ReadableArray): List<Payment> {
|
||||
return list
|
||||
}
|
||||
|
||||
fun asPrepareBuyBitcoinRequest(prepareBuyBitcoinRequest: ReadableMap): PrepareBuyBitcoinRequest? {
|
||||
if (!validateMandatoryFields(
|
||||
prepareBuyBitcoinRequest,
|
||||
arrayOf(
|
||||
"provider",
|
||||
"amountSat",
|
||||
),
|
||||
)
|
||||
) {
|
||||
return null
|
||||
}
|
||||
val provider = prepareBuyBitcoinRequest.getString("provider")?.let { asBuyBitcoinProvider(it) }!!
|
||||
val amountSat = prepareBuyBitcoinRequest.getDouble("amountSat").toULong()
|
||||
return PrepareBuyBitcoinRequest(
|
||||
provider,
|
||||
amountSat,
|
||||
)
|
||||
}
|
||||
|
||||
fun readableMapOf(prepareBuyBitcoinRequest: PrepareBuyBitcoinRequest): ReadableMap =
|
||||
readableMapOf(
|
||||
"provider" to prepareBuyBitcoinRequest.provider.name.lowercase(),
|
||||
"amountSat" to prepareBuyBitcoinRequest.amountSat,
|
||||
)
|
||||
|
||||
fun asPrepareBuyBitcoinRequestList(arr: ReadableArray): List<PrepareBuyBitcoinRequest> {
|
||||
val list = ArrayList<PrepareBuyBitcoinRequest>()
|
||||
for (value in arr.toArrayList()) {
|
||||
when (value) {
|
||||
is ReadableMap -> list.add(asPrepareBuyBitcoinRequest(value)!!)
|
||||
else -> throw SdkException.Generic(errUnexpectedType("${value::class.java.name}"))
|
||||
}
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
fun asPrepareBuyBitcoinResponse(prepareBuyBitcoinResponse: ReadableMap): PrepareBuyBitcoinResponse? {
|
||||
if (!validateMandatoryFields(
|
||||
prepareBuyBitcoinResponse,
|
||||
arrayOf(
|
||||
"provider",
|
||||
"amountSat",
|
||||
"feesSat",
|
||||
),
|
||||
)
|
||||
) {
|
||||
return null
|
||||
}
|
||||
val provider = prepareBuyBitcoinResponse.getString("provider")?.let { asBuyBitcoinProvider(it) }!!
|
||||
val amountSat = prepareBuyBitcoinResponse.getDouble("amountSat").toULong()
|
||||
val feesSat = prepareBuyBitcoinResponse.getDouble("feesSat").toULong()
|
||||
return PrepareBuyBitcoinResponse(
|
||||
provider,
|
||||
amountSat,
|
||||
feesSat,
|
||||
)
|
||||
}
|
||||
|
||||
fun readableMapOf(prepareBuyBitcoinResponse: PrepareBuyBitcoinResponse): ReadableMap =
|
||||
readableMapOf(
|
||||
"provider" to prepareBuyBitcoinResponse.provider.name.lowercase(),
|
||||
"amountSat" to prepareBuyBitcoinResponse.amountSat,
|
||||
"feesSat" to prepareBuyBitcoinResponse.feesSat,
|
||||
)
|
||||
|
||||
fun asPrepareBuyBitcoinResponseList(arr: ReadableArray): List<PrepareBuyBitcoinResponse> {
|
||||
val list = ArrayList<PrepareBuyBitcoinResponse>()
|
||||
for (value in arr.toArrayList()) {
|
||||
when (value) {
|
||||
is ReadableMap -> list.add(asPrepareBuyBitcoinResponse(value)!!)
|
||||
else -> throw SdkException.Generic(errUnexpectedType("${value::class.java.name}"))
|
||||
}
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
fun asPreparePayOnchainRequest(preparePayOnchainRequest: ReadableMap): PreparePayOnchainRequest? {
|
||||
if (!validateMandatoryFields(
|
||||
preparePayOnchainRequest,
|
||||
@@ -2129,6 +2240,19 @@ fun asAesSuccessActionDataResultList(arr: ReadableArray): List<AesSuccessActionD
|
||||
return list
|
||||
}
|
||||
|
||||
fun asBuyBitcoinProvider(type: String): BuyBitcoinProvider = BuyBitcoinProvider.valueOf(camelToUpperSnakeCase(type))
|
||||
|
||||
fun asBuyBitcoinProviderList(arr: ReadableArray): List<BuyBitcoinProvider> {
|
||||
val list = ArrayList<BuyBitcoinProvider>()
|
||||
for (value in arr.toArrayList()) {
|
||||
when (value) {
|
||||
is String -> list.add(asBuyBitcoinProvider(value)!!)
|
||||
else -> throw SdkException.Generic(errUnexpectedType("${value::class.java.name}"))
|
||||
}
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
fun asInputType(inputType: ReadableMap): InputType? {
|
||||
val type = inputType.getString("type")
|
||||
|
||||
|
||||
@@ -351,6 +351,41 @@ class BreezSDKLiquidModule(
|
||||
}
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
fun prepareBuyBitcoin(
|
||||
req: ReadableMap,
|
||||
promise: Promise,
|
||||
) {
|
||||
executor.execute {
|
||||
try {
|
||||
val prepareBuyBitcoinRequest =
|
||||
asPrepareBuyBitcoinRequest(req)
|
||||
?: run { throw SdkException.Generic(errMissingMandatoryField("req", "PrepareBuyBitcoinRequest")) }
|
||||
val res = getBindingLiquidSdk().prepareBuyBitcoin(prepareBuyBitcoinRequest)
|
||||
promise.resolve(readableMapOf(res))
|
||||
} catch (e: Exception) {
|
||||
promise.reject(e.javaClass.simpleName.replace("Exception", "Error"), e.message, e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
fun buyBitcoin(
|
||||
req: ReadableMap,
|
||||
promise: Promise,
|
||||
) {
|
||||
executor.execute {
|
||||
try {
|
||||
val buyBitcoinRequest =
|
||||
asBuyBitcoinRequest(req) ?: run { throw SdkException.Generic(errMissingMandatoryField("req", "BuyBitcoinRequest")) }
|
||||
val res = getBindingLiquidSdk().buyBitcoin(buyBitcoinRequest)
|
||||
promise.resolve(res)
|
||||
} catch (e: Exception) {
|
||||
promise.reject(e.javaClass.simpleName.replace("Exception", "Error"), e.message, e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
fun listPayments(
|
||||
req: ReadableMap,
|
||||
|
||||
@@ -143,6 +143,50 @@ enum BreezSDKLiquidMapper {
|
||||
return bitcoinAddressDataList.map { v -> [String: Any?] in return dictionaryOf(bitcoinAddressData: v) }
|
||||
}
|
||||
|
||||
static func asBuyBitcoinRequest(buyBitcoinRequest: [String: Any?]) throws -> BuyBitcoinRequest {
|
||||
guard let prepareResTmp = buyBitcoinRequest["prepareRes"] as? [String: Any?] else {
|
||||
throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "prepareRes", typeName: "BuyBitcoinRequest"))
|
||||
}
|
||||
let prepareRes = try asPrepareBuyBitcoinResponse(prepareBuyBitcoinResponse: prepareResTmp)
|
||||
|
||||
var redirectUrl: String?
|
||||
if hasNonNilKey(data: buyBitcoinRequest, key: "redirectUrl") {
|
||||
guard let redirectUrlTmp = buyBitcoinRequest["redirectUrl"] as? String else {
|
||||
throw SdkError.Generic(message: errUnexpectedValue(fieldName: "redirectUrl"))
|
||||
}
|
||||
redirectUrl = redirectUrlTmp
|
||||
}
|
||||
|
||||
return BuyBitcoinRequest(
|
||||
prepareRes: prepareRes,
|
||||
redirectUrl: redirectUrl
|
||||
)
|
||||
}
|
||||
|
||||
static func dictionaryOf(buyBitcoinRequest: BuyBitcoinRequest) -> [String: Any?] {
|
||||
return [
|
||||
"prepareRes": dictionaryOf(prepareBuyBitcoinResponse: buyBitcoinRequest.prepareRes),
|
||||
"redirectUrl": buyBitcoinRequest.redirectUrl == nil ? nil : buyBitcoinRequest.redirectUrl,
|
||||
]
|
||||
}
|
||||
|
||||
static func asBuyBitcoinRequestList(arr: [Any]) throws -> [BuyBitcoinRequest] {
|
||||
var list = [BuyBitcoinRequest]()
|
||||
for value in arr {
|
||||
if let val = value as? [String: Any?] {
|
||||
var buyBitcoinRequest = try asBuyBitcoinRequest(buyBitcoinRequest: val)
|
||||
list.append(buyBitcoinRequest)
|
||||
} else {
|
||||
throw SdkError.Generic(message: errUnexpectedType(typeName: "BuyBitcoinRequest"))
|
||||
}
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
static func arrayOf(buyBitcoinRequestList: [BuyBitcoinRequest]) -> [Any] {
|
||||
return buyBitcoinRequestList.map { v -> [String: Any?] in return dictionaryOf(buyBitcoinRequest: v) }
|
||||
}
|
||||
|
||||
static func asConfig(config: [String: Any?]) throws -> Config {
|
||||
guard let liquidElectrumUrl = config["liquidElectrumUrl"] as? String else {
|
||||
throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "liquidElectrumUrl", typeName: "Config"))
|
||||
@@ -1470,6 +1514,91 @@ enum BreezSDKLiquidMapper {
|
||||
return paymentList.map { v -> [String: Any?] in return dictionaryOf(payment: v) }
|
||||
}
|
||||
|
||||
static func asPrepareBuyBitcoinRequest(prepareBuyBitcoinRequest: [String: Any?]) throws -> PrepareBuyBitcoinRequest {
|
||||
guard let providerTmp = prepareBuyBitcoinRequest["provider"] as? String else {
|
||||
throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "provider", typeName: "PrepareBuyBitcoinRequest"))
|
||||
}
|
||||
let provider = try asBuyBitcoinProvider(buyBitcoinProvider: providerTmp)
|
||||
|
||||
guard let amountSat = prepareBuyBitcoinRequest["amountSat"] as? UInt64 else {
|
||||
throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "amountSat", typeName: "PrepareBuyBitcoinRequest"))
|
||||
}
|
||||
|
||||
return PrepareBuyBitcoinRequest(
|
||||
provider: provider,
|
||||
amountSat: amountSat
|
||||
)
|
||||
}
|
||||
|
||||
static func dictionaryOf(prepareBuyBitcoinRequest: PrepareBuyBitcoinRequest) -> [String: Any?] {
|
||||
return [
|
||||
"provider": valueOf(buyBitcoinProvider: prepareBuyBitcoinRequest.provider),
|
||||
"amountSat": prepareBuyBitcoinRequest.amountSat,
|
||||
]
|
||||
}
|
||||
|
||||
static func asPrepareBuyBitcoinRequestList(arr: [Any]) throws -> [PrepareBuyBitcoinRequest] {
|
||||
var list = [PrepareBuyBitcoinRequest]()
|
||||
for value in arr {
|
||||
if let val = value as? [String: Any?] {
|
||||
var prepareBuyBitcoinRequest = try asPrepareBuyBitcoinRequest(prepareBuyBitcoinRequest: val)
|
||||
list.append(prepareBuyBitcoinRequest)
|
||||
} else {
|
||||
throw SdkError.Generic(message: errUnexpectedType(typeName: "PrepareBuyBitcoinRequest"))
|
||||
}
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
static func arrayOf(prepareBuyBitcoinRequestList: [PrepareBuyBitcoinRequest]) -> [Any] {
|
||||
return prepareBuyBitcoinRequestList.map { v -> [String: Any?] in return dictionaryOf(prepareBuyBitcoinRequest: v) }
|
||||
}
|
||||
|
||||
static func asPrepareBuyBitcoinResponse(prepareBuyBitcoinResponse: [String: Any?]) throws -> PrepareBuyBitcoinResponse {
|
||||
guard let providerTmp = prepareBuyBitcoinResponse["provider"] as? String else {
|
||||
throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "provider", typeName: "PrepareBuyBitcoinResponse"))
|
||||
}
|
||||
let provider = try asBuyBitcoinProvider(buyBitcoinProvider: providerTmp)
|
||||
|
||||
guard let amountSat = prepareBuyBitcoinResponse["amountSat"] as? UInt64 else {
|
||||
throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "amountSat", typeName: "PrepareBuyBitcoinResponse"))
|
||||
}
|
||||
guard let feesSat = prepareBuyBitcoinResponse["feesSat"] as? UInt64 else {
|
||||
throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "feesSat", typeName: "PrepareBuyBitcoinResponse"))
|
||||
}
|
||||
|
||||
return PrepareBuyBitcoinResponse(
|
||||
provider: provider,
|
||||
amountSat: amountSat,
|
||||
feesSat: feesSat
|
||||
)
|
||||
}
|
||||
|
||||
static func dictionaryOf(prepareBuyBitcoinResponse: PrepareBuyBitcoinResponse) -> [String: Any?] {
|
||||
return [
|
||||
"provider": valueOf(buyBitcoinProvider: prepareBuyBitcoinResponse.provider),
|
||||
"amountSat": prepareBuyBitcoinResponse.amountSat,
|
||||
"feesSat": prepareBuyBitcoinResponse.feesSat,
|
||||
]
|
||||
}
|
||||
|
||||
static func asPrepareBuyBitcoinResponseList(arr: [Any]) throws -> [PrepareBuyBitcoinResponse] {
|
||||
var list = [PrepareBuyBitcoinResponse]()
|
||||
for value in arr {
|
||||
if let val = value as? [String: Any?] {
|
||||
var prepareBuyBitcoinResponse = try asPrepareBuyBitcoinResponse(prepareBuyBitcoinResponse: val)
|
||||
list.append(prepareBuyBitcoinResponse)
|
||||
} else {
|
||||
throw SdkError.Generic(message: errUnexpectedType(typeName: "PrepareBuyBitcoinResponse"))
|
||||
}
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
static func arrayOf(prepareBuyBitcoinResponseList: [PrepareBuyBitcoinResponse]) -> [Any] {
|
||||
return prepareBuyBitcoinResponseList.map { v -> [String: Any?] in return dictionaryOf(prepareBuyBitcoinResponse: v) }
|
||||
}
|
||||
|
||||
static func asPreparePayOnchainRequest(preparePayOnchainRequest: [String: Any?]) throws -> PreparePayOnchainRequest {
|
||||
guard let receiverAmountSat = preparePayOnchainRequest["receiverAmountSat"] as? UInt64 else {
|
||||
throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "receiverAmountSat", typeName: "PreparePayOnchainRequest"))
|
||||
@@ -2477,6 +2606,39 @@ enum BreezSDKLiquidMapper {
|
||||
return list
|
||||
}
|
||||
|
||||
static func asBuyBitcoinProvider(buyBitcoinProvider: String) throws -> BuyBitcoinProvider {
|
||||
switch buyBitcoinProvider {
|
||||
case "moonpay":
|
||||
return BuyBitcoinProvider.moonpay
|
||||
|
||||
default: throw SdkError.Generic(message: "Invalid variant \(buyBitcoinProvider) for enum BuyBitcoinProvider")
|
||||
}
|
||||
}
|
||||
|
||||
static func valueOf(buyBitcoinProvider: BuyBitcoinProvider) -> String {
|
||||
switch buyBitcoinProvider {
|
||||
case .moonpay:
|
||||
return "moonpay"
|
||||
}
|
||||
}
|
||||
|
||||
static func arrayOf(buyBitcoinProviderList: [BuyBitcoinProvider]) -> [String] {
|
||||
return buyBitcoinProviderList.map { v -> String in return valueOf(buyBitcoinProvider: v) }
|
||||
}
|
||||
|
||||
static func asBuyBitcoinProviderList(arr: [Any]) throws -> [BuyBitcoinProvider] {
|
||||
var list = [BuyBitcoinProvider]()
|
||||
for value in arr {
|
||||
if let val = value as? String {
|
||||
var buyBitcoinProvider = try asBuyBitcoinProvider(buyBitcoinProvider: val)
|
||||
list.append(buyBitcoinProvider)
|
||||
} else {
|
||||
throw SdkError.Generic(message: errUnexpectedType(typeName: "BuyBitcoinProvider"))
|
||||
}
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
static func asInputType(inputType: [String: Any?]) throws -> InputType {
|
||||
let type = inputType["type"] as! String
|
||||
if type == "bitcoinAddress" {
|
||||
|
||||
@@ -106,6 +106,18 @@ RCT_EXTERN_METHOD(
|
||||
reject: (RCTPromiseRejectBlock)reject
|
||||
)
|
||||
|
||||
RCT_EXTERN_METHOD(
|
||||
prepareBuyBitcoin: (NSDictionary*)req
|
||||
resolve: (RCTPromiseResolveBlock)resolve
|
||||
reject: (RCTPromiseRejectBlock)reject
|
||||
)
|
||||
|
||||
RCT_EXTERN_METHOD(
|
||||
buyBitcoin: (NSDictionary*)req
|
||||
resolve: (RCTPromiseResolveBlock)resolve
|
||||
reject: (RCTPromiseRejectBlock)reject
|
||||
)
|
||||
|
||||
RCT_EXTERN_METHOD(
|
||||
listPayments: (NSDictionary*)req
|
||||
resolve: (RCTPromiseResolveBlock)resolve
|
||||
|
||||
@@ -272,6 +272,28 @@ class RNBreezSDKLiquid: RCTEventEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
@objc(prepareBuyBitcoin:resolve:reject:)
|
||||
func prepareBuyBitcoin(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
||||
do {
|
||||
let prepareBuyBitcoinRequest = try BreezSDKLiquidMapper.asPrepareBuyBitcoinRequest(prepareBuyBitcoinRequest: req)
|
||||
var res = try getBindingLiquidSdk().prepareBuyBitcoin(req: prepareBuyBitcoinRequest)
|
||||
resolve(BreezSDKLiquidMapper.dictionaryOf(prepareBuyBitcoinResponse: res))
|
||||
} catch let err {
|
||||
rejectErr(err: err, reject: reject)
|
||||
}
|
||||
}
|
||||
|
||||
@objc(buyBitcoin:resolve:reject:)
|
||||
func buyBitcoin(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
||||
do {
|
||||
let buyBitcoinRequest = try BreezSDKLiquidMapper.asBuyBitcoinRequest(buyBitcoinRequest: req)
|
||||
var res = try getBindingLiquidSdk().buyBitcoin(req: buyBitcoinRequest)
|
||||
resolve(res)
|
||||
} catch let err {
|
||||
rejectErr(err: err, reject: reject)
|
||||
}
|
||||
}
|
||||
|
||||
@objc(listPayments:resolve:reject:)
|
||||
func listPayments(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
||||
do {
|
||||
|
||||
@@ -36,6 +36,11 @@ export interface BitcoinAddressData {
|
||||
message?: string
|
||||
}
|
||||
|
||||
export interface BuyBitcoinRequest {
|
||||
prepareRes: PrepareBuyBitcoinResponse
|
||||
redirectUrl?: string
|
||||
}
|
||||
|
||||
export interface Config {
|
||||
liquidElectrumUrl: string
|
||||
bitcoinElectrumUrl: string
|
||||
@@ -211,6 +216,17 @@ export interface Payment {
|
||||
refundTxAmountSat?: number
|
||||
}
|
||||
|
||||
export interface PrepareBuyBitcoinRequest {
|
||||
provider: BuyBitcoinProvider
|
||||
amountSat: number
|
||||
}
|
||||
|
||||
export interface PrepareBuyBitcoinResponse {
|
||||
provider: BuyBitcoinProvider
|
||||
amountSat: number
|
||||
feesSat: number
|
||||
}
|
||||
|
||||
export interface PreparePayOnchainRequest {
|
||||
receiverAmountSat: number
|
||||
satPerVbyte?: number
|
||||
@@ -348,6 +364,10 @@ export type AesSuccessActionDataResult = {
|
||||
reason: string
|
||||
}
|
||||
|
||||
export enum BuyBitcoinProvider {
|
||||
MOONPAY = "moonpay"
|
||||
}
|
||||
|
||||
export enum InputTypeVariant {
|
||||
BITCOIN_ADDRESS = "bitcoinAddress",
|
||||
BOLT11 = "bolt11",
|
||||
@@ -608,6 +628,16 @@ export const receiveOnchain = async (req: PrepareReceiveOnchainResponse): Promis
|
||||
return response
|
||||
}
|
||||
|
||||
export const prepareBuyBitcoin = async (req: PrepareBuyBitcoinRequest): Promise<PrepareBuyBitcoinResponse> => {
|
||||
const response = await BreezSDKLiquid.prepareBuyBitcoin(req)
|
||||
return response
|
||||
}
|
||||
|
||||
export const buyBitcoin = async (req: BuyBitcoinRequest): Promise<string> => {
|
||||
const response = await BreezSDKLiquid.buyBitcoin(req)
|
||||
return response
|
||||
}
|
||||
|
||||
export const listPayments = async (req: ListPaymentsRequest): Promise<Payment[]> => {
|
||||
const response = await BreezSDKLiquid.listPayments(req)
|
||||
return response
|
||||
|
||||
Reference in New Issue
Block a user