@node-lightning/graph
v0.28.0
Published
Lightning Network P2P Graph
Downloads
61
Maintainers
Readme
@node-lightning/graph
This library constructs a graph as an adjacency list from P2P gossip messages.
This class includes the following types:
- GraphManger - constructs a graph from gossip messages
- Graph - adjacency list representation of a graph
- Node - vertex in the graph
- Channel - directional edge in the graph
- ChannelSettings - one directional edge information
Examples
Message from a gossip emitter (defined in @node-lightning/wire) will be used to construct an adjacency list based graph.
const graphManager = new GossipManager(gossipEmitter);
graphManager.on("node", (node: Node) => {
//
});
graphManager.on("channel", (channel: Channel) => {
//
});
graphManager.on("channel_update", (channel: Channel, settings: ChannelSettings) => {
//
});
The following events are emitted for the corresponding gossip message:
channel_announcement message
- emits node event for node1 in channel
- emits node event for node2 in channel
- emits channel
channel_update message
- emits channel_update event
node_announcement message
- emits node event
LND Serialization
You can serialize the graph instance in the same manner as the serialization used in LND RPC calls.
const serializer = new LndSerializer();
// to a plain-old JavaScript object
serializer.toObject(graph);
// to JSON
serializer.toJson(graph);