Skip to content

Commit 4d4d7f9

Browse files
committed
f - Add example to NetworkUpdateHandler docs
1 parent 704b183 commit 4d4d7f9

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

lightning/src/routing/network_graph.rs

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,46 @@ where C::Target: chain::Access, L::Target: Logger {
129129
/// Provides interface to help with initial routing sync by
130130
/// serving historical announcements.
131131
///
132-
/// An [`EventHandler`] decorator for applying updates from [`Event::PaymentFailed`] to the
133-
/// [`NetworkGraph`].
132+
/// Serves as an [`EventHandler`] decorator for applying updates from [`Event::PaymentFailed`] to
133+
/// the [`NetworkGraph`].
134+
///
135+
/// # Example
136+
///
137+
/// ```
138+
/// # extern crate bitcoin;
139+
/// #
140+
/// # use bitcoin::blockdata::constants::genesis_block;
141+
/// # use bitcoin::blockdata::transaction::TxOut;
142+
/// # use bitcoin::hash_types::BlockHash;
143+
/// # use bitcoin::network::constants::Network;
144+
/// # use lightning::chain;
145+
/// # use lightning::routing::network_graph::{NetGraphMsgHandler, NetworkGraph};
146+
/// # use lightning::util::events::Event;
147+
/// # use lightning::util::logger::{Logger, Record};
148+
/// #
149+
/// # struct NullLogger;
150+
/// # impl Logger for NullLogger {
151+
/// # fn log(&self, _record: &Record) {}
152+
/// # }
153+
/// # struct ChainSource;
154+
/// # impl chain::Access for ChainSource {
155+
/// # fn get_utxo(&self, _: &BlockHash, _: u64) -> Result<TxOut, chain::AccessError> {
156+
/// # unimplemented!()
157+
/// # }
158+
/// # }
159+
/// let network_graph = NetworkGraph::new(genesis_block(Network::Testnet).header.block_hash());
160+
/// let chain_source = ChainSource {};
161+
/// let logger = NullLogger {};
162+
/// let event_handler = |event: &Event| {
163+
/// // Handle event
164+
/// };
165+
/// let event_handler = NetGraphMsgHandler::new(network_graph, Some(&chain_source), &logger, event_handler);
166+
/// ```
167+
///
168+
/// Once `event_handler` has been decorated, use it with any implementation of [`EventsProvider`] as
169+
/// usual.
170+
///
171+
/// [`EventsProvider`]: crate::util::events::EventsProvider
134172
pub struct NetGraphMsgHandler<C: Deref, L: Deref, E: EventHandler>
135173
where C::Target: chain::Access, L::Target: Logger
136174
{

0 commit comments

Comments
 (0)