Skip to content

Commit e25d973

Browse files
committed
common: move json_add_channel_type from lightningd/
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
1 parent 84dcd19 commit e25d973

File tree

8 files changed

+35
-31
lines changed

8 files changed

+35
-31
lines changed

common/json_channel_type.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,19 @@ void json_add_channel_type_arr(struct json_stream *response,
4343
json_array_end(response);
4444
}
4545

46+
void json_add_channel_type(struct json_stream *response,
47+
const char *fieldname,
48+
const struct channel_type *channel_type)
49+
{
50+
const char **fnames;
51+
52+
json_object_start(response, fieldname);
53+
json_add_channel_type_arr(response, "bits", channel_type);
54+
55+
json_array_start(response, "names");
56+
fnames = channel_type_name(tmpctx, channel_type);
57+
for (size_t i = 0; i < tal_count(fnames); i++)
58+
json_add_string(response, NULL, fnames[i]);
59+
json_array_end(response);
60+
json_object_end(response);
61+
}

common/json_channel_type.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,10 @@ struct command_result *param_channel_type(struct command *cmd,
1818
void json_add_channel_type_arr(struct json_stream *response,
1919
const char *fieldname,
2020
const struct channel_type *ctype);
21+
22+
23+
/* Add channel_type object, with array and names */
24+
void json_add_channel_type(struct json_stream *response,
25+
const char *fieldname,
26+
const struct channel_type *channel_type);
2127
#endif /* LIGHTNING_COMMON_JSON_CHANNEL_TYPE_H */

common/json_stream.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ struct bip340sig;
2424
struct secret;
2525
struct node_id;
2626
struct channel_id;
27+
struct channel_type;
2728
struct bitcoin_txid;
2829
struct bitcoin_outpoint;
2930
struct short_channel_id;

lightningd/closed_channel.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "config.h"
2+
#include <common/json_channel_type.h>
23
#include <common/json_command.h>
34
#include <common/json_param.h>
45
#include <common/json_stream.h>

lightningd/peer_control.c

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <common/features.h>
2020
#include <common/htlc_trim.h>
2121
#include <common/initial_commit_tx.h>
22+
#include <common/json_channel_type.h>
2223
#include <common/json_command.h>
2324
#include <common/json_param.h>
2425
#include <common/jsonrpc_errors.h>
@@ -805,29 +806,6 @@ struct amount_msat channel_amount_receivable(const struct channel *channel)
805806
return receivable;
806807
}
807808

808-
void json_add_channel_type(struct json_stream *response,
809-
const char *fieldname,
810-
const struct channel_type *channel_type)
811-
{
812-
const char **fnames;
813-
814-
json_object_start(response, fieldname);
815-
json_array_start(response, "bits");
816-
for (size_t i = 0; i < tal_bytelen(channel_type->features) * CHAR_BIT; i++) {
817-
if (!feature_is_set(channel_type->features, i))
818-
continue;
819-
json_add_u64(response, NULL, i);
820-
}
821-
json_array_end(response);
822-
823-
json_array_start(response, "names");
824-
fnames = channel_type_name(tmpctx, channel_type);
825-
for (size_t i = 0; i < tal_count(fnames); i++)
826-
json_add_string(response, NULL, fnames[i]);
827-
json_array_end(response);
828-
json_object_end(response);
829-
}
830-
831809
static void json_add_channel(struct lightningd *ld,
832810
struct json_stream *response, const char *key,
833811
const struct channel *channel,

lightningd/peer_control.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,6 @@ command_find_channel(struct command *cmd,
145145
const char *buffer, const jsmntok_t *tok,
146146
struct channel **channel);
147147

148-
/* Add channel_type object */
149-
void json_add_channel_type(struct json_stream *response,
150-
const char *fieldname,
151-
const struct channel_type *channel_type);
152-
153148
/* Ancient (0.7.0 and before) releases could create invalid commitment txs! */
154149
bool invalid_last_tx(const struct bitcoin_tx *tx);
155150

lightningd/test/run-invoice-select-inchan.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,6 @@ const char *channel_state_str(enum channel_state state UNNEEDED)
110110
/* Generated stub for channel_type_has */
111111
bool channel_type_has(const struct channel_type *type UNNEEDED, int feature UNNEEDED)
112112
{ fprintf(stderr, "channel_type_has called!\n"); abort(); }
113-
/* Generated stub for channel_type_name */
114-
const char **channel_type_name(const tal_t *ctx UNNEEDED, const struct channel_type *t UNNEEDED)
115-
{ fprintf(stderr, "channel_type_name called!\n"); abort(); }
116113
/* Generated stub for channel_unsaved_close_conn */
117114
void channel_unsaved_close_conn(struct channel *channel UNNEEDED, const char *why UNNEEDED)
118115
{ fprintf(stderr, "channel_unsaved_close_conn called!\n"); abort(); }
@@ -489,6 +486,11 @@ void json_add_bolt11(struct json_stream *response UNNEEDED,
489486
void json_add_bool(struct json_stream *result UNNEEDED, const char *fieldname UNNEEDED,
490487
bool value UNNEEDED)
491488
{ fprintf(stderr, "json_add_bool called!\n"); abort(); }
489+
/* Generated stub for json_add_channel_type */
490+
void json_add_channel_type(struct json_stream *response UNNEEDED,
491+
const char *fieldname UNNEEDED,
492+
const struct channel_type *channel_type UNNEEDED)
493+
{ fprintf(stderr, "json_add_channel_type called!\n"); abort(); }
492494
/* Generated stub for json_add_escaped_string */
493495
void json_add_escaped_string(struct json_stream *result UNNEEDED,
494496
const char *fieldname UNNEEDED,

wallet/test/run-wallet.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,11 @@ void json_add_channel_id(struct json_stream *response UNNEEDED,
373373
const char *fieldname UNNEEDED,
374374
const struct channel_id *cid UNNEEDED)
375375
{ fprintf(stderr, "json_add_channel_id called!\n"); abort(); }
376+
/* Generated stub for json_add_channel_type */
377+
void json_add_channel_type(struct json_stream *response UNNEEDED,
378+
const char *fieldname UNNEEDED,
379+
const struct channel_type *channel_type UNNEEDED)
380+
{ fprintf(stderr, "json_add_channel_type called!\n"); abort(); }
376381
/* Generated stub for json_add_hex */
377382
void json_add_hex(struct json_stream *result UNNEEDED, const char *fieldname UNNEEDED,
378383
const void *data UNNEEDED, size_t len UNNEEDED)

0 commit comments

Comments
 (0)