Skip to content

Commit

Permalink
Merge pull request #13 from uma-universal-money-address/fix/paymentin…
Browse files Browse the repository at this point in the history
…fodecimals

Some tweaks to the payment_info in payreq response.
  • Loading branch information
jklein24 authored Dec 22, 2023
2 parents 9acacf8 + 49180ef commit 260e004
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/currency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ pub struct Currency {
// means. For example, if the currency is "BTC" and the multiplier is 1000, really we're exchanging in SATs, so
// `decimals` would be 8.
// For details on edge cases and examples, see https://github.com/uma-universal-money-address/protocol/blob/main/umad-04-lnurlp-response.md.
pub decimals: i64,
pub decimals: i32,
}
13 changes: 10 additions & 3 deletions src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ impl PayRequest {
}

/// PayReqResponse is the response sent by the receiver to the sender to provide an invoice.
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct PayReqResponse {
/// encoded_invoice is the BOLT11 invoice that the sender will pay.
#[serde(rename = "pr")]
Expand Down Expand Up @@ -240,17 +240,24 @@ pub struct PayReqResponseCompliance {
pub utxo_callback: String,
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct PayReqResponsePaymentInfo {
/// CurrencyCode is the ISO 3-digit currency code that the receiver will receive for this
/// payment.
#[serde(rename = "currencyCode")]
pub currency_code: String,

/// Number of digits after the decimal point for the receiving currency. For example, in USD, by
/// convention, there are 2 digits for cents - $5.95. In this case, `decimals` would be 2. This should align with
/// the currency's `decimals` field in the LNURLP response. It is included here for convenience. See
/// [UMAD-04](https://github.com/uma-universal-money-address/protocol/blob/main/umad-04-lnurlp-response.md) for
/// details, edge cases, and examples.
pub decimals: i32,

/// Multiplier is the conversion rate. It is the number of millisatoshis that the receiver will
/// receive for 1 unit of the specified currency.
#[serde(rename = "multiplier")]
pub multiplier: i64,
pub multiplier: f64,

/// ExchangeFeesMillisatoshi is the fees charged (in millisats) by the receiving VASP for this
/// transaction. This is separate from the Multiplier.
Expand Down
7 changes: 5 additions & 2 deletions src/uma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,8 @@ pub fn get_pay_req_response<T>(
invoice_creator: &T,
metadata: &str,
currency_code: &str,
conversion_rate: i64,
currency_decimals: i32,
conversion_rate: f64,
receiver_fees_millisats: i64,
receiver_channel_utxos: &[String],
receiver_node_pub_key: Option<&str>,
Expand All @@ -476,7 +477,8 @@ pub fn get_pay_req_response<T>(
where
T: UmaInvoiceCreator,
{
let msats_amount = query.amount * conversion_rate + receiver_fees_millisats;
let msats_amount =
(query.amount as f64 * conversion_rate).round() as i64 + receiver_fees_millisats;
let encoded_payer_data =
serde_json::to_string(&query.payer_data).map_err(Error::InvalidData)?;
let encoded_invoice = invoice_creator
Expand All @@ -496,6 +498,7 @@ where
},
payment_info: PayReqResponsePaymentInfo {
currency_code: currency_code.to_string(),
decimals: currency_decimals,
multiplier: conversion_rate,
exchange_fees_millisatoshi: receiver_fees_millisats,
},
Expand Down
3 changes: 2 additions & 1 deletion src/uma_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ mod tests {
&client,
&metadata,
"USD",
34150,
2,
23150.0,
100_000,
&["abcdef12345".to_owned()],
None,
Expand Down
2 changes: 1 addition & 1 deletion src/version.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::uma;

const MAJOR_VERSION: i32 = 0;
const MINOR_VERSION: i32 = 2;
const MINOR_VERSION: i32 = 3;

pub fn uma_protocol_version() -> String {
format!("{}.{}", MAJOR_VERSION, MINOR_VERSION)
Expand Down

0 comments on commit 260e004

Please sign in to comment.