Skip to content

Commit

Permalink
Cargo format, re-generate FRB and RN bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
ok300 committed Jun 13, 2024
1 parent d679f4b commit 3f42fab
Show file tree
Hide file tree
Showing 11 changed files with 4,277 additions and 82 deletions.
1,114 changes: 1,104 additions & 10 deletions lib/core/src/frb_generated.rs

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions lib/core/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -701,9 +701,9 @@ impl From<SwapTree> for InternalSwapTree {

/// LNURL-related wrappers
pub mod lnurl {
use crate::error::LiquidSdkError;
use sdk_common::prelude::*;
use serde::Serialize;
use crate::error::LiquidSdkError;

use crate::model::Payment;

Expand All @@ -720,7 +720,7 @@ pub mod lnurl {
pub payment: Payment,
pub success_action: Option<SuccessActionProcessed>,
}

impl From<LnUrlError> for LiquidSdkError {
fn from(value: LnUrlError) -> Self {
Self::LnUrlPay(format!("{value}"))
Expand Down
48 changes: 25 additions & 23 deletions lib/core/src/sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ use std::{fs, path::PathBuf, str::FromStr, sync::Arc, time::Duration};

use anyhow::Result;
use async_trait::async_trait;
use boltz_client::lightning_invoice::Bolt11InvoiceDescription;
use boltz_client::swaps::boltzv2;
use boltz_client::ToHex;
use boltz_client::{swaps::boltzv2::*, util::secrets::Preimage, Amount, Bolt11Invoice};
use futures_util::stream::select_all;
Expand Down Expand Up @@ -1082,40 +1080,44 @@ impl LiquidSdk {
req.amount_msat,
&req.comment,
&req.data,
self.config.network.into()
self.config.network.into(),
)
.await?
.await?
{
ValidatedCallbackResponse::EndpointError { data: e } => {
Ok(WrappedLnUrlPayResult::EndpointError { data: e })
}
ValidatedCallbackResponse::EndpointSuccess { data: cb } => {
let pay_req = self.prepare_send_payment(&PrepareSendRequest {
invoice: cb.pr.clone(),
}).await.map_err(|e| LiquidSdkError::Generic {
err: format!("{e}")
})?;

let payment = self.send_payment(&pay_req)
.await.map_err(|e| LiquidSdkError::LnUrlPay(format!("{e}")))?
.payment;
let pay_req = self
.prepare_send_payment(&PrepareSendRequest {
invoice: cb.pr.clone(),
})
.await
.map_err(|e| LiquidSdkError::Generic {
err: format!("{e}"),
})?;

let payment = self
.send_payment(&pay_req)
.await
.map_err(|e| LiquidSdkError::LnUrlPay(format!("{e}")))?
.payment;

let maybe_sa_processed: Option<SuccessActionProcessed> = match cb.success_action {
Some(sa) => {
let processed_sa = match sa {
// For AES, we decrypt the contents on the fly
SuccessAction::Aes(data) => {
let preimage_str = payment.preimage.clone().ok_or(
LiquidSdkError::Generic {
err: "Payment successful but no preimage found".to_string()
}
)?;
let preimage = sha256::Hash::from_str(&preimage_str).map_err(|_|
LiquidSdkError::Generic {
err: "Invalid preimage".to_string()
}
)?;
let preimage_str =
payment.preimage.clone().ok_or(LiquidSdkError::Generic {
err: "Payment successful but no preimage found".to_string(),
})?;
let preimage =
sha256::Hash::from_str(&preimage_str).map_err(|_| {
LiquidSdkError::Generic {
err: "Invalid preimage".to_string(),
}
})?;
let preimage_arr: [u8; 32] = preimage.into_32();
let result = match (data, &preimage_arr).try_into() {
Ok(data) => AesSuccessActionDataResult::Decrypted { data },
Expand Down
Loading

0 comments on commit 3f42fab

Please sign in to comment.