lnvis

nanovg lightning network visualizer
git clone git://jb55.com/lnvis
Log | Files | Refs | README | LICENSE

ln.h (2738B)


      1 
      2 #ifndef LNVIS_LN_H
      3 #define LNVIS_LN_H
      4 
      5 #include "nanovg/nanovg.h"
      6 #include "defs.h"
      7 
      8 #define CELL_MAX_ELEMS 32
      9 #define MAX_ALIAS_SIZE 32
     10 
     11 // TODO: parse pubkeys
     12 #define PUBKEY_SIZE 66
     13 
     14 union color {
     15 	float rgba[4];
     16 	struct {
     17 		float r, g, b, a;
     18 	};
     19 	NVGcolor nvg_color;
     20 };
     21 
     22 struct node {
     23 	char alias[MAX_ALIAS_SIZE+1];
     24 	char id[PUBKEY_SIZE+1];
     25 
     26 	int visible, mark_filtered, adj_drag_target;
     27 
     28 	union color color;
     29 
     30 	struct cell *cell;
     31 	double x, y;
     32 	double vx, vy;
     33 	double ax, ay;
     34 
     35 	float size;
     36 };
     37 
     38 
     39 // REMOTE: remote node opened the channel with local
     40 // LOCAL: local node opened the channel with remote
     41 enum side {
     42 	LOCAL,
     43 	REMOTE,
     44 	NUM_SIDES
     45 };
     46 
     47 /*
     48  *   type: 256 (`channel_announcement`)
     49  *     - [`64`:`node_signature_1`]
     50  *     - [`64`:`node_signature_2`]
     51  *     - [`64`:`bitcoin_signature_1`]
     52  *     - [`64`:`bitcoin_signature_2`]
     53  *     - [`2`:`len`]
     54  *     - [`len`:`features`]
     55  *     - [`32`:`chain_hash`]
     56  *     - [`8`:`short_channel_id`]
     57  *     - [`33`:`node_id_1`]
     58  *     - [`33`:`node_id_2`]
     59  *     - [`33`:`bitcoin_key_1`]
     60  *     - [`33`:`bitcoin_key_2`]
     61  */
     62 
     63 /* type: 258 (`channel_update`)
     64  *    - [`64`:`signature`]
     65  *    - [`32`:`chain_hash`]
     66  *    - [`8`:`short_channel_id`]
     67  *    - [`4`:`timestamp`]
     68  *    - [`2`:`flags`]
     69  *    - [`2`:`cltv_expiry_delta`]
     70  *    - [`8`:`htlc_minimum_msat`]
     71  *    - [`4`:`fee_base_msat`]
     72  *    - [`4`:`fee_proportional_millionths`]
     73  */
     74 
     75 struct short_channel_id {
     76 	u32 blocknum;
     77 	u32 txnum;
     78 	u16 outnum;
     79 };
     80 
     81 struct channel {
     82 	struct node *nodes[2];
     83 
     84 	char source[PUBKEY_SIZE+1];
     85 	char destination[PUBKEY_SIZE+1];
     86 
     87 	struct short_channel_id short_channel_id;
     88 	u8 public;
     89 	u8 active;
     90 
     91 	u16 flags;
     92 
     93 	u32 last_update_timestamp;
     94 	u32 delay;
     95 	u32 base_fee_msat;
     96 	u32 fee_per_millionth;
     97 
     98 	u64 satoshis;
     99 
    100 	// app specific stuff
    101 	int visible;
    102 	int draw_last;
    103 };
    104 
    105 enum display_flags {
    106 	DISP_DARK         = 1UL << 0,
    107 	DISP_GRID         = 1UL << 1,
    108 	DISP_ALIASES      = 1UL << 2,
    109 	DISP_STROKE_NODES = 1UL << 3,
    110 	DISP_BEZIER       = 1UL << 4,
    111 	DISP_FPS          = 1UL << 5,
    112 };
    113 
    114 struct ln {
    115 	NVGcontext *vg;
    116 
    117 	int clicked;
    118 	int right_clicked;
    119 	int mdown;
    120 	double mx, my;
    121 	int window_width;
    122 	int window_height;
    123 
    124 	char *filter;
    125 	union color clear_color;
    126 	u64 display_flags;
    127 
    128 	int grid_div;
    129 	struct cell *grid;
    130 
    131 	struct node *drag_target;
    132 	struct node *last_drag_target;
    133 	struct node *filter_target;
    134 
    135 	struct node *nodes;
    136 	u32 node_count;
    137 
    138 	struct channel *channels;
    139 	u32 channel_count;
    140 };
    141 
    142 void init_ln(struct ln *ln, int grid_div);
    143 void free_ln(struct ln *ln);
    144 void random_network(int ww, int wh, int max_per_node, int num_nodes, struct ln *ln);
    145 void init_network(int ww, int wh, struct ln *ln);
    146 void filter_network(const char *nodeid, struct node *filter_node, struct ln *ln);
    147 
    148 #endif /* LNVIS_LN_H */