Skip to content

Commit 7c1cc1a

Browse files
committed
refactor using combination of traits for a single referance
1 parent 81568f6 commit 7c1cc1a

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

src/ln/msgs.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -564,14 +564,18 @@ pub trait RoutingMessageHandler : Send + Sync {
564564
fn handle_htlc_fail_channel_update(&self, update: &HTLCFailChannelUpdate);
565565
}
566566

567-
///A trait to describe the API required to access the network topology
568-
pub trait NetworkAPI : Send + Sync {
567+
///A trait to describe the functions required to access the local network topology
568+
pub trait NetworkTopology : Send + Sync {
569569
///This should return a vec of all possible channel announcements or an error
570570
fn get_all_channel_announcements(&self)-> Result<Vec<ChannelAnnouncement>, std::fmt::Error>;
571571
///This should return a vec of all possible node announcements or an error
572572
fn get_all_node_announcements(&self)-> Result<Vec<NodeAnnouncement>, std::fmt::Error>;
573573
}
574574

575+
///this is a combination trait of NetworkTopology and RoutingMerssageHandler
576+
pub trait NetworkAPI : RoutingMessageHandler + NetworkTopology{}
577+
impl<T> NetworkAPI for T where T: RoutingMessageHandler+NetworkTopology{}
578+
575579
pub(crate) struct OnionRealm0HopData {
576580
pub(crate) short_channel_id: u64,
577581
pub(crate) amt_to_forward: u64,

src/ln/peer_handler.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub struct MessageHandler {
2828
pub chan_handler: Arc<msgs::ChannelMessageHandler>,
2929
/// A message handler which handles messages updating our knowledge of the network channel
3030
/// graph. Usually this is just a Router object.
31-
pub route_handler: Arc<msgs::RoutingMessageHandler>,
31+
pub route_handler: Arc<msgs::NetworkAPI>,
3232
}
3333

3434
/// Provides an object which can be used to send data to and which uniquely identifies a connection
@@ -131,7 +131,6 @@ pub struct PeerManager<Descriptor: SocketDescriptor> {
131131
pending_events: Mutex<Vec<Event>>,
132132
our_node_secret: SecretKey,
133133
initial_syncs_sent: AtomicUsize,
134-
network_api : NetworkAPI,
135134
logger: Arc<Logger>,
136135
}
137136

src/ln/router.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use bitcoin::blockdata::opcodes;
1313

1414
use chain::chaininterface::{ChainError, ChainWatchInterface};
1515
use ln::channelmanager;
16-
use ln::msgs::{ErrorAction,HandleError,RoutingMessageHandler,NetAddress,GlobalFeatures, NetworkAPI};
16+
use ln::msgs::{ErrorAction,HandleError,RoutingMessageHandler,NetAddress,GlobalFeatures,NetworkTopology};
1717
use ln::msgs;
1818
use util::ser::Writeable;
1919
use util::logger::Logger;
@@ -428,8 +428,8 @@ impl RoutingMessageHandler for Router {
428428
}
429429
}
430430

431-
impl NetworkAPI for Router {
432-
fn get_all_channel_announcements(&self)-> Result<Vec<msgs::NodeAnnouncement>, std::fmt::Error>{
431+
impl NetworkTopology for Router {
432+
fn get_all_channel_announcements(&self)-> Result<Vec<msgs::ChannelAnnouncement>, std::fmt::Error>{
433433
unimplemented!();
434434
}
435435
fn get_all_node_announcements(&self)-> Result<Vec<msgs::NodeAnnouncement>, std::fmt::Error>{

0 commit comments

Comments
 (0)