Skip to content

Commit

Permalink
Address uniffi feedback (#90)
Browse files Browse the repository at this point in the history
* Replace invoice_amount_sat with payer_amount_sat

* Replace onchain_amount_sat with receiver_amount_sat
  • Loading branch information
ok300 authored Apr 17, 2024
1 parent fa0cde1 commit 7443a87
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 29 deletions.
12 changes: 6 additions & 6 deletions cli/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ pub(crate) enum Command {
/// Receive lbtc and send btc through a swap
ReceivePayment {
#[arg(short, long)]
onchain_amount_sat: Option<u64>,
receiver_amount_sat: Option<u64>,

#[arg(short, long)]
invoice_amount_sat: Option<u64>,
payer_amount_sat: Option<u64>,
},
/// List incoming and outgoing payments
ListPayments,
Expand Down Expand Up @@ -75,12 +75,12 @@ pub(crate) fn handle_command(
) -> Result<String> {
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();
Expand Down
4 changes: 2 additions & 2 deletions lib/ls-sdk-bindings/src/ls_sdk.udl
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions lib/ls-sdk-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down
10 changes: 5 additions & 5 deletions lib/ls-sdk-core/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ impl WalletOptions {

#[derive(Debug)]
pub struct ReceivePaymentRequest {
pub invoice_amount_sat: Option<u64>,
pub onchain_amount_sat: Option<u64>,
pub payer_amount_sat: Option<u64>,
pub receiver_amount_sat: Option<u64>,
}

#[derive(Debug, Serialize)]
Expand Down Expand Up @@ -146,7 +146,7 @@ pub(crate) enum OngoingSwap {
redeem_script: String,
blinding_key: String,
invoice: String,
onchain_amount_sat: u64,
receiver_amount_sat: u64,
},
}

Expand Down Expand Up @@ -185,14 +185,14 @@ impl From<OngoingSwap> 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),
},
}
Expand Down
2 changes: 1 addition & 1 deletion lib/ls-sdk-core/src/persist/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
10 changes: 5 additions & 5 deletions lib/ls-sdk-core/src/persist/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl Persister {
redeem_script,
blinding_key,
invoice,
onchain_amount_sat,
receiver_amount_sat,
} => {
let mut stmt = con.prepare(
"
Expand All @@ -87,7 +87,7 @@ impl Persister {
redeem_script,
blinding_key,
invoice,
onchain_amount_sat
receiver_amount_sat
)
VALUES (?, ?, ?, ?, ?, ?)
",
Expand All @@ -99,7 +99,7 @@ impl Persister {
&redeem_script,
&blinding_key,
&invoice,
&onchain_amount_sat,
&receiver_amount_sat,
))?
}
}
Expand Down Expand Up @@ -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
Expand All @@ -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())
Expand Down
16 changes: 8 additions & 8 deletions lib/ls-sdk-core/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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)?;
Expand All @@ -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,
))?
};

Expand All @@ -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)?;

Expand Down

0 comments on commit 7443a87

Please sign in to comment.