Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1892,6 +1892,10 @@ components:
payee_pubkey:
type: string
example: 03b79a4bc1ec365524b4fab9a39eb133753646babb5a1da5c4bc94c53110b7795d
preimage:
type: string
description: Optional custom payment preimage (hex string, 32 bytes)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
description: Optional custom payment preimage (hex string, 32 bytes)

example: "1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
example: "1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef"
example: 89d28bd306aa9bb906fd0ac31092d04c37c919a171b343083167e2a3cdc60578

Peer:
type: object
properties:
Expand Down
5 changes: 5 additions & 0 deletions src/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,7 @@
pub(crate) created_at: u64,
pub(crate) updated_at: u64,
pub(crate) payee_pubkey: String,
pub(crate) preimage: Option<String>,
}

#[derive(Clone, Deserialize, Serialize)]
Expand Down Expand Up @@ -1137,7 +1138,7 @@
}

async fn check_locked(
&self,

Check warning on line 1141 in src/routes.rs

View workflow job for this annotation

GitHub Actions / build (nightly, macos)

lifetime flowing from input to output with different syntax can be confusing

Check warning on line 1141 in src/routes.rs

View workflow job for this annotation

GitHub Actions / build (nightly, windows)

lifetime flowing from input to output with different syntax can be confusing

Check warning on line 1141 in src/routes.rs

View workflow job for this annotation

GitHub Actions / build (nightly, linux)

lifetime flowing from input to output with different syntax can be confusing
) -> Result<TokioMutexGuard<Option<Arc<UnlockedAppState>>>, APIError> {
let unlocked_app_state = self.get_unlocked_app_state().await;
if unlocked_app_state.is_some() {
Expand All @@ -1149,7 +1150,7 @@
}

async fn check_unlocked(
&self,

Check warning on line 1153 in src/routes.rs

View workflow job for this annotation

GitHub Actions / build (nightly, macos)

lifetime flowing from input to output with different syntax can be confusing

Check warning on line 1153 in src/routes.rs

View workflow job for this annotation

GitHub Actions / build (nightly, windows)

lifetime flowing from input to output with different syntax can be confusing

Check warning on line 1153 in src/routes.rs

View workflow job for this annotation

GitHub Actions / build (nightly, linux)

lifetime flowing from input to output with different syntax can be confusing
) -> Result<TokioMutexGuard<Option<Arc<UnlockedAppState>>>, APIError> {
let unlocked_app_state = self.get_unlocked_app_state().await;
if unlocked_app_state.is_none() {
Expand Down Expand Up @@ -2027,6 +2028,7 @@
created_at: payment_info.created_at,
updated_at: payment_info.updated_at,
payee_pubkey: payment_info.payee_pubkey.to_string(),
preimage: payment_info.preimage.map(|p| hex_str(&p.0)),
});
}

Expand All @@ -2053,6 +2055,7 @@
created_at: payment_info.created_at,
updated_at: payment_info.updated_at,
payee_pubkey: payment_info.payee_pubkey.to_string(),
preimage: payment_info.preimage.map(|p| hex_str(&p.0)),
});
}

