Skip to content

Commit

Permalink
Use register_topup (#679)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgranhao authored Oct 5, 2023
1 parent 249eb23 commit a276511
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 21 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ name = "uniffi_lipalightninglib"
nigiri = []

[dependencies]
chameleon = { git = "https://github.com/getlipa/wild", tag = "v1.11.0" }
crow = { git = "https://github.com/getlipa/wild", tag = "v1.11.0" }
honey-badger = { git = "https://github.com/getlipa/wild", tag = "v1.11.0" }
chameleon = { git = "https://github.com/getlipa/wild", tag = "v1.12.0" }
crow = { git = "https://github.com/getlipa/wild", tag = "v1.12.0" }
honey-badger = { git = "https://github.com/getlipa/wild", tag = "v1.12.0" }
graphql = { git = "https://github.com/getlipa/wild", tag = "v1.12.0" }
perro = { git = "https://github.com/getlipa/perro", tag = "v1.1.0" }
graphql = { git = "https://github.com/getlipa/wild", tag = "v1.11.0" }

breez-sdk-core = { git = "https://github.com/breez/breez-sdk", tag = "0.2.5" }

Expand Down
2 changes: 2 additions & 0 deletions src/fiat_topup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub enum TopupCurrency {

#[derive(Debug)]
pub struct FiatTopupInfo {
pub order_id: String,
pub debitor_iban: String,
pub creditor_reference: String,
pub creditor_iban: String,
Expand All @@ -38,6 +39,7 @@ pub struct FiatTopupInfo {
impl FiatTopupInfo {
fn from_pocket_create_order_response(create_order_response: CreateOrderResponse) -> Self {
FiatTopupInfo {
order_id: create_order_response.id,
debitor_iban: create_order_response.payment_method.debitor_iban,
creditor_reference: create_order_response.payment_method.creditor_reference,
creditor_iban: create_order_response.payment_method.creditor_iban,
Expand Down
24 changes: 11 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -736,25 +736,23 @@ impl LightningNode {
user_currency: TopupCurrency,
) -> Result<FiatTopupInfo> {
trace!("register_fiat_topup() - called with - email: {email:?} - user_iban: {user_iban} - user_currency: {user_currency:?}");
if let Err(e) = user_iban.parse::<Iban>() {
return Err(invalid_input(format!("Invalid user_iban: {}", e)));
}
user_iban
.parse::<Iban>()
.map_to_invalid_input("Invalid user_iban")?;

if let Some(email) = email {
if let Err(e) = EmailAddress::from_str(&email) {
return Err(invalid_input(format!("Invalid email: {}", e)));
}
self.offer_manager
.register_email(email)
.map_runtime_error_to(RuntimeErrorCode::AuthServiceUnavailable)?;
if let Some(email) = email.as_ref() {
EmailAddress::from_str(email).map_to_invalid_input("Invalid email")?;
}

let topup_info = self
.fiat_topup_client
.register_pocket_fiat_topup(&user_iban, user_currency)?;

self.offer_manager
.register_node(self.get_node_info()?.node_pubkey)
.register_topup(topup_info.order_id.clone(), email)
.map_runtime_error_to(RuntimeErrorCode::OfferServiceUnavailable)?;

self.fiat_topup_client
.register_pocket_fiat_topup(&user_iban, user_currency)
Ok(topup_info)
}

pub fn query_uncompleted_offers(&self) -> Result<Vec<OfferInfo>> {
Expand Down
1 change: 1 addition & 0 deletions src/lipalightninglib.udl
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ enum TopupCurrency {

// Information about a fiat top-up registration
dictionary FiatTopupInfo {
string order_id;
string debitor_iban; // The user should transfer fiat from this IBAN
string creditor_reference; // This reference should be included in the fiat transfer reference
string creditor_iban; // The user should transfer fiat to this IBAN
Expand Down

0 comments on commit a276511

Please sign in to comment.