@@ -1914,15 +1914,6 @@ static struct listpeers_channel *json_to_listpeers_channel(const tal_t *ctx,
1914
1914
json_get_member (buffer , tok , "spendable_msat" ),
1915
1915
* aliastok = json_get_member (buffer , tok , "alias" );
1916
1916
1917
- if (privtok == NULL || privtok -> type != JSMN_PRIMITIVE ||
1918
- statetok == NULL || statetok -> type != JSMN_STRING ||
1919
- ftxidtok == NULL || ftxidtok -> type != JSMN_STRING ||
1920
- (scidtok != NULL && scidtok -> type != JSMN_STRING ) ||
1921
- (dirtok != NULL && dirtok -> type != JSMN_PRIMITIVE ) ||
1922
- tmsattok == NULL ||
1923
- smsattok == NULL )
1924
- return NULL ;
1925
-
1926
1917
chan = tal (ctx , struct listpeers_channel );
1927
1918
1928
1919
json_to_bool (buffer , privtok , & chan -> private );
@@ -1973,70 +1964,43 @@ static struct listpeers_channel *json_to_listpeers_channel(const tal_t *ctx,
1973
1964
return chan ;
1974
1965
}
1975
1966
1976
- static struct listpeers_peer * json_to_listpeers_peer (const tal_t * ctx ,
1977
- const char * buffer ,
1978
- const jsmntok_t * tok )
1967
+ /* Append channels for this peer */
1968
+ static void json_add_listpeers_peer (struct listpeers_channel * * * chans ,
1969
+ const char * buffer ,
1970
+ const jsmntok_t * tok )
1979
1971
{
1980
- struct listpeers_peer * res ;
1981
1972
size_t i ;
1982
1973
const jsmntok_t * iter ;
1983
1974
const jsmntok_t * idtok = json_get_member (buffer , tok , "id" ),
1984
1975
* conntok = json_get_member (buffer , tok , "connected" ),
1985
- * netaddrtok = json_get_member (buffer , tok , "netaddr" ),
1986
1976
* channelstok = json_get_member (buffer , tok , "channels" );
1977
+ bool connected ;
1978
+ struct node_id id ;
1987
1979
1988
- /* Preliminary sanity checks. */
1989
- if (idtok == NULL || idtok -> type != JSMN_STRING || conntok == NULL ||
1990
- conntok -> type != JSMN_PRIMITIVE ||
1991
- (netaddrtok != NULL && netaddrtok -> type != JSMN_ARRAY ) ||
1992
- channelstok == NULL || channelstok -> type != JSMN_ARRAY )
1993
- return NULL ;
1994
-
1995
- res = tal (ctx , struct listpeers_peer );
1996
- json_to_node_id (buffer , idtok , & res -> id );
1997
- json_to_bool (buffer , conntok , & res -> connected );
1980
+ json_to_node_id (buffer , idtok , & id );
1981
+ json_to_bool (buffer , conntok , & connected );
1998
1982
1999
- res -> netaddr = tal_arr (res , const char * , 0 );
2000
- if (netaddrtok != NULL ) {
2001
- json_for_each_arr (i , iter , netaddrtok ) {
2002
- tal_arr_expand (& res -> netaddr ,
2003
- json_strdup (res , buffer , iter ));
2004
- }
2005
- }
2006
-
2007
- res -> channels = tal_arr (res , struct listpeers_channel * , 0 );
2008
1983
json_for_each_arr (i , iter , channelstok ) {
2009
- struct listpeers_channel * chan = json_to_listpeers_channel (res , buffer , iter );
2010
- assert (chan != NULL );
2011
- tal_arr_expand (& res -> channels , chan );
1984
+ struct listpeers_channel * chan = json_to_listpeers_channel (* chans , buffer , iter );
1985
+ chan -> id = id ;
1986
+ chan -> connected = connected ;
1987
+ tal_arr_expand (chans , chan );
2012
1988
}
2013
-
2014
- return res ;
2015
1989
}
2016
1990
2017
- struct listpeers_result * json_to_listpeers_result (const tal_t * ctx ,
2018
- const char * buffer ,
2019
- const jsmntok_t * toks )
1991
+ struct listpeers_channel * * json_to_listpeers_channels (const tal_t * ctx ,
1992
+ const char * buffer ,
1993
+ const jsmntok_t * tok )
2020
1994
{
2021
1995
size_t i ;
2022
1996
const jsmntok_t * iter ;
2023
- struct listpeers_result * res ;
2024
- const jsmntok_t * peerstok = json_get_member (buffer , toks , "peers" );
2025
-
2026
- if (peerstok == NULL || peerstok -> type != JSMN_ARRAY )
2027
- return NULL ;
2028
-
2029
- res = tal (ctx , struct listpeers_result );
2030
- res -> peers = tal_arr (res , struct listpeers_peer * , 0 );
1997
+ const jsmntok_t * peerstok = json_get_member (buffer , tok , "peers" );
1998
+ struct listpeers_channel * * chans ;
2031
1999
2032
- json_for_each_obj (i , iter , peerstok ) {
2033
- struct listpeers_peer * p =
2034
- json_to_listpeers_peer (res , buffer , iter );
2035
- if (p == NULL )
2036
- return tal_free (res );
2037
- tal_arr_expand (& res -> peers , p );
2038
- }
2039
- return res ;
2000
+ chans = tal_arr (ctx , struct listpeers_channel * , 0 );
2001
+ json_for_each_obj (i , iter , peerstok )
2002
+ json_add_listpeers_peer (& chans , buffer , iter );
2003
+ return chans ;
2040
2004
}
2041
2005
2042
2006
struct createonion_response * json_to_createonion_response (const tal_t * ctx ,
0 commit comments