Skip to content

Commit

Permalink
greenlight: remove unused payment mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
JssDWt committed Oct 5, 2024
1 parent 980471b commit 3a124b7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 70 deletions.
50 changes: 0 additions & 50 deletions libs/sdk-core/src/greenlight/node_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1891,56 +1891,6 @@ impl From<PayStatus> for PaymentStatus {
}
}

/// Construct a lightning transaction from an invoice
impl TryFrom<gl_client::signer::model::greenlight::Payment> for Payment {
type Error = NodeError;

fn try_from(
payment: gl_client::signer::model::greenlight::Payment,
) -> std::result::Result<Self, Self::Error> {
let mut description = None;
if !payment.bolt11.is_empty() {
description = parse_invoice(&payment.bolt11)?.description;
}

let payment_amount = amount_to_msat(&payment.amount.clone().unwrap_or_default());
let payment_amount_sent = amount_to_msat(&payment.amount_sent.clone().unwrap_or_default());
let status = payment.status().into();

Ok(Payment {
id: hex::encode(payment.payment_hash.clone()),
payment_type: PaymentType::Sent,
payment_time: payment.created_at as i64,
amount_msat: payment_amount,
fee_msat: payment_amount_sent - payment_amount,
status,
error: None,
description,
details: PaymentDetails::Ln {
data: LnPaymentDetails {
payment_hash: hex::encode(payment.payment_hash),
label: "".to_string(),
destination_pubkey: hex::encode(payment.destination),
payment_preimage: hex::encode(payment.payment_preimage),
keysend: payment.bolt11.is_empty(),
bolt11: payment.bolt11,
lnurl_success_action: None,
lnurl_pay_domain: None,
lnurl_pay_comment: None,
lnurl_metadata: None,
ln_address: None,
lnurl_withdraw_endpoint: None,
swap_info: None,
reverse_swap_info: None,
pending_expiration_block: None,
open_channel_bolt11: None,
},
},
metadata: None,
})
}
}

/// Construct a lightning transaction from an invoice
impl TryFrom<cln::ListinvoicesInvoices> for Payment {
type Error = NodeError;
Expand Down
36 changes: 16 additions & 20 deletions libs/sdk-core/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ use std::{mem, vec};

use anyhow::{Error, Result};
use chrono::{SecondsFormat, Utc};
use gl_client::signer::model::greenlight::amount::Unit;
use gl_client::signer::model::greenlight::Amount;
use gl_client::pb::cln::Amount;
use gl_client::signer::model::greenlight::PayStatus;
use rand::distributions::uniform::{SampleRange, SampleUniform};
use rand::distributions::{Alphanumeric, DistString, Standard};
Expand Down Expand Up @@ -322,7 +321,7 @@ pub struct MockNodeAPI {
/// Each call to [MockNodeAPI::add_dummy_payment_for] will add the new payment here such that
/// [NodeAPI::pull_changed], which is called in [BreezServices::sync], always retrieves the newly
/// added test payments
cloud_payments: Mutex<Vec<gl_client::signer::model::greenlight::Payment>>,
cloud_payments: Mutex<Vec<gl_client::pb::cln::ListpaysPays>>,
node_state: NodeState,
on_send_custom_message: Box<dyn Fn(CustomMessage) -> NodeResult<()> + Sync + Send>,
on_stream_custom_messages: Mutex<mpsc::Receiver<CustomMessage>>,
Expand Down Expand Up @@ -568,27 +567,24 @@ impl MockNodeAPI {
preimage: Option<sha256::Hash>,
status: Option<PayStatus>,
) -> NodeResult<Payment> {
let gl_payment = gl_client::signer::model::greenlight::Payment {
let gl_payment = gl_client::pb::cln::ListpaysPays {
payment_hash: hex::decode(inv.payment_hash().to_hex())?,
bolt11: inv.to_string(),
amount: inv
.amount_milli_satoshis()
.map(Unit::Millisatoshi)
.map(Some)
.map(|amt| Amount { unit: amt }),
amount_sent: inv
.amount_milli_satoshis()
.map(Unit::Millisatoshi)
.map(Some)
.map(|amt| Amount { unit: amt }),
payment_preimage: match preimage {
Some(preimage) => hex::decode(preimage.to_hex())?,
None => rand_vec_u8(32),
bolt11: Some(inv.to_string()),
amount_msat: inv.amount_milli_satoshis().map(|msat| Amount { msat }),
amount_sent_msat: inv.amount_milli_satoshis().map(|msat| Amount { msat }),
preimage: match preimage {
Some(preimage) => Some(hex::decode(preimage.to_hex())?),
None => Some(rand_vec_u8(32)),
},
status: status.unwrap_or(PayStatus::Complete).into(),
created_at: random(),
destination: rand_vec_u8(32),
destination: Some(rand_vec_u8(32)),
completed_at: random(),
label: None,
description: None,
bolt12: None,
erroronion: None,
number_of_parts: None,
};

self.save_payment_for_future_sync_updates(gl_payment.clone())
Expand All @@ -598,7 +594,7 @@ impl MockNodeAPI {
/// Include payment in the result of [MockNodeAPI::pull_changed].
async fn save_payment_for_future_sync_updates(
&self,
gl_payment: gl_client::signer::model::greenlight::Payment,
gl_payment: gl_client::pb::cln::ListpaysPays,
) -> NodeResult<Payment> {
let mut cloud_payments = self.cloud_payments.lock().await;

Expand Down

0 comments on commit 3a124b7

Please sign in to comment.