@@ -28,7 +28,7 @@ use bitcoin::hashes::hmac::Hmac;
28
28
use bitcoin::hashes::sha256::Hash as Sha256;
29
29
use bitcoin::hash_types::{BlockHash, Txid};
30
30
31
- use bitcoin::secp256k1::{SecretKey, PublicKey};
31
+ use bitcoin::secp256k1::{schnorr, PublicKey, SecretKey };
32
32
use bitcoin::secp256k1::Secp256k1;
33
33
use bitcoin::{secp256k1, Sequence};
34
34
@@ -47,6 +47,7 @@ use crate::events::{self, Event, EventHandler, EventsProvider, InboundChannelFun
47
47
// construct one themselves.
48
48
use crate::ln::inbound_payment;
49
49
use crate::ln::types::ChannelId;
50
+ use crate::offers::flow::OffersMessageCommons;
50
51
use crate::types::payment::{PaymentHash, PaymentPreimage, PaymentSecret};
51
52
use crate::ln::channel::{self, Channel, ChannelError, ChannelUpdateStatus, FundedChannel, ShutdownResult, UpdateFulfillCommitFetch, OutboundV1Channel, ReconnectionMsg, InboundV1Channel, WithChannelContext};
52
53
#[cfg(any(dual_funding, splicing))]
@@ -122,7 +123,7 @@ use core::{cmp, mem};
122
123
use core::borrow::Borrow;
123
124
use core::cell::RefCell;
124
125
use crate::io::Read;
125
- use crate::sync::{Arc, Mutex, RwLock, RwLockReadGuard, FairRwLock, LockTestExt, LockHeldState };
126
+ use crate::sync::{Arc, FairRwLock, LockHeldState, LockTestExt, Mutex, MutexGuard, RwLock, RwLockReadGuard };
126
127
use core::sync::atomic::{AtomicUsize, AtomicBool, Ordering};
127
128
use core::time::Duration;
128
129
use core::ops::Deref;
@@ -9932,6 +9933,88 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {
9932
9933
}
9933
9934
} }
9934
9935
9936
+ impl<M: Deref, T: Deref, ES: Deref, NS: Deref, SP: Deref, F: Deref, R: Deref, MR: Deref, L: Deref> OffersMessageCommons for ChannelManager<M, T, ES, NS, SP, F, R, MR, L>
9937
+ where
9938
+ M::Target: chain::Watch<<SP::Target as SignerProvider>::EcdsaSigner>,
9939
+ T::Target: BroadcasterInterface,
9940
+ ES::Target: EntropySource,
9941
+ NS::Target: NodeSigner,
9942
+ SP::Target: SignerProvider,
9943
+ F::Target: FeeEstimator,
9944
+ R::Target: Router,
9945
+ MR::Target: MessageRouter,
9946
+ L::Target: Logger,
9947
+ {
9948
+ fn get_current_blocktime(&self) -> Duration {
9949
+ Duration::from_secs(self.highest_seen_timestamp.load(Ordering::Acquire) as u64)
9950
+ }
9951
+
9952
+ fn get_peer_for_blinded_path(&self) -> Vec<MessageForwardNode> {
9953
+ self.per_peer_state.read().unwrap()
9954
+ .iter()
9955
+ .map(|(node_id, peer_state)| (node_id, peer_state.lock().unwrap()))
9956
+ .filter(|(_, peer)| peer.is_connected)
9957
+ .filter(|(_, peer)| peer.latest_features.supports_onion_messages())
9958
+ .map(|(node_id, peer)| MessageForwardNode {
9959
+ node_id: *node_id,
9960
+ short_channel_id: peer.channel_by_id
9961
+ .iter()
9962
+ .filter(|(_, channel)| channel.context().is_usable())
9963
+ .min_by_key(|(_, channel)| channel.context().channel_creation_height)
9964
+ .and_then(|(_, channel)| channel.context().get_short_channel_id()),
9965
+ })
9966
+ .collect::<Vec<_>>()
9967
+ }
9968
+
9969
+ fn create_blinded_payment_paths(
9970
+ &self, amount_msats: Option<u64>, payment_secret: PaymentSecret, payment_context: PaymentContext, relative_expiry_time: u32,
9971
+ ) -> Result<Vec<BlindedPaymentPath>, ()> {
9972
+ self.create_blinded_payment_paths(amount_msats, payment_secret, payment_context, relative_expiry_time)
9973
+ }
9974
+
9975
+ fn create_inbound_payment(&self, min_value_msat: Option<u64>, invoice_expiry_delta_secs: u32,
9976
+ min_final_cltv_expiry_delta: Option<u16>) -> Result<(PaymentHash, PaymentSecret), ()> {
9977
+ self.create_inbound_payment(min_value_msat, invoice_expiry_delta_secs, min_final_cltv_expiry_delta)
9978
+ }
9979
+
9980
+ fn release_invoice_requests_awaiting_invoice(&self) -> Vec<(PaymentId, RetryableInvoiceRequest)> {
9981
+ self.pending_outbound_payments.release_invoice_requests_awaiting_invoice()
9982
+ }
9983
+
9984
+ fn sign_bolt12_invoice(
9985
+ &self, invoice: &UnsignedBolt12Invoice,
9986
+ ) -> Result<schnorr::Signature, ()> {
9987
+ self.node_signer.sign_bolt12_invoice(invoice)
9988
+ }
9989
+
9990
+ fn send_payment_for_verified_bolt12_invoice(&self, invoice: &Bolt12Invoice, payment_id: PaymentId) -> Result<(), Bolt12PaymentError> {
9991
+ self.send_payment_for_verified_bolt12_invoice(invoice, payment_id)
9992
+ }
9993
+
9994
+ fn abandon_payment_with_reason(&self, payment_id: PaymentId, reason: PaymentFailureReason) {
9995
+ self.abandon_payment_with_reason(payment_id, reason);
9996
+ }
9997
+
9998
+ // ----Temporary Functions----
9999
+ // Set of functions temporarily moved to OffersMessageCommons for easier
10000
+ // transition of code from ChannelManager to OffersMessageFlow
10001
+
10002
+ fn get_pending_offers_messages(&self) -> MutexGuard<'_, Vec<(OffersMessage, MessageSendInstructions)>> {
10003
+ self.pending_offers_messages.lock().expect("Mutex is locked by other thread.")
10004
+ }
10005
+
10006
+ fn enqueue_invoice_request(&self, invoice_request: InvoiceRequest, reply_paths: Vec<BlindedMessagePath>) -> Result<(), Bolt12SemanticError> {
10007
+ self.enqueue_invoice_request(invoice_request, reply_paths)
10008
+ }
10009
+
10010
+ #[cfg(async_payments)]
10011
+ fn initiate_async_payment(
10012
+ &self, invoice: &StaticInvoice, payment_id: PaymentId
10013
+ ) -> Result<(), Bolt12PaymentError> {
10014
+ self.initiate_async_payment(invoice, payment_id)
10015
+ }
10016
+ }
10017
+
9935
10018
/// Defines the maximum number of [`OffersMessage`] including different reply paths to be sent
9936
10019
/// along different paths.
9937
10020
/// Sending multiple requests increases the chances of successful delivery in case some
0 commit comments