forked from ElementsProject/lightning
-
Notifications
You must be signed in to change notification settings - Fork 0
/
billboard.c
67 lines (62 loc) · 2.13 KB
/
billboard.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "config.h"
#include <ccan/ccan/tal/str/str.h>
#include <common/billboard.h>
#include <common/utils.h>
char *billboard_message(const tal_t *ctx,
const bool channel_ready[NUM_SIDES],
const bool have_sigs[NUM_SIDES],
const bool shutdown_sent[NUM_SIDES],
u32 depth_togo,
size_t num_htlcs)
{
const char *funding_status, *announce_status,
*shutdown_status COMPILER_WANTS_INIT("gcc 8.3.0");
if (channel_ready[LOCAL] && channel_ready[REMOTE])
funding_status = "Channel ready for use.";
else if (!channel_ready[LOCAL] && !channel_ready[REMOTE])
funding_status = tal_fmt(ctx,
"Funding needs %d more"
" confirmations to be ready.",
depth_togo);
else if (channel_ready[LOCAL] && !channel_ready[REMOTE])
funding_status = "We've confirmed channel ready, they haven't yet.";
else {
assert(!channel_ready[LOCAL] && channel_ready[REMOTE]);
funding_status = "They've confirmed channel ready, we haven't yet.";
}
if (have_sigs) {
if (have_sigs[LOCAL] && have_sigs[REMOTE])
announce_status = " Channel announced.";
else if (have_sigs[LOCAL] && !have_sigs[REMOTE])
announce_status = " Waiting for their"
" announcement signatures.";
else if (!have_sigs[LOCAL] && have_sigs[REMOTE])
announce_status = " They need our announcement"
" signatures.";
else {
assert(!have_sigs[LOCAL] && !have_sigs[REMOTE]);
announce_status = "";
}
} else
announce_status = "";
if (!shutdown_sent[LOCAL] && !shutdown_sent[REMOTE])
shutdown_status = "";
else if (!shutdown_sent[LOCAL] && shutdown_sent[REMOTE])
shutdown_status = " They've sent shutdown, waiting for ours";
else if (shutdown_sent[LOCAL] && !shutdown_sent[REMOTE])
shutdown_status = " We've send shutdown, waiting for theirs";
else if (shutdown_sent[LOCAL] && shutdown_sent[REMOTE]) {
if (num_htlcs)
shutdown_status = tal_fmt(ctx,
" Shutdown messages"
" exchanged, waiting for"
" %zu HTLCs to complete.",
num_htlcs);
else
shutdown_status = tal_fmt(ctx,
" Shutdown messages"
" exchanged.");
}
return tal_fmt(ctx, "%s%s%s", funding_status,
announce_status, shutdown_status);
}