From 7443a8717a5baf9104dd8104800d5adf8951d489 Mon Sep 17 00:00:00 2001 From: ok300 <106775972+ok300@users.noreply.github.com> Date: Wed, 17 Apr 2024 20:57:51 +0000 Subject: [PATCH] Address uniffi feedback (#90) * Replace invoice_amount_sat with payer_amount_sat * Replace onchain_amount_sat with receiver_amount_sat --- cli/src/commands.rs | 12 ++++++------ lib/ls-sdk-bindings/src/ls_sdk.udl | 4 ++-- lib/ls-sdk-core/src/lib.rs | 4 ++-- lib/ls-sdk-core/src/model.rs | 10 +++++----- lib/ls-sdk-core/src/persist/migrations.rs | 2 +- lib/ls-sdk-core/src/persist/mod.rs | 10 +++++----- lib/ls-sdk-core/src/wallet.rs | 16 ++++++++-------- 7 files changed, 29 insertions(+), 29 deletions(-) diff --git a/cli/src/commands.rs b/cli/src/commands.rs index 23d1ece58..1d0dc6c86 100644 --- a/cli/src/commands.rs +++ b/cli/src/commands.rs @@ -28,10 +28,10 @@ pub(crate) enum Command { /// Receive lbtc and send btc through a swap ReceivePayment { #[arg(short, long)] - onchain_amount_sat: Option, + receiver_amount_sat: Option, #[arg(short, long)] - invoice_amount_sat: Option, + payer_amount_sat: Option, }, /// List incoming and outgoing payments ListPayments, @@ -75,12 +75,12 @@ pub(crate) fn handle_command( ) -> Result { Ok(match command { Command::ReceivePayment { - onchain_amount_sat, - invoice_amount_sat, + receiver_amount_sat, + payer_amount_sat, } => { let response = wallet.receive_payment(ReceivePaymentRequest { - invoice_amount_sat, - onchain_amount_sat, + payer_amount_sat, + receiver_amount_sat, })?; let invoice = response.invoice.clone(); diff --git a/lib/ls-sdk-bindings/src/ls_sdk.udl b/lib/ls-sdk-bindings/src/ls_sdk.udl index 940ddd154..2480e60c8 100644 --- a/lib/ls-sdk-bindings/src/ls_sdk.udl +++ b/lib/ls-sdk-bindings/src/ls_sdk.udl @@ -33,8 +33,8 @@ dictionary PreparePaymentResponse { }; dictionary ReceivePaymentRequest { - u64? invoice_amount_sat; - u64? onchain_amount_sat; + u64? payer_amount_sat; + u64? receiver_amount_sat; }; dictionary ReceivePaymentResponse { diff --git a/lib/ls-sdk-core/src/lib.rs b/lib/ls-sdk-core/src/lib.rs index 407a294e1..887f71b78 100644 --- a/lib/ls-sdk-core/src/lib.rs +++ b/lib/ls-sdk-core/src/lib.rs @@ -69,8 +69,8 @@ mod tests { let breez_wallet = Wallet::init(TEST_MNEMONIC, Some(data_dir_str), Network::LiquidTestnet)?; breez_wallet.receive_payment(ReceivePaymentRequest { - onchain_amount_sat: Some(1000), - invoice_amount_sat: None, + receiver_amount_sat: Some(1000), + payer_amount_sat: None, })?; assert!(!list_pending(&breez_wallet)?.is_empty()); diff --git a/lib/ls-sdk-core/src/model.rs b/lib/ls-sdk-core/src/model.rs index 87f072459..a9d6bbe52 100644 --- a/lib/ls-sdk-core/src/model.rs +++ b/lib/ls-sdk-core/src/model.rs @@ -59,8 +59,8 @@ impl WalletOptions { #[derive(Debug)] pub struct ReceivePaymentRequest { - pub invoice_amount_sat: Option, - pub onchain_amount_sat: Option, + pub payer_amount_sat: Option, + pub receiver_amount_sat: Option, } #[derive(Debug, Serialize)] @@ -146,7 +146,7 @@ pub(crate) enum OngoingSwap { redeem_script: String, blinding_key: String, invoice: String, - onchain_amount_sat: u64, + receiver_amount_sat: u64, }, } @@ -185,14 +185,14 @@ impl From for Payment { invoice: Some(invoice), }, OngoingSwap::Receive { - onchain_amount_sat, + receiver_amount_sat, invoice, .. } => Payment { id: None, timestamp: None, payment_type: PaymentType::PendingReceive, - amount_sat: onchain_amount_sat, + amount_sat: receiver_amount_sat, invoice: Some(invoice), }, } diff --git a/lib/ls-sdk-core/src/persist/migrations.rs b/lib/ls-sdk-core/src/persist/migrations.rs index a9a672454..4b3505141 100644 --- a/lib/ls-sdk-core/src/persist/migrations.rs +++ b/lib/ls-sdk-core/src/persist/migrations.rs @@ -6,7 +6,7 @@ pub(crate) fn current_migrations() -> Vec<&'static str> { redeem_script TEXT NOT NULL, blinding_key TEXT NOT NULL, invoice TEXT NOT NULL, - onchain_amount_sat INTEGER NOT NULL, + receiver_amount_sat INTEGER NOT NULL, created_at TEXT DEFAULT CURRENT_TIMESTAMP ) STRICT;", "CREATE TABLE IF NOT EXISTS ongoing_send_swaps ( diff --git a/lib/ls-sdk-core/src/persist/mod.rs b/lib/ls-sdk-core/src/persist/mod.rs index 72631db19..5278899ae 100644 --- a/lib/ls-sdk-core/src/persist/mod.rs +++ b/lib/ls-sdk-core/src/persist/mod.rs @@ -77,7 +77,7 @@ impl Persister { redeem_script, blinding_key, invoice, - onchain_amount_sat, + receiver_amount_sat, } => { let mut stmt = con.prepare( " @@ -87,7 +87,7 @@ impl Persister { redeem_script, blinding_key, invoice, - onchain_amount_sat + receiver_amount_sat ) VALUES (?, ?, ?, ?, ?, ?) ", @@ -99,7 +99,7 @@ impl Persister { &redeem_script, &blinding_key, &invoice, - &onchain_amount_sat, + &receiver_amount_sat, ))? } } @@ -167,7 +167,7 @@ impl Persister { redeem_script, blinding_key, invoice, - onchain_amount_sat, + receiver_amount_sat, created_at FROM ongoing_receive_swaps ORDER BY created_at @@ -182,7 +182,7 @@ impl Persister { redeem_script: row.get(2)?, blinding_key: row.get(3)?, invoice: row.get(4)?, - onchain_amount_sat: row.get(5)?, + receiver_amount_sat: row.get(5)?, }) })? .map(|i| i.unwrap()) diff --git a/lib/ls-sdk-core/src/wallet.rs b/lib/ls-sdk-core/src/wallet.rs index fcd2ef726..9027a1441 100644 --- a/lib/ls-sdk-core/src/wallet.rs +++ b/lib/ls-sdk-core/src/wallet.rs @@ -345,8 +345,8 @@ impl Wallet { .get_lbtc_pair() .ok_or(PaymentError::WalletError)?; - let (onchain_amount_sat, invoice_amount_sat) = - match (req.onchain_amount_sat, req.invoice_amount_sat) { + let (receiver_amount_sat, payer_amount_sat) = + match (req.receiver_amount_sat, req.payer_amount_sat) { (Some(onchain_amount_sat), None) => { let fees_lockup = lbtc_pair.fees.reverse_lockup(); let fees_claim = CLAIM_ABSOLUTE_FEES; // lbtc_pair.fees.reverse_claim_estimate(); @@ -380,11 +380,11 @@ impl Wallet { err: "Both invoice and onchain amounts were specified".into(), }), }?; - debug!("Creating reverse swap with: onchain_amount_sat {onchain_amount_sat} sat, invoice_amount_sat {invoice_amount_sat} sat"); + debug!("Creating reverse swap with: receiver_amount_sat {receiver_amount_sat} sat, payer_amount_sat {payer_amount_sat} sat"); lbtc_pair .limits - .within(invoice_amount_sat) + .within(payer_amount_sat) .map_err(|_| PaymentError::AmountOutOfRange)?; let mnemonic = self.signer.mnemonic().ok_or(PaymentError::WalletError)?; @@ -396,19 +396,19 @@ impl Wallet { let preimage_str = preimage.to_string().ok_or(PaymentError::InvalidPreimage)?; let preimage_hash = preimage.sha256.to_string(); - let swap_response = if req.onchain_amount_sat.is_some() { + let swap_response = if req.receiver_amount_sat.is_some() { client.create_swap(CreateSwapRequest::new_lbtc_reverse_onchain_amt( lbtc_pair.hash, preimage_hash.clone(), lsk.keypair.public_key().to_string(), - onchain_amount_sat, + receiver_amount_sat, ))? } else { client.create_swap(CreateSwapRequest::new_lbtc_reverse_invoice_amt( lbtc_pair.hash, preimage_hash.clone(), lsk.keypair.public_key().to_string(), - invoice_amount_sat, + payer_amount_sat, ))? }; @@ -430,7 +430,7 @@ impl Wallet { blinding_key: blinding_str, redeem_script, invoice: invoice.to_string(), - onchain_amount_sat, + receiver_amount_sat, }])) .map_err(|_| PaymentError::PersistError)?;