Skip to content

Commit

Permalink
feat: readding invoice changes
Browse files Browse the repository at this point in the history
  • Loading branch information
vacwmX committed Dec 9, 2023
1 parent b6a4c0e commit 314feca
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 25 deletions.
2 changes: 1 addition & 1 deletion libs/sdk-bindings/src/breez_sdk.udl
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ enum SendPaymentError {
"RouteNotFound",
"RouteTooExpensive",
"ServiceConnectivity",
"OfferAmountChanged",
"OfferChanged",
};

enum EnvironmentType {
Expand Down
4 changes: 2 additions & 2 deletions libs/sdk-core/src/breez_services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1391,8 +1391,8 @@ impl BreezServices {
})
.await?;

if let Some(new_amount) = fetch_invoice_response.new_amount_msat {
return Err(SendPaymentError::OfferAmountChanged { new_amount });
if let Some(changes) = fetch_invoice_response.changes {
return Err(SendPaymentError::OfferChanged { changes });
}

Ok(self.send_payment(SendPaymentRequest {
Expand Down
6 changes: 3 additions & 3 deletions libs/sdk-core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use thiserror::Error;

use crate::{
invoice::InvoiceError, lnurl::error::LnUrlError, node_api::NodeError,
persist::error::PersistError, swap_in::error::SwapError, swap_out::error::ReverseSwapError,
persist::error::PersistError, swap_in::error::SwapError, swap_out::error::ReverseSwapError, FetchInvoiceChanges,
};

pub type SdkResult<T, E = SdkError> = Result<T, E>;
Expand Down Expand Up @@ -589,8 +589,8 @@ pub enum SendPaymentError {
#[error("Service connectivity: {err}")]
ServiceConnectivity { err: String },

#[error("Amount has changed: {new_amount}")]
OfferAmountChanged { new_amount: u64 },
#[error("Offer has changed: {changes:?}")]
OfferChanged { changes: FetchInvoiceChanges },
}

impl From<anyhow::Error> for SendPaymentError {
Expand Down
9 changes: 5 additions & 4 deletions libs/sdk-core/src/greenlight/node_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1007,10 +1007,11 @@ impl NodeAPI for Greenlight {

Ok(FetchInvoiceResponse {
bolt12: response.invoice,
new_amount_msat: match response.changes {
Some(changes) => changes.amount_msat.map(|amount| amount.msat),
None => None
},
changes: response.changes.map(|changes| FetchInvoiceChanges {
amount: changes.amount_msat.map(|amount| amount.msat),
vendor: changes.vendor,
description: changes.description
})
})
}

Expand Down
9 changes: 8 additions & 1 deletion libs/sdk-core/src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -824,10 +824,17 @@ pub struct FetchInvoiceRequest {
pub(crate) payer_note: Option<String>,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct FetchInvoiceChanges {
pub(crate) vendor: Option<String>,
pub(crate) description: Option<String>,
pub(crate) amount: Option<u64>,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct FetchInvoiceResponse {
pub(crate) bolt12: String,
pub(crate) new_amount_msat: Option<u64>,
pub(crate) changes: Option<FetchInvoiceChanges>,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,12 +457,10 @@ fun asCreateOfferRequest(createOfferRequest: ReadableMap): CreateOfferRequest? {
} else {
null
}
val issuer = if (hasNonNullKey(createOfferRequest, "issuer")) createOfferRequest.getString("issuer") else null
return CreateOfferRequest(
amountMsat,
description,
absoluteExpiry,
issuer,
)
}

Expand All @@ -471,7 +469,6 @@ fun readableMapOf(createOfferRequest: CreateOfferRequest): ReadableMap {
"amountMsat" to createOfferRequest.amountMsat,
"description" to createOfferRequest.description,
"absoluteExpiry" to createOfferRequest.absoluteExpiry,
"issuer" to createOfferRequest.issuer,
)
}

Expand Down
11 changes: 1 addition & 10 deletions libs/sdk-react-native/ios/BreezSDKMapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -497,19 +497,11 @@ enum BreezSDKMapper {
}
absoluteExpiry = absoluteExpiryTmp
}
var issuer: String?
if hasNonNilKey(data: createOfferRequest, key: "issuer") {
guard let issuerTmp = createOfferRequest["issuer"] as? String else {
throw SdkError.Generic(message: errUnexpectedValue(fieldName: "issuer"))
}
issuer = issuerTmp
}

return CreateOfferRequest(
amountMsat: amountMsat,
description: description,
absoluteExpiry: absoluteExpiry,
issuer: issuer
absoluteExpiry: absoluteExpiry
)
}

Expand All @@ -518,7 +510,6 @@ enum BreezSDKMapper {
"amountMsat": createOfferRequest.amountMsat == nil ? nil : createOfferRequest.amountMsat,
"description": createOfferRequest.description,
"absoluteExpiry": createOfferRequest.absoluteExpiry == nil ? nil : createOfferRequest.absoluteExpiry,
"issuer": createOfferRequest.issuer == nil ? nil : createOfferRequest.issuer,
]
}

Expand Down
1 change: 0 additions & 1 deletion libs/sdk-react-native/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ export type CreateOfferRequest = {
amountMsat?: number
description: string
absoluteExpiry?: number
issuer?: string
}

export type CurrencyInfo = {
Expand Down

0 comments on commit 314feca

Please sign in to comment.