@@ -2203,96 +2203,104 @@ static struct command_result *json_getinfo(struct command *cmd,
22032203 const jsmntok_t * obj UNNEEDED ,
22042204 const jsmntok_t * params )
22052205{
2206- struct json_stream * response ;
2207- struct peer * peer ;
2208- struct channel * channel ;
2209- unsigned int pending_channels = 0 , active_channels = 0 ,
2210- inactive_channels = 0 , num_peers = 0 ;
2211- size_t count_announceable ;
2212-
2213- if (!param (cmd , buffer , params , NULL ))
2214- return command_param_failed ();
2206+ struct json_stream * response ;
2207+ struct peer * peer ;
2208+ struct channel * channel ;
2209+ unsigned int pending_channels = 0 , active_channels = 0 ,
2210+ inactive_channels = 0 , num_peers = 0 ;
2211+ size_t count_announceable ;
2212+
2213+ if (!param (cmd , buffer , params , NULL ))
2214+ return command_param_failed ();
2215+
2216+ response = json_stream_success (cmd );
2217+ json_add_node_id (response , "id" , & cmd -> ld -> id );
2218+ json_add_string (response , "alias" , (const char * )cmd -> ld -> alias );
2219+ json_add_hex_talarr (response , "color" , cmd -> ld -> rgb );
22152220
2216- response = json_stream_success (cmd );
2217- json_add_node_id (response , "id" , & cmd -> ld -> id );
2218- json_add_string (response , "alias" , (const char * )cmd -> ld -> alias );
2219- json_add_hex_talarr (response , "color" , cmd -> ld -> rgb );
2220-
2221- /* Add some peer and channel stats */
2222- list_for_each (& cmd -> ld -> peers , peer , list ) {
2223- num_peers ++ ;
2224-
2225- list_for_each (& peer -> channels , channel , list ) {
2226- if (channel -> state == CHANNELD_AWAITING_LOCKIN
2227- || channel -> state == DUALOPEND_AWAITING_LOCKIN
2228- || channel -> state == DUALOPEND_OPEN_INIT ) {
2229- pending_channels ++ ;
2230- } else if (channel_active (channel )) {
2231- active_channels ++ ;
2232- } else {
2233- inactive_channels ++ ;
2234- }
2235- }
2236- }
2237- json_add_num (response , "num_peers" , num_peers );
2238- json_add_num (response , "num_pending_channels" , pending_channels );
2239- json_add_num (response , "num_active_channels" , active_channels );
2240- json_add_num (response , "num_inactive_channels" , inactive_channels );
2241-
2242- /* Add network info */
2243- if (cmd -> ld -> listen ) {
2244- /* These are the addresses we're announcing */
2245- count_announceable = tal_count (cmd -> ld -> announceable );
2246- json_array_start (response , "address" );
2247- for (size_t i = 0 ; i < count_announceable ; i ++ )
2248- json_add_address (response , NULL , cmd -> ld -> announceable + i );
2249-
2250- /* Currently, IP discovery will only be announced by gossipd, if we
2251- * don't already have usable addresses.
2252- * See `create_node_announcement` in `gossip_generation.c`. */
2253- if (count_announceable == 0 ) {
2254- if (cmd -> ld -> remote_addr_v4 != NULL &&
2255- !wireaddr_arr_contains (cmd -> ld -> announceable , cmd -> ld -> remote_addr_v4 ))
2256- json_add_address (response , NULL , cmd -> ld -> remote_addr_v4 );
2257- if (cmd -> ld -> remote_addr_v6 != NULL &&
2258- !wireaddr_arr_contains (cmd -> ld -> announceable , cmd -> ld -> remote_addr_v6 ))
2259- json_add_address (response , NULL , cmd -> ld -> remote_addr_v6 );
2260- }
2261- json_array_end (response );
2262-
2263- /* This is what we're actually bound to. */
2264- json_array_start (response , "binding" );
2265- for (size_t i = 0 ; i < tal_count (cmd -> ld -> binding ); i ++ )
2266- json_add_address_internal (response , NULL ,
2267- cmd -> ld -> binding + i );
2268- json_array_end (response );
2269- }
2270- json_add_string (response , "version" , version ());
2271- json_add_num (response , "blockheight" , cmd -> ld -> blockheight );
2272- json_add_string (response , "network" , chainparams -> network_name );
2273- json_add_amount_msat_compat (response ,
2274- wallet_total_forward_fees (cmd -> ld -> wallet ),
2275- "msatoshi_fees_collected" ,
2276- "fees_collected_msat" );
2277- json_add_string (response , "lightning-dir" , cmd -> ld -> config_netdir );
2278-
2279- if (!cmd -> ld -> topology -> bitcoind -> synced )
2280- json_add_string (response , "warning_bitcoind_sync" ,
2281- "Bitcoind is not up-to-date with network." );
2282- else if (!topology_synced (cmd -> ld -> topology ))
2283- json_add_string (response , "warning_lightningd_sync" ,
2284- "Still loading latest blocks from bitcoind." );
2285-
2286- u8 * * bits = cmd -> ld -> our_features -> bits ;
2287- json_object_start (response , "our_features" );
2288- json_add_hex_talarr (response , "init" ,
2289- featurebits_or (cmd , bits [INIT_FEATURE ], bits [GLOBAL_INIT_FEATURE ]));
2290- json_add_hex_talarr (response , "node" , bits [NODE_ANNOUNCE_FEATURE ]);
2291- json_add_hex_talarr (response , "channel" , bits [CHANNEL_FEATURE ]);
2292- json_add_hex_talarr (response , "invoice" , bits [BOLT11_FEATURE ]);
2293- json_object_end (response );
2294-
2295- return command_success (cmd , response );
2221+ /* Add some peer and channel stats */
2222+ list_for_each (& cmd -> ld -> peers , peer , list ) {
2223+ num_peers ++ ;
2224+
2225+ list_for_each (& peer -> channels , channel , list ) {
2226+ if (channel -> state == CHANNELD_AWAITING_LOCKIN
2227+ || channel -> state == DUALOPEND_AWAITING_LOCKIN
2228+ || channel -> state == DUALOPEND_OPEN_INIT ) {
2229+ pending_channels ++ ;
2230+ } else if (channel_active (channel )) {
2231+ active_channels ++ ;
2232+ } else {
2233+ inactive_channels ++ ;
2234+ }
2235+ }
2236+ }
2237+ json_add_num (response , "num_peers" , num_peers );
2238+ json_add_num (response , "num_pending_channels" , pending_channels );
2239+ json_add_num (response , "num_active_channels" , active_channels );
2240+ json_add_num (response , "num_inactive_channels" , inactive_channels );
2241+
2242+ /* Add network info */
2243+ if (cmd -> ld -> listen ) {
2244+ /* These are the addresses we're announcing */
2245+ count_announceable = tal_count (cmd -> ld -> announceable );
2246+ json_array_start (response , "address" );
2247+ for (size_t i = 0 ; i < count_announceable ; i ++ )
2248+ json_add_address (response , NULL , cmd -> ld -> announceable + i );
2249+
2250+ /* Currently, IP discovery will only be announced by gossipd, if we
2251+ * don't already have usable addresses.
2252+ * See `create_node_announcement` in `gossip_generation.c`. */
2253+ if (count_announceable == 0 ) {
2254+ if (cmd -> ld -> remote_addr_v4 != NULL &&
2255+ !wireaddr_arr_contains (
2256+ cmd -> ld -> announceable ,
2257+ cmd -> ld -> remote_addr_v4 ))
2258+ json_add_address (response , NULL ,
2259+ cmd -> ld -> remote_addr_v4 );
2260+ if (cmd -> ld -> remote_addr_v6 != NULL &&
2261+ !wireaddr_arr_contains (
2262+ cmd -> ld -> announceable ,
2263+ cmd -> ld -> remote_addr_v6 ))
2264+ json_add_address (response , NULL ,
2265+ cmd -> ld -> remote_addr_v6 );
2266+ }
2267+ json_array_end (response );
2268+
2269+ /* This is what we're actually bound to. */
2270+ json_array_start (response , "binding" );
2271+ for (size_t i = 0 ; i < tal_count (cmd -> ld -> binding ); i ++ )
2272+ json_add_address_internal (response , NULL ,
2273+ cmd -> ld -> binding + i );
2274+ json_array_end (response );
2275+ }
2276+ json_add_string (response , "version" , version ());
2277+ json_add_num (response , "blockheight" , cmd -> ld -> blockheight );
2278+ json_add_string (response , "network" , chainparams -> network_name );
2279+ json_add_amount_msat_compat (response ,
2280+ wallet_total_forward_fees (cmd -> ld -> wallet ),
2281+ "msatoshi_fees_collected" ,
2282+ "fees_collected_msat" );
2283+ json_add_string (response , "lightning-dir" , cmd -> ld -> config_netdir );
2284+
2285+ if (!cmd -> ld -> topology -> bitcoind -> synced )
2286+ json_add_string (response , "warning_bitcoind_sync" ,
2287+ "Bitcoind is not up-to-date with network." );
2288+ else if (!topology_synced (cmd -> ld -> topology ))
2289+ json_add_string (response , "warning_lightningd_sync" ,
2290+ "Still loading latest blocks from bitcoind." );
2291+
2292+ u8 * * bits = cmd -> ld -> our_features -> bits ;
2293+ json_object_start (response , "our_features" );
2294+ json_add_hex_talarr (response , "init" ,
2295+ featurebits_or (cmd ,
2296+ bits [INIT_FEATURE ],
2297+ bits [GLOBAL_INIT_FEATURE ]));
2298+ json_add_hex_talarr (response , "node" , bits [NODE_ANNOUNCE_FEATURE ]);
2299+ json_add_hex_talarr (response , "channel" , bits [CHANNEL_FEATURE ]);
2300+ json_add_hex_talarr (response , "invoice" , bits [BOLT11_FEATURE ]);
2301+ json_object_end (response );
2302+
2303+ return command_success (cmd , response );
22962304}
22972305
22982306static const struct json_command getinfo_command = {
0 commit comments