MCPcopy Create free account
hub / github.com/ElementsProject/lightning / handle_error

Function handle_error

plugins/fetchinvoice.c:99–156  ·  view source on GitHub ↗

Returns NULL if it wasn't an error. */

Source from the content-addressed store, hash-verified

97
98/* Returns NULL if it wasn't an error. */
99static struct command_result *handle_error(struct command *cmd,
100 struct sent *sent,
101 const char *buf,
102 const jsmntok_t *om)
103{
104 const u8 *data;
105 size_t dlen;
106 struct tlv_invoice_error *err;
107 struct json_out *details;
108 const jsmntok_t *errtok;
109
110 errtok = json_get_member(buf, om, "invoice_error");
111 if (!errtok)
112 return NULL;
113
114 data = json_tok_bin_from_hex(cmd, buf, errtok);
115 dlen = tal_bytelen(data);
116 details = json_out_new(cmd);
117
118 plugin_log(cmd->plugin, LOG_DBG, "errtok = %.*s",
119 json_tok_full_len(errtok),
120 json_tok_full(buf, errtok));
121 json_out_start(details, NULL, '{');
122 err = fromwire_tlv_invoice_error(cmd, &data, &dlen);
123 if (!err) {
124 plugin_log(cmd->plugin, LOG_DBG,
125 "Invalid invoice_error %.*s",
126 json_tok_full_len(errtok),
127 json_tok_full(buf, errtok));
128 json_out_addstr(details, "invoice_error_hex",
129 tal_strndup(tmpctx,
130 buf + errtok->start,
131 errtok->end - errtok->start));
132 } else {
133 char *failstr;
134
135 /* FIXME: with a bit more generate-wire.py support,
136 * we could have fieldnames and even types. */
137 if (err->erroneous_field)
138 json_out_add(details, "erroneous_field", false,
139 "%"PRIu64, *err->erroneous_field);
140 if (err->suggested_value)
141 json_out_addstr(details, "suggested_value",
142 tal_hex(tmpctx,
143 err->suggested_value));
144 /* If they don't include this, it'll be empty */
145 failstr = tal_strndup(tmpctx,
146 err->error,
147 tal_bytelen(err->error));
148 json_out_addstr(details, "error", failstr);
149 }
150 json_out_end(details, '}');
151 discard_result(command_done_err(sent->cmd,
152 OFFER_BAD_INVREQ_REPLY,
153 "Remote node sent failure message",
154 details));
155 return command_hook_success(cmd);
156}

Callers 1

Calls 15

tal_bytelenFunction · 0.85
json_out_newFunction · 0.85
json_out_startFunction · 0.85
json_out_addstrFunction · 0.85
json_out_addFunction · 0.85
tal_hexFunction · 0.85
json_out_endFunction · 0.85
discard_resultFunction · 0.85
command_done_errFunction · 0.85
command_hook_successFunction · 0.85
plugin_logFunction · 0.70
json_get_memberFunction · 0.50

Tested by

no test coverage detected