@ -803,7 +803,7 @@ static void json_add_peer(struct lightningd *ld,
json_object_end ( response ) ;
}
static void json_listpeers ( struct command * cmd ,
static struct command_result * json_listpeers ( struct command * cmd ,
const char * buffer ,
const jsmntok_t * obj UNNEEDED ,
const jsmntok_t * params )
@ -817,7 +817,7 @@ static void json_listpeers(struct command *cmd,
p_opt ( " id " , param_pubkey , & specific_id ) ,
p_opt ( " level " , param_loglevel , & ll ) ,
NULL ) )
return ;
return command_param_failed ( ) ;
response = json_stream_success ( cmd ) ;
json_object_start ( response , NULL ) ;
@ -832,7 +832,7 @@ static void json_listpeers(struct command *cmd,
}
json_array_end ( response ) ;
json_object_end ( response ) ;
command_success ( cmd , response ) ;
return command_success ( cmd , response ) ;
}
static const struct json_command listpeers_command = {
@ -891,7 +891,7 @@ command_find_channel(struct command *cmd,
}
}
static void json_close ( struct command * cmd ,
static struct command_result * json_close ( struct command * cmd ,
const char * buffer ,
const jsmntok_t * obj UNNEEDED ,
const jsmntok_t * params )
@ -907,7 +907,7 @@ static void json_close(struct command *cmd,
p_opt_def ( " force " , param_bool , & force , false ) ,
p_opt_def ( " timeout " , param_number , & timeout , 30 ) ,
NULL ) )
return ;
return command_param_failed ( ) ;
peer = peer_from_json ( cmd - > ld , buffer , idtok ) ;
if ( peer )
@ -915,7 +915,7 @@ static void json_close(struct command *cmd,
else {
channel = command_find_channel ( cmd , buffer , idtok ) ;
if ( ! channel )
return ;
return command_its_complicated ( ) ;
}
if ( ! channel & & peer ) {
@ -924,12 +924,10 @@ static void json_close(struct command *cmd,
/* Easy case: peer can simply be forgotten. */
kill_uncommitted_channel ( uc , " close command called " ) ;
command_success ( cmd , null_response ( cmd ) ) ;
return ;
return command_success ( cmd , null_response ( cmd ) ) ;
}
command_fail ( cmd , LIGHTNINGD ,
return command_fail ( cmd , LIGHTNINGD ,
" Peer has no active channel " ) ;
return ;
}
/* Normal case.
@ -941,9 +939,8 @@ static void json_close(struct command *cmd,
channel - > state ! = CHANNELD_AWAITING_LOCKIN & &
channel - > state ! = CHANNELD_SHUTTING_DOWN & &
channel - > state ! = CLOSINGD_SIGEXCHANGE ) {
command_fail ( cmd , LIGHTNINGD , " Channel is in state %s " ,
return command_fail ( cmd , LIGHTNINGD , " Channel is in state %s " ,
channel_state_name ( channel ) ) ;
return ;
}
/* If normal or locking in, transition to shutting down
@ -963,7 +960,7 @@ static void json_close(struct command *cmd,
register_close_command ( cmd - > ld , cmd , channel , * timeout , * force ) ;
/* Wait until close drops down to chain. */
command_still_pending ( cmd ) ;
return command_still_pending ( cmd ) ;
}
static const struct json_command close_command = {
@ -1035,7 +1032,7 @@ void load_channels_from_wallet(struct lightningd *ld)
htlcs_reconnect ( ld , & ld - > htlcs_in , & ld - > htlcs_out ) ;
}
static void json_disconnect ( struct command * cmd ,
static struct command_result * json_disconnect ( struct command * cmd ,
const char * buffer ,
const jsmntok_t * obj UNNEEDED ,
const jsmntok_t * params )
@ -1049,32 +1046,28 @@ static void json_disconnect(struct command *cmd,
p_req ( " id " , param_pubkey , & id ) ,
p_opt_def ( " force " , param_bool , & force , false ) ,
NULL ) )
return ;
return command_param_failed ( ) ;
peer = peer_by_id ( cmd - > ld , id ) ;
if ( ! peer ) {
command_fail ( cmd , LIGHTNINGD , " Peer not connected " ) ;
return ;
return command_fail ( cmd , LIGHTNINGD , " Peer not connected " ) ;
}
channel = peer_active_channel ( peer ) ;
if ( channel ) {
if ( * force ) {
channel_fail_transient ( channel ,
" disconnect command force=true " ) ;
command_success ( cmd , null_response ( cmd ) ) ;
return ;
return command_success ( cmd , null_response ( cmd ) ) ;
}
command_fail ( cmd , LIGHTNINGD , " Peer is in state %s " ,
return command_fail ( cmd , LIGHTNINGD , " Peer is in state %s " ,
channel_state_name ( channel ) ) ;
return ;
}
if ( ! peer - > uncommitted_channel ) {
command_fail ( cmd , LIGHTNINGD , " Peer not connected " ) ;
return ;
return command_fail ( cmd , LIGHTNINGD , " Peer not connected " ) ;
}
kill_uncommitted_channel ( peer - > uncommitted_channel ,
" disconnect command " ) ;
command_success ( cmd , null_response ( cmd ) ) ;
return command_success ( cmd , null_response ( cmd ) ) ;
}
static const struct json_command disconnect_command = {
@ -1084,7 +1077,7 @@ static const struct json_command disconnect_command = {
} ;
AUTODATA ( json_command , & disconnect_command ) ;
static void json_getinfo ( struct command * cmd ,
static struct command_result * json_getinfo ( struct command * cmd ,
const char * buffer ,
const jsmntok_t * obj UNNEEDED ,
const jsmntok_t * params )
@ -1096,7 +1089,7 @@ static void json_getinfo(struct command *cmd,
inactive_channels = 0 , num_peers = 0 ;
if ( ! param ( cmd , buffer , params , NULL ) )
return ;
return command_param_failed ( ) ;
response = json_stream_success ( cmd ) ;
json_object_start ( response , NULL ) ;
@ -1148,7 +1141,7 @@ static void json_getinfo(struct command *cmd,
json_add_u64 ( response , " msatoshi_fees_collected " ,
wallet_total_forward_fees ( cmd - > ld - > wallet ) ) ;
json_object_end ( response ) ;
command_success ( cmd , response ) ;
return command_success ( cmd , response ) ;
}
static const struct json_command getinfo_command = {
@ -1159,7 +1152,7 @@ static const struct json_command getinfo_command = {
AUTODATA ( json_command , & getinfo_command ) ;
# if DEVELOPER
static void json_sign_last_tx ( struct command * cmd ,
static struct command_result * json_sign_last_tx ( struct command * cmd ,
const char * buffer ,
const jsmntok_t * obj UNNEEDED ,
const jsmntok_t * params )
@ -1173,19 +1166,17 @@ static void json_sign_last_tx(struct command *cmd,
if ( ! param ( cmd , buffer , params ,
p_req ( " id " , param_pubkey , & peerid ) ,
NULL ) )
return ;
return command_param_failed ( ) ;
peer = peer_by_id ( cmd - > ld , peerid ) ;
if ( ! peer ) {
command_fail ( cmd , LIGHTNINGD ,
return command_fail ( cmd , LIGHTNINGD ,
" Could not find peer with that id " ) ;
return ;
}
channel = peer_active_channel ( peer ) ;
if ( ! channel ) {
command_fail ( cmd , LIGHTNINGD ,
return command_fail ( cmd , LIGHTNINGD ,
" Could not find active channel " ) ;
return ;
}
response = json_stream_success ( cmd ) ;
@ -1198,7 +1189,7 @@ static void json_sign_last_tx(struct command *cmd,
json_object_start ( response , NULL ) ;
json_add_hex_talarr ( response , " tx " , linear ) ;
json_object_end ( response ) ;
command_success ( cmd , response ) ;
return command_success ( cmd , response ) ;
}
static const struct json_command dev_sign_last_tx = {
@ -1208,7 +1199,7 @@ static const struct json_command dev_sign_last_tx = {
} ;
AUTODATA ( json_command , & dev_sign_last_tx ) ;
static void json_dev_fail ( struct command * cmd ,
static struct command_result * json_dev_fail ( struct command * cmd ,
const char * buffer ,
const jsmntok_t * obj UNNEEDED ,
const jsmntok_t * params )
@ -1220,24 +1211,22 @@ static void json_dev_fail(struct command *cmd,
if ( ! param ( cmd , buffer , params ,
p_req ( " id " , param_pubkey , & peerid ) ,
NULL ) )
return ;
return command_param_failed ( ) ;
peer = peer_by_id ( cmd - > ld , peerid ) ;
if ( ! peer ) {
command_fail ( cmd , LIGHTNINGD ,
return command_fail ( cmd , LIGHTNINGD ,
" Could not find peer with that id " ) ;
return ;
}
channel = peer_active_channel ( peer ) ;
if ( ! channel ) {
command_fail ( cmd , LIGHTNINGD ,
return command_fail ( cmd , LIGHTNINGD ,
" Could not find active channel with peer " ) ;
return ;
}
channel_internal_error ( channel , " Failing due to dev-fail command " ) ;
command_success ( cmd , null_response ( cmd ) ) ;
return command_success ( cmd , null_response ( cmd ) ) ;
}
static const struct json_command dev_fail_command = {
@ -1252,10 +1241,10 @@ static void dev_reenable_commit_finished(struct subd *channeld UNUSED,
const int * fds UNUSED ,
struct command * cmd )
{
command_success ( cmd , null_response ( cmd ) ) ;
was_pending ( command_success ( cmd , null_response ( cmd ) ) ) ;
}
static void json_dev_reenable_commit ( struct command * cmd ,
static struct command_result * json_dev_reenable_commit ( struct command * cmd ,
const char * buffer ,
const jsmntok_t * obj UNNEEDED ,
const jsmntok_t * params )
@ -1268,37 +1257,33 @@ static void json_dev_reenable_commit(struct command *cmd,
if ( ! param ( cmd , buffer , params ,
p_req ( " id " , param_pubkey , & peerid ) ,
NULL ) )
return ;
return command_param_failed ( ) ;
peer = peer_by_id ( cmd - > ld , peerid ) ;
if ( ! peer ) {
command_fail ( cmd , LIGHTNINGD ,
return command_fail ( cmd , LIGHTNINGD ,
" Could not find peer with that id " ) ;
return ;
}
channel = peer_active_channel ( peer ) ;
if ( ! channel ) {
command_fail ( cmd , LIGHTNINGD ,
return command_fail ( cmd , LIGHTNINGD ,
" Peer has no active channel " ) ;
return ;
}
if ( ! channel - > owner ) {
command_fail ( cmd , LIGHTNINGD ,
return command_fail ( cmd , LIGHTNINGD ,
" Peer has no owner " ) ;
return ;
}
if ( ! streq ( channel - > owner - > name , " lightning_channeld " ) ) {
command_fail ( cmd , LIGHTNINGD ,
return command_fail ( cmd , LIGHTNINGD ,
" Peer owned by %s " , channel - > owner - > name ) ;
return ;
}
msg = towire_channel_dev_reenable_commit ( channel ) ;
subd_req ( peer , channel - > owner , take ( msg ) , - 1 , 0 ,
dev_reenable_commit_finished , cmd ) ;
command_still_pending ( cmd ) ;
return command_still_pending ( cmd ) ;
}
static const struct json_command dev_reenable_commit = {
@ -1347,7 +1332,7 @@ static void process_dev_forget_channel(struct bitcoind *bitcoind UNUSED,
command_success ( forget - > cmd , response ) ;
}
static void json_dev_forget_channel ( struct command * cmd ,
static struct command_result * json_dev_forget_channel ( struct command * cmd ,
const char * buffer ,
const jsmntok_t * obj UNNEEDED ,
const jsmntok_t * params )
@ -1365,14 +1350,13 @@ static void json_dev_forget_channel(struct command *cmd,
p_opt ( " short_channel_id " , param_short_channel_id , & scid ) ,
p_opt_def ( " force " , param_bool , & force , false ) ,
NULL ) )
return ;
return command_param_failed ( ) ;
forget - > force = * force ;
peer = peer_by_id ( cmd - > ld , peerid ) ;
if ( ! peer ) {
command_fail ( cmd , LIGHTNINGD ,
return command_fail ( cmd , LIGHTNINGD ,
" Could not find channel with that peer " ) ;
return ;
}
forget - > channel = NULL ;
@ -1384,34 +1368,30 @@ static void json_dev_forget_channel(struct command *cmd,
continue ;
}
if ( forget - > channel ) {
command_fail ( cmd , LIGHTNINGD ,
return command_fail ( cmd , LIGHTNINGD ,
" Multiple channels: "
" please specify short_channel_id " ) ;
return ;
}
forget - > channel = channel ;
}
if ( ! forget - > channel ) {
command_fail ( cmd , LIGHTNINGD ,
return command_fail ( cmd , LIGHTNINGD ,
" No channels matching that short_channel_id " ) ;
return ;
}
if ( channel_has_htlc_out ( forget - > channel ) | |
channel_has_htlc_in ( forget - > channel ) ) {
command_fail ( cmd , LIGHTNINGD ,
return command_fail ( cmd , LIGHTNINGD ,
" This channel has HTLCs attached and it is "
" not safe to forget it. Please use `close` "
" or `dev-fail` instead. " ) ;
return ;
}
bitcoind_gettxout ( cmd - > ld - > topology - > bitcoind ,
& forget - > channel - > funding_txid ,
forget - > channel - > funding_outnum ,
process_dev_forget_channel , forget ) ;
command_still_pending ( cmd ) ;
return command_still_pending ( cmd ) ;
}
static const struct json_command dev_forget_channel_command = {