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

Function tal_sendpay_result_from_json

plugins/renepay/json.c:169–251  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

167}
168
169struct payment_result *tal_sendpay_result_from_json(const tal_t *ctx,
170 const char *buffer,
171 const jsmntok_t *toks,
172 struct secret *shared_secrets)
173{
174 const jsmntok_t *idtok = json_get_member(buffer, toks, "created_index");
175 const jsmntok_t *hashtok =
176 json_get_member(buffer, toks, "payment_hash");
177 const jsmntok_t *senttok =
178 json_get_member(buffer, toks, "amount_sent_msat");
179 const jsmntok_t *statustok = json_get_member(buffer, toks, "status");
180 const jsmntok_t *preimagetok =
181 json_get_member(buffer, toks, "payment_preimage");
182 const jsmntok_t *codetok = json_get_member(buffer, toks, "code");
183 const jsmntok_t *msgtok = json_get_member(buffer, toks, "message");
184 const jsmntok_t *datatok = json_get_member(buffer, toks, "data");
185 struct payment_result *result;
186
187 /* Check if we have an error and need to descend into data to get
188 * details. */
189 if (codetok != NULL && datatok != NULL) {
190 idtok = json_get_member(buffer, datatok, "create_index");
191 hashtok = json_get_member(buffer, datatok, "payment_hash");
192 senttok = json_get_member(buffer, datatok, "amount_sent_msat");
193 statustok = json_get_member(buffer, datatok, "status");
194 }
195
196 /* Initial sanity checks, all these fields must exist. */
197 if (hashtok == NULL || hashtok->type != JSMN_STRING ||
198 senttok == NULL || statustok == NULL ||
199 statustok->type != JSMN_STRING) {
200 return NULL;
201 }
202
203 result = tal(ctx, struct payment_result);
204 memset(result, 0, sizeof(struct payment_result));
205
206 if (msgtok)
207 result->message = json_strdup(result, buffer, msgtok);
208 else
209 result->message = NULL;
210
211 if (codetok != NULL)
212 // u32? isn't this an int?
213 // json_to_u32(buffer, codetok, &result->code);
214 json_to_int(buffer, codetok, &result->code);
215 else
216 result->code = 0;
217
218 if (idtok) {
219 result->created_index = tal(result, u64);
220 json_to_u64(buffer, idtok, result->created_index);
221 } else
222 result->created_index = NULL;
223
224 json_to_msat(buffer, senttok, &result->amount_sent);
225 if (json_tok_streq(buffer, statustok, "pending")) {
226 result->status = SENDPAY_PENDING;

Callers 2

Calls 10

json_get_memberFunction · 0.85
json_to_intFunction · 0.85
json_tok_streqFunction · 0.85
json_to_preimageFunction · 0.85
get_data_detailsFunction · 0.85
tal_freeFunction · 0.85
json_strdupFunction · 0.50
json_to_u64Function · 0.50
json_to_msatFunction · 0.50

Tested by

no test coverage detected