@ -60,11 +60,11 @@ static void json_add_invoice(struct json_result *response,
static void tell_waiter ( struct command * cmd , const struct invoice * inv )
{
struct json_result * response = new_json_result ( cmd ) ;
struct invoice_details details ;
const struct invoice_details * details ;
wallet_invoice_details ( cmd , cmd - > ld - > wallet , * inv , & details ) ;
json_add_invoice ( response , & details ) ;
if ( details . state = = PAID )
details = wallet_invoice_details ( cmd , cmd - > ld - > wallet , * inv ) ;
json_add_invoice ( response , details ) ;
if ( details - > state = = PAID )
command_success ( cmd , response ) ;
else {
/* FIXME: -2 should be a constant in jsonrpc_errors.h. */
@ -153,7 +153,7 @@ static void json_invoice(struct command *cmd,
const char * buffer , const jsmntok_t * params )
{
struct invoice invoice ;
struct invoice_details details ;
const struct invoice_details * details ;
const jsmntok_t * msatoshi , * label , * desctok , * fallbacks ;
const jsmntok_t * preimagetok ;
u64 * msatoshi_val ;
@ -320,23 +320,23 @@ static void json_invoice(struct command *cmd,
}
/* Get details */
wallet_invoice_details ( cmd , cmd - > ld - > wallet , invoice , & details ) ;
details = wallet_invoice_details ( cmd , cmd - > ld - > wallet , invoice ) ;
json_object_start ( response , NULL ) ;
json_add_hex ( response , " payment_hash " ,
& details . rhash , sizeof ( details . rhash ) ) ;
json_add_u64 ( response , " expires_at " , details . expiry_time ) ;
json_add_string ( response , " bolt11 " , details . bolt11 ) ;
json_add_hex ( response , " payment_hash " , details - > rhash . u . u8 ,
sizeof ( details - > rhash ) ) ;
json_add_u64 ( response , " expires_at " , details - > expiry_time ) ;
json_add_string ( response , " bolt11 " , details - > bolt11 ) ;
json_object_end ( response ) ;
command_success ( cmd , response ) ;
}
static const struct json_command invoice_command = {
" invoice " ,
json_invoice ,
" Create an invoice for {msatoshi} with {label} and {description} with optional {expiry} seconds (default 1 hour) and optional {preimage} (default autogenerated) "
} ;
" invoice " , json_invoice , " Create an invoice for {msatoshi} with {label} "
" and {description} with optional {expiry} seconds "
" (default 1 hour) and optional {preimage} "
" (default autogenerated) " } ;
AUTODATA ( json_command , & invoice_command ) ;
static void json_add_invoices ( struct json_result * response ,
@ -344,23 +344,22 @@ static void json_add_invoices(struct json_result *response,
const struct json_escaped * label )
{
struct invoice_iterator it ;
struct invoice_details details ;
const struct invoice_details * details ;
/* Don't iterate entire db if we're just after one. */
if ( label ) {
struct invoice invoice ;
if ( wallet_invoice_find_by_label ( wallet , & invoice , label ) ) {
wallet_invoice_details ( response , wallet , invoice ,
& details ) ;
json_add_invoice ( response , & details ) ;
details = wallet_invoice_details ( response , wallet , invoice ) ;
json_add_invoice ( response , details ) ;
}
return ;
}
memset ( & it , 0 , sizeof ( it ) ) ;
while ( wallet_invoice_iterate ( wallet , & it ) ) {
wallet_invoice_iterator_deref ( response , wallet , & it , & details ) ;
json_add_invoice ( response , & details ) ;
details = wallet_invoice_iterator_deref ( response , wallet , & it ) ;
json_add_invoice ( response , details ) ;
}
}
@ -408,7 +407,7 @@ static void json_delinvoice(struct command *cmd,
const char * buffer , const jsmntok_t * params )
{
struct invoice i ;
struct invoice_details details ;
const struct invoice_details * details ;
const jsmntok_t * labeltok , * statustok ;
struct json_result * response = new_json_result ( cmd ) ;
const char * status , * actual_status ;
@ -433,13 +432,14 @@ static void json_delinvoice(struct command *cmd,
command_fail ( cmd , LIGHTNINGD , " Unknown invoice " ) ;
return ;
}
wallet_invoice_details ( cmd , cmd - > ld - > wallet , i , & details ) ;
details = wallet_invoice_details ( cmd , cmd - > ld - > wallet , i ) ;
status = tal_strndup ( cmd , buffer + statustok - > start ,
statustok - > end - statustok - > start ) ;
/* This is time-sensitive, so only call once; otherwise error msg
* might not make sense if it changed ! */
actual_status = invoice_status_str ( & details ) ;
actual_status = invoice_status_str ( details ) ;
if ( ! streq ( actual_status , status ) ) {
command_fail ( cmd , LIGHTNINGD , " Invoice status is %s not %s " ,
actual_status , status ) ;
@ -448,7 +448,7 @@ static void json_delinvoice(struct command *cmd,
/* Get invoice details before attempting to delete, as
* otherwise the invoice will be freed . */
json_add_invoice ( response , & details ) ;
json_add_invoice ( response , details ) ;
if ( ! wallet_invoice_delete ( wallet , i ) ) {
log_broken ( cmd - > ld - > log ,
@ -562,7 +562,7 @@ static void json_waitinvoice(struct command *cmd,
const char * buffer , const jsmntok_t * params )
{
struct invoice i ;
struct invoice_details details ;
const struct invoice_details * details ;
struct wallet * wallet = cmd - > ld - > wallet ;
const jsmntok_t * labeltok ;
struct json_escaped * label ;
@ -586,10 +586,10 @@ static void json_waitinvoice(struct command *cmd,
command_fail ( cmd , LIGHTNINGD , " Label not found " ) ;
return ;
}
wallet_invoice_details ( cmd , cmd - > ld - > wallet , i , & details ) ;
details = wallet_invoice_details ( cmd , cmd - > ld - > wallet , i ) ;
/* If paid or expired return immediately */
if ( details . state = = PAID | | details . state = = EXPIRED ) {
if ( details - > state = = PAID | | details - > state = = EXPIRED ) {
tell_waiter ( cmd , & i ) ;
return ;
} else {