@node-lightning/graph
Version:
Lightning Network P2P Graph
63 lines • 2.35 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.LndSerializer = void 0;
/**
* Performs JSON serialization of the graph in the same format
* as used by LND and defined in LND API documentation:
*
* https://api.lightning.community/#simple-rpc-33
*/
class LndSerializer {
toObject(g) {
return {
nodes: Array.from(g.nodes.values()).map(node => this.serializeNode(node)),
edges: Array.from(g.channels.values()).map(chan => this.serializeChannel(chan)),
};
}
toJSON(g, format = true) {
const obj = this.toObject(g);
return format ? JSON.stringify(obj, null, 2) : JSON.stringify(obj);
}
serializeNode(node) {
return {
last_update: node.lastUpdate,
pub_key: node.nodeId.toString("hex"),
alias: node.aliasString,
addresses: node.addresses.filter(p => p).map(address => this.serializeAddress(address)),
color: node.rgbColorString,
};
}
serializeAddress(address) {
return {
network: "tcp",
addr: address.toString(),
};
}
serializeChannel(chan) {
return {
channel_id: chan.shortChannelId.toNumber().toString(),
chan_point: chan.channelPoint && chan.channelPoint.toString(),
last_update: chan.lastUpdate,
node1_pub: chan.nodeId1.toString("hex"),
node2_pub: chan.nodeId2.toString("hex"),
capacity: chan.capacity && chan.capacity.toString(),
node1_policy: this.serializeRoutingPolicy(chan.node1Settings),
node2_policy: this.serializeRoutingPolicy(chan.node2Settings),
};
}
serializeRoutingPolicy(policy) {
if (!policy)
return null;
return {
time_lock_delta: policy.cltvExpiryDelta,
min_htlc: policy.htlcMinimumMsat.toString(),
fee_base_msat: policy.feeBaseMsat.toString(),
fee_rate_milli_msat: policy.feeProportionalMillionths.toString(),
disabled: policy.disabled,
max_htlc_msat: policy.htlcMaximumMsat ? policy.htlcMaximumMsat.toString() : "0",
last_update: policy.timestamp,
};
}
}
exports.LndSerializer = LndSerializer;
//# sourceMappingURL=lnd-serializer.js.map