Skip to content
This repository was archived by the owner on Feb 3, 2025. It is now read-only.

Commit 60ecded

Browse files
Rename LnNode to InvoiceHandler and move to lib
1 parent b531075 commit 60ecded

3 files changed

Lines changed: 28 additions & 22 deletions

File tree

mutiny-core/src/lib.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,25 @@ use std::sync::Arc;
8787
use std::{collections::HashMap, sync::atomic::AtomicBool};
8888
use uuid::Uuid;
8989

90+
#[cfg(test)]
91+
use mockall::{automock, predicate::*};
92+
9093
const DEFAULT_PAYMENT_TIMEOUT: u64 = 30;
9194

95+
#[cfg_attr(test, automock)]
96+
pub(crate) trait InvoiceHandler {
97+
fn logger(&self) -> &MutinyLogger;
98+
fn skip_hodl_invoices(&self) -> bool;
99+
fn get_outbound_payment_status(&self, payment_hash: &[u8; 32]) -> Option<HTLCStatus>;
100+
async fn pay_invoice_with_timeout(
101+
&self,
102+
invoice: &Bolt11Invoice,
103+
amt_sats: Option<u64>,
104+
timeout_secs: Option<u64>,
105+
labels: Vec<String>,
106+
) -> Result<MutinyInvoice, MutinyError>;
107+
}
108+
92109
#[derive(Copy, Clone)]
93110
pub struct MutinyBalance {
94111
pub confirmed: u64,

mutiny-core/src/node.rs

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use crate::ldkstorage::{persist_monitor, ChannelOpenParams};
21
use crate::lsp::{InvoiceRequest, LspConfig};
32
use crate::messagehandler::MutinyMessageHandler;
43
use crate::nodemanager::ChannelClosure;
@@ -23,6 +22,10 @@ use crate::{
2322
use crate::{fees::P2WSH_OUTPUT_SIZE, peermanager::connect_peer_if_necessary};
2423
use crate::{keymanager::PhantomKeysManager, scorer::HubPreferentialScorer};
2524
use crate::{labels::LabelStorage, DEFAULT_PAYMENT_TIMEOUT};
25+
use crate::{
26+
ldkstorage::{persist_monitor, ChannelOpenParams},
27+
InvoiceHandler,
28+
};
2629
use anyhow::{anyhow, Context};
2730
use bdk::FeeRate;
2831
use bitcoin::hashes::{hex::ToHex, sha256::Hash as Sha256};
@@ -73,7 +76,7 @@ use lightning_liquidity::{
7376
};
7477

7578
#[cfg(test)]
76-
use mockall::{automock, predicate::*};
79+
use mockall::predicate::*;
7780
use std::collections::HashMap;
7881
use std::{
7982
str::FromStr,
@@ -2054,21 +2057,7 @@ pub(crate) fn default_user_config() -> UserConfig {
20542057
}
20552058
}
20562059

2057-
#[cfg_attr(test, automock)]
2058-
pub(crate) trait LnNode {
2059-
fn logger(&self) -> &MutinyLogger;
2060-
fn skip_hodl_invoices(&self) -> bool;
2061-
fn get_outbound_payment_status(&self, payment_hash: &[u8; 32]) -> Option<HTLCStatus>;
2062-
async fn pay_invoice_with_timeout(
2063-
&self,
2064-
invoice: &Bolt11Invoice,
2065-
amt_sats: Option<u64>,
2066-
timeout_secs: Option<u64>,
2067-
labels: Vec<String>,
2068-
) -> Result<MutinyInvoice, MutinyError>;
2069-
}
2070-
2071-
impl<S: MutinyStorage> LnNode for Node<S> {
2060+
impl<S: MutinyStorage> InvoiceHandler for Node<S> {
20722061
fn logger(&self) -> &MutinyLogger {
20732062
self.logger.as_ref()
20742063
}

mutiny-core/src/nostr/nwc.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use crate::error::MutinyError;
22
use crate::event::HTLCStatus;
3-
use crate::node::LnNode;
43
use crate::nostr::nip49::NIP49Confirmation;
54
use crate::nostr::NostrManager;
65
use crate::storage::MutinyStorage;
76
use crate::utils;
7+
use crate::InvoiceHandler;
88
use anyhow::anyhow;
99
use bitcoin::hashes::hex::{FromHex, ToHex};
1010
use bitcoin::secp256k1::{Secp256k1, Signing, ThirtyTwoByteHash};
@@ -309,7 +309,7 @@ impl NostrWalletConnect {
309309

310310
pub(crate) async fn pay_nwc_invoice(
311311
&self,
312-
node: &impl LnNode,
312+
node: &impl InvoiceHandler,
313313
invoice: &Bolt11Invoice,
314314
) -> Result<Response, MutinyError> {
315315
let label = self
@@ -398,7 +398,7 @@ impl NostrWalletConnect {
398398
pub async fn handle_nwc_request<S: MutinyStorage>(
399399
&mut self,
400400
event: Event,
401-
node: &impl LnNode,
401+
node: &impl InvoiceHandler,
402402
nostr_manager: &NostrManager<S>,
403403
) -> anyhow::Result<Option<Event>> {
404404
let client_pubkey = self.client_key.public_key();
@@ -1102,11 +1102,11 @@ mod wasm_test {
11021102
use super::*;
11031103
use crate::event::{MillisatAmount, PaymentInfo};
11041104
use crate::logging::MutinyLogger;
1105-
use crate::node::MockLnNode;
11061105
use crate::nodemanager::MutinyInvoice;
11071106
use crate::nostr::ProfileType;
11081107
use crate::storage::MemoryStorage;
11091108
use crate::test_utils::{create_dummy_invoice, create_node, create_nwc_request};
1109+
use crate::MockInvoiceHandler;
11101110
use bitcoin::hashes::Hash;
11111111
use bitcoin::secp256k1::ONE_KEY;
11121112
use bitcoin::Network;
@@ -1454,7 +1454,7 @@ mod wasm_test {
14541454
async fn test_process_nwc_event_budget() {
14551455
let storage = MemoryStorage::default();
14561456
let logger = Arc::new(MutinyLogger::default());
1457-
let mut node = MockLnNode::new();
1457+
let mut node = MockInvoiceHandler::new();
14581458

14591459
let amount_msats = 5_000;
14601460

0 commit comments

Comments
 (0)