Skip to content
Merged
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
3 changes: 3 additions & 0 deletions openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2346,6 +2346,9 @@ components:
payee_pubkey:
type: string
example: 03b79a4bc1ec365524b4fab9a39eb133753646babb5a1da5c4bc94c53110b7795d
preimage:
type: string
example: 89d28bd306aa9bb906fd0ac31092d04c37c919a171b343083167e2a3cdc60578
Peer:
type: object
required:
Expand Down
5 changes: 5 additions & 0 deletions src/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,7 @@ pub(crate) struct Payment {
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 @@ -1774,6 +1775,7 @@ pub(crate) async fn get_payment(
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 @@ -1803,6 +1805,7 @@ pub(crate) async fn get_payment(
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 @@ -2316,6 +2319,7 @@ pub(crate) async fn list_payments(
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 @@ -2342,6 +2346,7 @@ pub(crate) async fn list_payments(
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
11 changes: 10 additions & 1 deletion src/test/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use amplify::s;
use biscuit_auth::{builder::date, macros::*, KeyPair};
use bitcoin::hashes::sha256::Hash as Sha256;
use bitcoin::hashes::Hash;
use chrono::{DateTime, Local, Utc};
use electrum_client::ElectrumApi;
use lazy_static::lazy_static;
Expand Down Expand Up @@ -41,7 +43,7 @@ use crate::routes::{
SendPaymentResponse, SendRgbRequest, SendRgbResponse, Swap, SwapStatus, TakerRequest,
Transaction, Transfer, UnlockRequest, Unspent, WitnessData,
};
use crate::utils::{hex_str_to_vec, ELECTRUM_URL_REGTEST, PROXY_ENDPOINT_LOCAL};
use crate::utils::{hex_str, hex_str_to_vec, ELECTRUM_URL_REGTEST, PROXY_ENDPOINT_LOCAL};

use super::*;

Expand Down Expand Up @@ -83,6 +85,13 @@ fn _bitcoin_cli() -> [String; 7] {
]
}

fn check_preimage_matches_hash(payment: &Payment, expected_payment_hash: &str) {
let payment_preimage = payment.preimage.as_ref().unwrap();
let payment_preimage_hash =
hex_str(&Sha256::hash(&hex_str_to_vec(payment_preimage).unwrap()).to_byte_array());
assert_eq!(payment_preimage_hash, expected_payment_hash);
}

async fn _check_response_is_ok(res: Response) -> Response {
if res.status() != reqwest::StatusCode::OK {
panic!("reqwest response is not OK: {:?}", res.text().await);
Expand Down
20 changes: 20 additions & 0 deletions src/test/payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,24 @@ 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);
check_preimage_matches_hash(&payment, &decoded.payment_hash);
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);
check_preimage_matches_hash(&payment, &decoded.payment_hash);
let payment = list_payments(node1_addr)
.await
.into_iter()
.find(|payment| payment.payment_hash == decoded.payment_hash)
.unwrap();
check_preimage_matches_hash(&payment, &decoded.payment_hash);
let payment = list_payments(node2_addr)
.await
.into_iter()
.find(|payment| payment.payment_hash == decoded.payment_hash)
.unwrap();
check_preimage_matches_hash(&payment, &decoded.payment_hash);

let asset_amount = Some(50);
let LNInvoiceResponse { invoice } =
Expand All @@ -86,10 +100,12 @@ 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);
check_preimage_matches_hash(&payment, &decoded.payment_hash);
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);
check_preimage_matches_hash(&payment, &decoded.payment_hash);

let LNInvoiceResponse { invoice } =
ln_invoice(node2_addr, None, Some(&asset_id), asset_amount, 900).await;
Expand All @@ -100,10 +116,12 @@ 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);
check_preimage_matches_hash(&payment, &decoded.payment_hash);
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);
check_preimage_matches_hash(&payment, &decoded.payment_hash);

let LNInvoiceResponse { invoice } =
ln_invoice(node1_addr, None, Some(&asset_id), asset_amount, 900).await;
Expand All @@ -114,10 +132,12 @@ 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);
check_preimage_matches_hash(&payment, &decoded.payment_hash);
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);
check_preimage_matches_hash(&payment, &decoded.payment_hash);

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