Expand Down Expand Up @@ -2097,6 +2100,7 @@
created_at: payment_info.created_at,
updated_at: payment_info.updated_at,
payee_pubkey: payment_info.payee_pubkey.to_string(),
preimage: payment_info.preimage.map(|p| hex_str(&p.0)),
},
}));
}
Expand Down Expand Up @@ -2126,6 +2130,7 @@
created_at: payment_info.created_at,
updated_at: payment_info.updated_at,
payee_pubkey: payment_info.payee_pubkey.to_string(),
preimage: payment_info.preimage.map(|p| hex_str(&p.0)),
},
}));
}
Expand Down
32 changes: 32 additions & 0 deletions src/test/payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,18 @@ async fn success() {
assert_eq!(payment.asset_id, Some(asset_id.clone()));
assert_eq!(payment.asset_amount, asset_amount);
assert_eq!(payment.status, HTLCStatus::Succeeded);
assert!(
payment.preimage.is_some(),
"Payment preimage should be present for successful payment"
);
Comment on lines +66 to +69
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assert!(
payment.preimage.is_some(),
"Payment preimage should be present for successful payment"
);
let payment_preimage_hash = hex_str(
&Sha256::hash(&hex_str_to_vec(&payment.preimage.unwrap()).unwrap()).to_byte_array(),
);
assert_eq!(payment_preimage_hash, decoded.payment_hash);

please do this in this entire test, instead of checking that it's some.

you will also need to modify the top of the file like this:

+use bitcoin::hashes::sha256::Hash as Sha256;
+use bitcoin::hashes::Hash;
+
 use crate::routes::{BitcoinNetwork, TransactionType, TransferKind, TransferStatus};
+use crate::utils::hex_str;

let payment = get_payment(node2_addr, &decoded.payment_hash).await;
assert_eq!(payment.asset_id, Some(asset_id.clone()));
assert_eq!(payment.asset_amount, asset_amount);
assert_eq!(payment.status, HTLCStatus::Succeeded);
assert!(
payment.preimage.is_some(),
"Payment preimage should be present for successful payment"
);

let asset_amount = Some(50);
let LNInvoiceResponse { invoice } =
Expand All @@ -85,10 +93,18 @@ async fn success() {
assert_eq!(payment.asset_id, Some(asset_id.clone()));
assert_eq!(payment.asset_amount, asset_amount);
assert_eq!(payment.status, HTLCStatus::Succeeded);
assert!(
payment.preimage.is_some(),
"Payment preimage should be present for successful payment"
);
let payment = get_payment(node2_addr, &decoded.payment_hash).await;
assert_eq!(payment.asset_id, Some(asset_id.clone()));
assert_eq!(payment.asset_amount, asset_amount);
assert_eq!(payment.status, HTLCStatus::Succeeded);
assert!(
payment.preimage.is_some(),
"Payment preimage should be present for successful payment"
);

let LNInvoiceResponse { invoice } =
ln_invoice(node2_addr, None, Some(&asset_id), asset_amount, 900).await;
Expand All @@ -99,10 +115,18 @@ async fn success() {
assert_eq!(payment.asset_id, Some(asset_id.clone()));
assert_eq!(payment.asset_amount, asset_amount);
assert_eq!(payment.status, HTLCStatus::Succeeded);
assert!(
payment.preimage.is_some(),
"Payment preimage should be present for successful payment"
);
let payment = get_payment(node2_addr, &decoded.payment_hash).await;
assert_eq!(payment.asset_id, Some(asset_id.clone()));
assert_eq!(payment.asset_amount, asset_amount);
assert_eq!(payment.status, HTLCStatus::Succeeded);
assert!(
payment.preimage.is_some(),
"Payment preimage should be present for successful payment"
);

let LNInvoiceResponse { invoice } =
ln_invoice(node1_addr, None, Some(&asset_id), asset_amount, 900).await;
Expand All @@ -113,10 +137,18 @@ async fn success() {
assert_eq!(payment.asset_id, Some(asset_id.clone()));
assert_eq!(payment.asset_amount, asset_amount);
assert_eq!(payment.status, HTLCStatus::Succeeded);
assert!(
payment.preimage.is_some(),
"Payment preimage should be present for successful payment"
);
let payment = get_payment(node2_addr, &decoded.payment_hash).await;
assert_eq!(payment.asset_id, Some(asset_id.clone()));
assert_eq!(payment.asset_amount, asset_amount);
assert_eq!(payment.status, HTLCStatus::Succeeded);
assert!(
payment.preimage.is_some(),
"Payment preimage should be present for successful payment"
);

let channels_1 = list_channels(node1_addr).await;
let channels_2 = list_channels(node2_addr).await;
Expand Down
Loading