diff --git a/common/errcode.h b/common/errcode.h index eb4da10c7..9fcf6fbed 100644 --- a/common/errcode.h +++ b/common/errcode.h @@ -5,10 +5,6 @@ #include -typedef s32 errcode_t; - -#define PRIerrcode PRId32 - // Setup errors #define EXITCODE_SUBDAEMON_FAIL 10 #define EXITCODE_PIDFILE_LOCK 11 diff --git a/common/json_command.h b/common/json_command.h index 88cf14aeb..e4a2dbd67 100644 --- a/common/json_command.h +++ b/common/json_command.h @@ -11,7 +11,7 @@ struct command; struct command_result; /* Caller supplied this: param assumes it can call it. */ -struct command_result *command_fail(struct command *cmd, errcode_t code, +struct command_result *command_fail(struct command *cmd, enum jsonrpc_errcode code, const char *fmt, ...) PRINTF_FMT(3, 4) WARN_UNUSED_RESULT RETURNS_NONNULL; diff --git a/common/json_parse.c b/common/json_parse.c index 025968d34..f60160519 100644 --- a/common/json_parse.c +++ b/common/json_parse.c @@ -134,7 +134,8 @@ bool json_to_int(const char *buffer, const jsmntok_t *tok, int *num) return true; } -bool json_to_errcode(const char *buffer, const jsmntok_t *tok, errcode_t *errcode) +bool json_to_jsonrpc_errcode(const char *buffer, const jsmntok_t *tok, + enum jsonrpc_errcode *errcode) { s64 tmp; diff --git a/common/json_parse.h b/common/json_parse.h index bcca914b2..311e3f04b 100644 --- a/common/json_parse.h +++ b/common/json_parse.h @@ -6,6 +6,7 @@ #include /* Simple helpers are here: this file contains heavier ones */ #include +#include struct json_escape; struct json_stream; @@ -49,7 +50,8 @@ bool json_to_millionths(const char *buffer, const jsmntok_t *tok, bool json_to_int(const char *buffer, const jsmntok_t *tok, int *num); /* Extract an error code from this (may be a string, or a number literal) */ -bool json_to_errcode(const char *buffer, const jsmntok_t *tok, errcode_t *errcode); +bool json_to_jsonrpc_errcode(const char *buffer, const jsmntok_t *tok, + enum jsonrpc_errcode *errcode); /* Split a json token into 2 tokens given a splitting character */ bool split_tok(const char *buffer, const jsmntok_t *tok, diff --git a/common/json_stream.c b/common/json_stream.c index 53b374e24..5e9401c62 100644 --- a/common/json_stream.c +++ b/common/json_stream.c @@ -377,10 +377,10 @@ void json_add_tok(struct json_stream *result, const char *fieldname, memcpy(space, json_tok_full(buffer, tok), json_tok_full_len(tok)); } -void json_add_errcode(struct json_stream *result, const char *fieldname, - errcode_t code) +void json_add_jsonrpc_errcode(struct json_stream *result, const char *fieldname, + enum jsonrpc_errcode code) { - json_add_primitive_fmt(result, fieldname, "%" PRIerrcode, code); + json_add_primitive_fmt(result, fieldname, "%i", code); } void json_add_invstring(struct json_stream *result, const char *invstring) diff --git a/common/json_stream.h b/common/json_stream.h index 316da33f4..7b0601e82 100644 --- a/common/json_stream.h +++ b/common/json_stream.h @@ -12,7 +12,7 @@ #include #include #include -#include +#include struct command; struct io_conn; @@ -260,8 +260,8 @@ void json_add_tok(struct json_stream *result, const char *fieldname, const jsmntok_t *tok, const char *buffer); /* Add an error code */ -void json_add_errcode(struct json_stream *result, const char *fieldname, - errcode_t code); +void json_add_jsonrpc_errcode(struct json_stream *result, const char *fieldname, + enum jsonrpc_errcode code); /* Add "bolt11" or "bolt12" field, depending on invstring. */ void json_add_invstring(struct json_stream *result, const char *invstring); diff --git a/common/jsonrpc_errors.h b/common/jsonrpc_errors.h index ebf45c4eb..cb0f1a49c 100644 --- a/common/jsonrpc_errors.h +++ b/common/jsonrpc_errors.h @@ -8,102 +8,104 @@ #include -/* Standard errors defined by JSON-RPC 2.0 standard */ -static const errcode_t JSONRPC2_INVALID_REQUEST = -32600; -static const errcode_t JSONRPC2_METHOD_NOT_FOUND = -32601; -static const errcode_t JSONRPC2_INVALID_PARAMS = -32602; +enum jsonrpc_errcode { + /* Standard errors defined by JSON-RPC 2.0 standard */ + JSONRPC2_INVALID_REQUEST = -32600, + JSONRPC2_METHOD_NOT_FOUND = -32601, + JSONRPC2_INVALID_PARAMS = -32602, -/* Uncategorized error. - * FIXME: This should be replaced in all places - * with a specific error code, and then removed. - */ -static const errcode_t LIGHTNINGD = -1; + /* Uncategorized error. + * FIXME: This should be replaced in all places + * with a specific error code, and then removed. + */ + LIGHTNINGD = -1, -/* Developer error in the parameters to param() call */ -static const errcode_t PARAM_DEV_ERROR = -2; + /* Developer error in the parameters to param() call */ + PARAM_DEV_ERROR = -2, -/* Plugin returned an error */ -static const errcode_t PLUGIN_ERROR = -3; + /* Plugin returned an error */ + PLUGIN_ERROR = -3, -/* Plugin terminated while handling a request. */ -static const errcode_t PLUGIN_TERMINATED = -4; + /* Plugin terminated while handling a request. */ + PLUGIN_TERMINATED = -4, -/* Lightningd is shutting down while handling a request. */ -static const errcode_t LIGHTNINGD_SHUTDOWN = -5; + /* Lightningd is shutting down while handling a request. */ + LIGHTNINGD_SHUTDOWN = -5, -/* Errors from `pay`, `sendpay`, or `waitsendpay` commands */ -static const errcode_t PAY_IN_PROGRESS = 200; -static const errcode_t PAY_RHASH_ALREADY_USED = 201; -static const errcode_t PAY_UNPARSEABLE_ONION = 202; -static const errcode_t PAY_DESTINATION_PERM_FAIL = 203; -static const errcode_t PAY_TRY_OTHER_ROUTE = 204; -static const errcode_t PAY_ROUTE_NOT_FOUND = 205; -static const errcode_t PAY_ROUTE_TOO_EXPENSIVE = 206; -static const errcode_t PAY_INVOICE_EXPIRED = 207; -static const errcode_t PAY_NO_SUCH_PAYMENT = 208; -static const errcode_t PAY_UNSPECIFIED_ERROR = 209; -static const errcode_t PAY_STOPPED_RETRYING = 210; -static const errcode_t PAY_STATUS_UNEXPECTED = 211; -static const errcode_t PAY_OFFER_INVALID = 212; + /* Errors from `pay`, `sendpay`, or `waitsendpay` commands */ + PAY_IN_PROGRESS = 200, + PAY_RHASH_ALREADY_USED = 201, + PAY_UNPARSEABLE_ONION = 202, + PAY_DESTINATION_PERM_FAIL = 203, + PAY_TRY_OTHER_ROUTE = 204, + PAY_ROUTE_NOT_FOUND = 205, + PAY_ROUTE_TOO_EXPENSIVE = 206, + PAY_INVOICE_EXPIRED = 207, + PAY_NO_SUCH_PAYMENT = 208, + PAY_UNSPECIFIED_ERROR = 209, + PAY_STOPPED_RETRYING = 210, + PAY_STATUS_UNEXPECTED = 211, + PAY_OFFER_INVALID = 212, -/* `fundchannel` or `withdraw` errors */ -static const errcode_t FUND_MAX_EXCEEDED = 300; -static const errcode_t FUND_CANNOT_AFFORD = 301; -static const errcode_t FUND_OUTPUT_IS_DUST = 302; -static const errcode_t FUNDING_BROADCAST_FAIL = 303; -static const errcode_t FUNDING_STILL_SYNCING_BITCOIN = 304; -static const errcode_t FUNDING_PEER_NOT_CONNECTED = 305; -static const errcode_t FUNDING_UNKNOWN_PEER = 306; -static const errcode_t FUNDING_NOTHING_TO_CANCEL = 307; -static const errcode_t FUNDING_CANCEL_NOT_SAFE = 308; -static const errcode_t FUNDING_PSBT_INVALID = 309; -static const errcode_t FUNDING_V2_NOT_SUPPORTED = 310; -static const errcode_t FUNDING_UNKNOWN_CHANNEL = 311; -static const errcode_t FUNDING_STATE_INVALID = 312; + /* `fundchannel` or `withdraw` errors */ + FUND_MAX_EXCEEDED = 300, + FUND_CANNOT_AFFORD = 301, + FUND_OUTPUT_IS_DUST = 302, + FUNDING_BROADCAST_FAIL = 303, + FUNDING_STILL_SYNCING_BITCOIN = 304, + FUNDING_PEER_NOT_CONNECTED = 305, + FUNDING_UNKNOWN_PEER = 306, + FUNDING_NOTHING_TO_CANCEL = 307, + FUNDING_CANCEL_NOT_SAFE = 308, + FUNDING_PSBT_INVALID = 309, + FUNDING_V2_NOT_SUPPORTED = 310, + FUNDING_UNKNOWN_CHANNEL = 311, + FUNDING_STATE_INVALID = 312, -/* `connect` errors */ -static const errcode_t CONNECT_NO_KNOWN_ADDRESS = 400; -static const errcode_t CONNECT_ALL_ADDRESSES_FAILED = 401; -static const errcode_t CONNECT_DISCONNECTED_DURING = 402; + /* `connect` errors */ + CONNECT_NO_KNOWN_ADDRESS = 400, + CONNECT_ALL_ADDRESSES_FAILED = 401, + CONNECT_DISCONNECTED_DURING = 402, -/* bitcoin-cli plugin errors */ -#define BCLI_ERROR 400 + /* bitcoin-cli plugin errors */ + BCLI_ERROR = 500, -/* Errors from `invoice` or `delinvoice` commands */ -static const errcode_t INVOICE_LABEL_ALREADY_EXISTS = 900; -static const errcode_t INVOICE_PREIMAGE_ALREADY_EXISTS = 901; -static const errcode_t INVOICE_HINTS_GAVE_NO_ROUTES = 902; -static const errcode_t INVOICE_EXPIRED_DURING_WAIT = 903; -static const errcode_t INVOICE_WAIT_TIMED_OUT = 904; -static const errcode_t INVOICE_NOT_FOUND = 905; -static const errcode_t INVOICE_STATUS_UNEXPECTED = 906; -static const errcode_t INVOICE_OFFER_INACTIVE = 907; -static const errcode_t INVOICE_NO_DESCRIPTION = 908; + /* Errors from `invoice` or `delinvoice` commands */ + INVOICE_LABEL_ALREADY_EXISTS = 900, + INVOICE_PREIMAGE_ALREADY_EXISTS = 901, + INVOICE_HINTS_GAVE_NO_ROUTES = 902, + INVOICE_EXPIRED_DURING_WAIT = 903, + INVOICE_WAIT_TIMED_OUT = 904, + INVOICE_NOT_FOUND = 905, + INVOICE_STATUS_UNEXPECTED = 906, + INVOICE_OFFER_INACTIVE = 907, + INVOICE_NO_DESCRIPTION = 908, -/* Errors from HSM crypto operations. */ -static const errcode_t HSM_ECDH_FAILED = 800; + /* Errors from HSM crypto operations. */ + HSM_ECDH_FAILED = 800, -/* Errors from `offer` commands */ -static const errcode_t OFFER_ALREADY_EXISTS = 1000; -static const errcode_t OFFER_ALREADY_DISABLED = 1001; -static const errcode_t OFFER_EXPIRED = 1002; -static const errcode_t OFFER_ROUTE_NOT_FOUND = 1003; -static const errcode_t OFFER_BAD_INVREQ_REPLY = 1004; -static const errcode_t OFFER_TIMEOUT = 1005; + /* Errors from `offer` commands */ + OFFER_ALREADY_EXISTS = 1000, + OFFER_ALREADY_DISABLED = 1001, + OFFER_EXPIRED = 1002, + OFFER_ROUTE_NOT_FOUND = 1003, + OFFER_BAD_INVREQ_REPLY = 1004, + OFFER_TIMEOUT = 1005, -/* Errors from datastore command */ -static const errcode_t DATASTORE_DEL_DOES_NOT_EXIST = 1200; -static const errcode_t DATASTORE_DEL_WRONG_GENERATION = 1201; -static const errcode_t DATASTORE_UPDATE_ALREADY_EXISTS = 1202; -static const errcode_t DATASTORE_UPDATE_DOES_NOT_EXIST = 1203; -static const errcode_t DATASTORE_UPDATE_WRONG_GENERATION = 1204; -static const errcode_t DATASTORE_UPDATE_HAS_CHILDREN = 1205; -static const errcode_t DATASTORE_UPDATE_NO_CHILDREN = 1206; + /* Errors from datastore command */ + DATASTORE_DEL_DOES_NOT_EXIST = 1200, + DATASTORE_DEL_WRONG_GENERATION = 1201, + DATASTORE_UPDATE_ALREADY_EXISTS = 1202, + DATASTORE_UPDATE_DOES_NOT_EXIST = 1203, + DATASTORE_UPDATE_WRONG_GENERATION = 1204, + DATASTORE_UPDATE_HAS_CHILDREN = 1205, + DATASTORE_UPDATE_NO_CHILDREN = 1206, -/* Errors from signmessage command */ -static const errcode_t SIGNMESSAGE_PUBKEY_NOT_FOUND = 1301; + /* Errors from signmessage command */ + SIGNMESSAGE_PUBKEY_NOT_FOUND = 1301, -/* Errors from wait* commands */ -static const errcode_t WAIT_TIMEOUT = 2000; + /* Errors from wait* commands */ + WAIT_TIMEOUT = 2000, +}; #endif /* LIGHTNING_COMMON_JSONRPC_ERRORS_H */ diff --git a/common/test/run-json_remove.c b/common/test/run-json_remove.c index e859dbcb4..99ae0122a 100644 --- a/common/test/run-json_remove.c +++ b/common/test/run-json_remove.c @@ -42,7 +42,7 @@ struct amount_sat amount_tx_fee(u32 fee_per_kw UNNEEDED, size_t weight UNNEEDED) bool command_check_only(const struct command *cmd UNNEEDED) { fprintf(stderr, "command_check_only called!\n"); abort(); } /* Generated stub for command_fail */ -struct command_result *command_fail(struct command *cmd UNNEEDED, errcode_t code UNNEEDED, +struct command_result *command_fail(struct command *cmd UNNEEDED, enum jsonrpc_errcode code UNNEEDED, const char *fmt UNNEEDED, ...) { fprintf(stderr, "command_fail called!\n"); abort(); } diff --git a/common/test/run-param.c b/common/test/run-param.c index 078708649..bd450aef3 100644 --- a/common/test/run-param.c +++ b/common/test/run-param.c @@ -24,7 +24,7 @@ struct command_result { static struct command_result cmd_failed; struct command_result *command_fail(struct command *cmd, - errcode_t code, const char *fmt, ...) + enum jsonrpc_errcode code, const char *fmt, ...) { failed = true; va_list ap; diff --git a/connectd/connectd.c b/connectd/connectd.c index c57a1646d..a5fa736aa 100644 --- a/connectd/connectd.c +++ b/connectd/connectd.c @@ -614,14 +614,14 @@ struct io_plan *connection_out(struct io_conn *conn, struct connecting *connect) static void connect_failed(struct daemon *daemon, const struct node_id *id, const struct wireaddr_internal *addrhint, - errcode_t errcode, + enum jsonrpc_errcode errcode, const char *errfmt, ...) PRINTF_FMT(5,6); static void connect_failed(struct daemon *daemon, const struct node_id *id, const struct wireaddr_internal *addrhint, - errcode_t errcode, + enum jsonrpc_errcode errcode, const char *errfmt, ...) { u8 *msg; diff --git a/connectd/connectd_wire.csv b/connectd/connectd_wire.csv index 1dc10bb92..8a2ce09c4 100644 --- a/connectd/connectd_wire.csv +++ b/connectd/connectd_wire.csv @@ -54,7 +54,7 @@ msgdata,connectd_connect_to_peer,addrhint,?wireaddr_internal, # Connectd->master: connect failed. msgtype,connectd_connect_failed,2020 msgdata,connectd_connect_failed,id,node_id, -msgdata,connectd_connect_failed,failcode,errcode_t, +msgdata,connectd_connect_failed,failcode,enum jsonrpc_errcode, msgdata,connectd_connect_failed,failreason,wirestring, msgdata,connectd_connect_failed,addrhint,?wireaddr_internal, diff --git a/lightningd/connect_control.c b/lightningd/connect_control.c index 056ef0329..61a6bcca8 100644 --- a/lightningd/connect_control.c +++ b/lightningd/connect_control.c @@ -357,7 +357,7 @@ void try_reconnect(const tal_t *ctx, /* We were trying to connect, but they disconnected. */ static void connect_failed(struct lightningd *ld, const struct node_id *id, - errcode_t errcode, + enum jsonrpc_errcode errcode, const char *errmsg, const struct wireaddr_internal *addrhint) { @@ -390,7 +390,7 @@ void connect_failed_disconnect(struct lightningd *ld, static void handle_connect_failed(struct lightningd *ld, const u8 *msg) { struct node_id id; - errcode_t errcode; + enum jsonrpc_errcode errcode; char *errmsg; struct wireaddr_internal *addrhint; diff --git a/lightningd/jsonrpc.c b/lightningd/jsonrpc.c index a5524b203..fbe74bb1b 100644 --- a/lightningd/jsonrpc.c +++ b/lightningd/jsonrpc.c @@ -475,7 +475,7 @@ struct command_result *command_failed(struct command *cmd, return command_raw_complete(cmd, result); } -struct command_result *command_fail(struct command *cmd, errcode_t code, +struct command_result *command_fail(struct command *cmd, enum jsonrpc_errcode code, const char *fmt, ...) { const char *errmsg; @@ -513,7 +513,7 @@ static void json_command_malformed(struct json_connection *jcon, json_add_string(js, "jsonrpc", "2.0"); json_add_primitive(js, "id", id); json_object_start(js, "error"); - json_add_errcode(js, "code", JSONRPC2_INVALID_REQUEST); + json_add_jsonrpc_errcode(js, "code", JSONRPC2_INVALID_REQUEST); json_add_string(js, "message", error); json_object_end(js); json_object_end(js); @@ -601,7 +601,7 @@ struct json_stream *json_stream_success(struct command *cmd) } struct json_stream *json_stream_fail_nodata(struct command *cmd, - errcode_t code, + enum jsonrpc_errcode code, const char *errmsg) { struct json_stream *js = json_start(cmd); @@ -609,14 +609,14 @@ struct json_stream *json_stream_fail_nodata(struct command *cmd, assert(code); json_object_start(js, "error"); - json_add_errcode(js, "code", code); + json_add_jsonrpc_errcode(js, "code", code); json_add_string(js, "message", errmsg); return js; } struct json_stream *json_stream_fail(struct command *cmd, - errcode_t code, + enum jsonrpc_errcode code, const char *errmsg) { struct json_stream *r = json_stream_fail_nodata(cmd, code, errmsg); @@ -824,11 +824,11 @@ rpc_command_hook_callback(struct rpc_command_hook_payload *p, custom_return = json_get_member(buffer, tok, "error"); if (custom_return) { - errcode_t code; + enum jsonrpc_errcode code; const char *errmsg; - if (!json_to_errcode(buffer, - json_get_member(buffer, custom_return, "code"), - &code)) { + if (!json_to_jsonrpc_errcode(buffer, + json_get_member(buffer, custom_return, "code"), + &code)) { error = "'error' object does not contain a code."; goto log_error_and_skip; } diff --git a/lightningd/jsonrpc.h b/lightningd/jsonrpc.h index 1964f1db4..38bff3cae 100644 --- a/lightningd/jsonrpc.h +++ b/lightningd/jsonrpc.h @@ -103,7 +103,7 @@ struct json_stream *json_stream_success(struct command *cmd); * You need to json_object_end() once you're done! */ struct json_stream *json_stream_fail(struct command *cmd, - errcode_t code, + enum jsonrpc_errcode code, const char *errmsg); /** @@ -115,7 +115,7 @@ struct json_stream *json_stream_fail(struct command *cmd, * This is used by command_fail(), which doesn't add any JSON data. */ struct json_stream *json_stream_fail_nodata(struct command *cmd, - errcode_t code, + enum jsonrpc_errcode code, const char *errmsg); /* These returned values are never NULL. */ diff --git a/lightningd/notification.c b/lightningd/notification.c index 2935094f2..a021a116c 100644 --- a/lightningd/notification.c +++ b/lightningd/notification.c @@ -392,7 +392,7 @@ void notify_sendpay_success(struct lightningd *ld, static void sendpay_failure_notification_serialize(struct json_stream *stream, const struct wallet_payment *payment, - errcode_t pay_errcode, + enum jsonrpc_errcode pay_errcode, const struct onionreply *onionreply, const struct routing_failure *fail, char *errmsg) @@ -401,7 +401,7 @@ static void sendpay_failure_notification_serialize(struct json_stream *stream, /* In line with the format of json error returned * by sendpay_fail(). */ - json_add_errcode(stream, "code", pay_errcode); + json_add_jsonrpc_errcode(stream, "code", pay_errcode); json_add_string(stream, "message", errmsg); json_object_start(stream, "data"); @@ -420,14 +420,14 @@ REGISTER_NOTIFICATION(sendpay_failure, void notify_sendpay_failure(struct lightningd *ld, const struct wallet_payment *payment, - errcode_t pay_errcode, + enum jsonrpc_errcode pay_errcode, const struct onionreply *onionreply, const struct routing_failure *fail, const char *errmsg) { void (*serialize)(struct json_stream *, const struct wallet_payment *, - errcode_t, + enum jsonrpc_errcode, const struct onionreply *, const struct routing_failure *, const char *) = sendpay_failure_notification_gen.serialize; diff --git a/lightningd/notification.h b/lightningd/notification.h index 7b1c624b0..d14df085f 100644 --- a/lightningd/notification.h +++ b/lightningd/notification.h @@ -76,7 +76,7 @@ void notify_sendpay_success(struct lightningd *ld, void notify_sendpay_failure(struct lightningd *ld, const struct wallet_payment *payment, - errcode_t pay_errcode, + enum jsonrpc_errcode pay_errcode, const struct onionreply *onionreply, const struct routing_failure *fail, const char *errmsg); diff --git a/lightningd/pay.c b/lightningd/pay.c index 3966ab531..ec2366802 100644 --- a/lightningd/pay.c +++ b/lightningd/pay.c @@ -205,7 +205,7 @@ json_add_routefail_info(struct json_stream *js, void json_sendpay_fail_fields(struct json_stream *js, const struct wallet_payment *payment, - errcode_t pay_errcode, + enum jsonrpc_errcode pay_errcode, const struct onionreply *onionreply, const struct routing_failure *fail) { @@ -224,7 +224,7 @@ void json_sendpay_fail_fields(struct json_stream *js, fail->msg); } -static const char *sendpay_errmsg_fmt(const tal_t *ctx, errcode_t pay_errcode, +static const char *sendpay_errmsg_fmt(const tal_t *ctx, enum jsonrpc_errcode pay_errcode, const struct routing_failure *fail, const char *details) { @@ -243,7 +243,7 @@ static const char *sendpay_errmsg_fmt(const tal_t *ctx, errcode_t pay_errcode, static struct command_result * sendpay_fail(struct command *cmd, const struct wallet_payment *payment, - errcode_t pay_errcode, + enum jsonrpc_errcode pay_errcode, const struct onionreply *onionreply, const struct routing_failure *fail, const char *errmsg) @@ -276,7 +276,7 @@ json_sendpay_in_progress(struct command *cmd, static void tell_waiters_failed(struct lightningd *ld, const struct sha256 *payment_hash, const struct wallet_payment *payment, - errcode_t pay_errcode, + enum jsonrpc_errcode pay_errcode, const struct onionreply *onionreply, const struct routing_failure *fail, const char *details) @@ -417,7 +417,7 @@ remote_routing_failure(const tal_t *ctx, const u8 *failuremsg, int origin_index, struct log *log, - errcode_t *pay_errcode) + enum jsonrpc_errcode *pay_errcode) { enum onion_wire failcode = fromwire_peektype(failuremsg); struct routing_failure *routing_failure; @@ -541,7 +541,7 @@ void payment_failed(struct lightningd *ld, const struct htlc_out *hout, struct wallet_payment *payment; struct routing_failure* fail = NULL; const char *failstr; - errcode_t pay_errcode; + enum jsonrpc_errcode pay_errcode; const u8 *failmsg; int origin_index; @@ -670,7 +670,7 @@ static struct command_result *wait_payment(struct lightningd *ld, char *faildetail; struct routing_failure *fail; int faildirection; - errcode_t rpcerrorcode; + enum jsonrpc_errcode rpcerrorcode; payment = wallet_payment_by_hash(tmpctx, ld->wallet, payment_hash, partid, groupid); diff --git a/lightningd/pay.h b/lightningd/pay.h index 7c9338774..439a2bd7e 100644 --- a/lightningd/pay.h +++ b/lightningd/pay.h @@ -29,7 +29,7 @@ void json_add_payment_fields(struct json_stream *response, /* This json will be also used in 'sendpay_failure' notifictaion. */ void json_sendpay_fail_fields(struct json_stream *js, const struct wallet_payment *t, - errcode_t pay_errcode, + enum jsonrpc_errcode pay_errcode, const struct onionreply *onionreply, const struct routing_failure *fail); diff --git a/lightningd/test/run-invoice-select-inchan.c b/lightningd/test/run-invoice-select-inchan.c index fcf26cbbf..95b27e1c3 100644 --- a/lightningd/test/run-invoice-select-inchan.c +++ b/lightningd/test/run-invoice-select-inchan.c @@ -124,7 +124,7 @@ void channel_update_reserve(struct channel *channel UNNEEDED, struct amount_sat funding_total UNNEEDED) { fprintf(stderr, "channel_update_reserve called!\n"); abort(); } /* Generated stub for command_fail */ -struct command_result *command_fail(struct command *cmd UNNEEDED, errcode_t code UNNEEDED, +struct command_result *command_fail(struct command *cmd UNNEEDED, enum jsonrpc_errcode code UNNEEDED, const char *fmt UNNEEDED, ...) { fprintf(stderr, "command_fail called!\n"); abort(); } @@ -455,7 +455,7 @@ const char *json_scan(const tal_t *ctx UNNEEDED, { fprintf(stderr, "json_scan called!\n"); abort(); } /* Generated stub for json_stream_fail */ struct json_stream *json_stream_fail(struct command *cmd UNNEEDED, - errcode_t code UNNEEDED, + enum jsonrpc_errcode code UNNEEDED, const char *errmsg UNNEEDED) { fprintf(stderr, "json_stream_fail called!\n"); abort(); } /* Generated stub for json_stream_success */ diff --git a/lightningd/test/run-jsonrpc.c b/lightningd/test/run-jsonrpc.c index 6536ffad8..8a0a3f9b6 100644 --- a/lightningd/test/run-jsonrpc.c +++ b/lightningd/test/run-jsonrpc.c @@ -27,9 +27,10 @@ bool fromwire_channel_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, /* Generated stub for fromwire_node_id */ void fromwire_node_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, struct node_id *id UNNEEDED) { fprintf(stderr, "fromwire_node_id called!\n"); abort(); } -/* Generated stub for json_to_errcode */ -bool json_to_errcode(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED, errcode_t *errcode UNNEEDED) -{ fprintf(stderr, "json_to_errcode called!\n"); abort(); } +/* Generated stub for json_to_jsonrpc_errcode */ +bool json_to_jsonrpc_errcode(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED, + enum jsonrpc_errcode *errcode UNNEEDED) +{ fprintf(stderr, "json_to_jsonrpc_errcode called!\n"); abort(); } /* Generated stub for json_to_number */ bool json_to_number(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED, unsigned int *num UNNEEDED) diff --git a/lightningd/test/run-log-pruning.c b/lightningd/test/run-log-pruning.c index f663a9f26..12d5d1f72 100644 --- a/lightningd/test/run-log-pruning.c +++ b/lightningd/test/run-log-pruning.c @@ -4,7 +4,7 @@ /* AUTOGENERATED MOCKS START */ /* Generated stub for command_fail */ -struct command_result *command_fail(struct command *cmd UNNEEDED, errcode_t code UNNEEDED, +struct command_result *command_fail(struct command *cmd UNNEEDED, enum jsonrpc_errcode code UNNEEDED, const char *fmt UNNEEDED, ...) { fprintf(stderr, "command_fail called!\n"); abort(); } diff --git a/plugins/libplugin.c b/plugins/libplugin.c index c7b03989c..e39a507c1 100644 --- a/plugins/libplugin.c +++ b/plugins/libplugin.c @@ -389,14 +389,14 @@ command_success(struct command *cmd, const struct json_out *result) } struct command_result *command_done_err(struct command *cmd, - errcode_t code, + enum jsonrpc_errcode code, const char *errmsg, const struct json_out *data) { struct json_stream *js = jsonrpc_stream_start(cmd); json_object_start(js, "error"); - json_add_errcode(js, "code", code); + json_add_jsonrpc_errcode(js, "code", code); json_add_string(js, "message", errmsg); if (data) @@ -442,7 +442,7 @@ struct command_result *forward_result(struct command *cmd, /* Called by param() directly if it's malformed. */ struct command_result *command_fail(struct command *cmd, - errcode_t code, const char *fmt, ...) + enum jsonrpc_errcode code, const char *fmt, ...) { va_list ap; struct command_result *res; diff --git a/plugins/libplugin.h b/plugins/libplugin.h index ba7c6b4ab..4131f4567 100644 --- a/plugins/libplugin.h +++ b/plugins/libplugin.h @@ -239,7 +239,7 @@ void NORETURN plugin_exit(struct plugin *p, int exitcode); * NULL, data can be NULL; otherwise it must be a JSON object. */ struct command_result *WARN_UNUSED_RESULT command_done_err(struct command *cmd, - errcode_t code, + enum jsonrpc_errcode code, const char *errmsg, const struct json_out *data); diff --git a/plugins/spender/multifundchannel.c b/plugins/spender/multifundchannel.c index e67baed0e..ffb50b053 100644 --- a/plugins/spender/multifundchannel.c +++ b/plugins/spender/multifundchannel.c @@ -69,7 +69,7 @@ void fail_destination_tok(struct multifundchannel_destination *dest, } void fail_destination_msg(struct multifundchannel_destination *dest, - errcode_t error_code, + enum jsonrpc_errcode error_code, const char *err_str TAKES) { dest->error_code = error_code; @@ -333,7 +333,7 @@ mfc_cleanup_(struct multifundchannel_command *mfc, struct mfc_fail_object { struct multifundchannel_command *mfc; struct command *cmd; - errcode_t code; + enum jsonrpc_errcode code; const char *msg; }; @@ -347,7 +347,7 @@ mfc_fail_complete(struct mfc_fail_object *obj) /* Use this instead of command_fail. */ static struct command_result * -mfc_fail(struct multifundchannel_command *mfc, errcode_t code, +mfc_fail(struct multifundchannel_command *mfc, enum jsonrpc_errcode code, const char *fmt, ...) { struct mfc_fail_object *obj; diff --git a/plugins/spender/multifundchannel.h b/plugins/spender/multifundchannel.h index e65c2785c..f27b378da 100644 --- a/plugins/spender/multifundchannel.h +++ b/plugins/spender/multifundchannel.h @@ -56,7 +56,7 @@ struct multifundchannel_removed { */ const char *method; const char *error_message; - errcode_t error_code; + enum jsonrpc_errcode error_code; /* Optional JSON object containing extra data */ const char *error_data; }; @@ -128,7 +128,7 @@ struct multifundchannel_destination { struct channel_id channel_id; const char *error_message; - errcode_t error_code; + enum jsonrpc_errcode error_code; /* Optional JSON object containing extra data */ const char *error_data; diff --git a/plugins/spender/multiwithdraw.c b/plugins/spender/multiwithdraw.c index 9ab29bb9e..9eb93c30e 100644 --- a/plugins/spender/multiwithdraw.c +++ b/plugins/spender/multiwithdraw.c @@ -288,7 +288,7 @@ mw_forward_error(struct command *cmd UNUSED, } /* Use this instead of command_fail. */ static struct command_result * -mw_fail(struct multiwithdraw_command *mw, errcode_t code, +mw_fail(struct multiwithdraw_command *mw, enum jsonrpc_errcode code, const char *fmt, ...) { va_list ap; @@ -303,7 +303,7 @@ mw_fail(struct multiwithdraw_command *mw, errcode_t code, js = new_json_stream(tmpctx, mw->cmd, NULL); json_object_start(js, NULL); - json_add_errcode(js, "code", code); + json_add_jsonrpc_errcode(js, "code", code); json_add_string(js, "message", message); json_object_end(js); diff --git a/tools/generate-wire.py b/tools/generate-wire.py index 19e658d93..24a2a1370 100755 --- a/tools/generate-wire.py +++ b/tools/generate-wire.py @@ -194,7 +194,6 @@ class Type(FieldSet): 'bool', 'amount_sat', 'amount_msat', - 'errcode_t', 'bigsize', 'varint' ] @@ -209,7 +208,6 @@ class Type(FieldSet): 'secp256k1_ecdsa_recoverable_signature', 'utf8', 'wirestring', - 'errcode_t', 'bigsize', 'varint', ] diff --git a/wallet/test/run-wallet.c b/wallet/test/run-wallet.c index 58d870a50..090e371ba 100644 --- a/wallet/test/run-wallet.c +++ b/wallet/test/run-wallet.c @@ -90,7 +90,7 @@ void channel_update_reserve(struct channel *channel UNNEEDED, struct amount_sat funding_total UNNEEDED) { fprintf(stderr, "channel_update_reserve called!\n"); abort(); } /* Generated stub for command_fail */ -struct command_result *command_fail(struct command *cmd UNNEEDED, errcode_t code UNNEEDED, +struct command_result *command_fail(struct command *cmd UNNEEDED, enum jsonrpc_errcode code UNNEEDED, const char *fmt UNNEEDED, ...) { fprintf(stderr, "command_fail called!\n"); abort(); } diff --git a/wire/fromwire.c b/wire/fromwire.c index e960f6e8e..97909534d 100644 --- a/wire/fromwire.c +++ b/wire/fromwire.c @@ -151,9 +151,9 @@ bool fromwire_bool(const u8 **cursor, size_t *max) return ret; } -errcode_t fromwire_errcode_t(const u8 **cursor, size_t *max) +enum jsonrpc_errcode fromwire_jsonrpc_errcode(const u8 **cursor, size_t *max) { - errcode_t ret; + enum jsonrpc_errcode ret; ret = (s32)fromwire_u32(cursor, max); diff --git a/wire/towire.c b/wire/towire.c index c4bfc6447..49eae1523 100644 --- a/wire/towire.c +++ b/wire/towire.c @@ -77,7 +77,7 @@ void towire_bool(u8 **pptr, bool v) towire(pptr, &val, sizeof(val)); } -void towire_errcode_t(u8 **pptr, errcode_t v) +void towire_jsonrpc_errcode(u8 **pptr, enum jsonrpc_errcode v) { towire_u32(pptr, (u32)v); } diff --git a/wire/wire.h b/wire/wire.h index 1b3d6502e..3b07a021b 100644 --- a/wire/wire.h +++ b/wire/wire.h @@ -3,7 +3,7 @@ #include "config.h" #include #include -#include +#include #include #include #include @@ -36,7 +36,7 @@ void towire_tu32(u8 **pptr, u32 v); void towire_tu64(u8 **pptr, u64 v); void towire_pad(u8 **pptr, size_t num); void towire_bool(u8 **pptr, bool v); -void towire_errcode_t(u8 **pptr, errcode_t v); +void towire_jsonrpc_errcode(u8 **pptr, enum jsonrpc_errcode v); void towire_u8_array(u8 **pptr, const u8 *arr, size_t num); void towire_utf8_array(u8 **pptr, const char *arr, size_t num); @@ -53,7 +53,7 @@ u16 fromwire_tu16(const u8 **cursor, size_t *max); u32 fromwire_tu32(const u8 **cursor, size_t *max); u64 fromwire_tu64(const u8 **cursor, size_t *max); bool fromwire_bool(const u8 **cursor, size_t *max); -errcode_t fromwire_errcode_t(const u8 **cursor, size_t *max); +enum jsonrpc_errcode fromwire_jsonrpc_errcode(const u8 **cursor, size_t *max); void fromwire_secp256k1_ecdsa_signature(const u8 **cursor, size_t *max, secp256k1_ecdsa_signature *signature); void fromwire_secp256k1_ecdsa_recoverable_signature(const u8 **cursor,