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

Function tal_sendpay_result_from_json

plugins/libplugin-pay.c:1052–1184  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1050}
1051
1052static struct payment_result *tal_sendpay_result_from_json(const tal_t *ctx,
1053 const char *buffer,
1054 const jsmntok_t *toks)
1055{
1056 const jsmntok_t *idtok = json_get_member(buffer, toks, "id");
1057 const jsmntok_t *hashtok = json_get_member(buffer, toks, "payment_hash");
1058 const jsmntok_t *partidtok = json_get_member(buffer, toks, "partid");
1059 const jsmntok_t *senttok = json_get_member(buffer, toks, "amount_sent_msat");
1060 const jsmntok_t *statustok = json_get_member(buffer, toks, "status");
1061 const jsmntok_t *preimagetok = json_get_member(buffer, toks, "payment_preimage");
1062 const jsmntok_t *codetok = json_get_member(buffer, toks, "code");
1063 const jsmntok_t *datatok = json_get_member(buffer, toks, "data");
1064 const jsmntok_t *erridxtok, *msgtok, *failcodetok, *rawmsgtok,
1065 *failcodenametok, *errchantok, *errnodetok, *errdirtok;
1066 struct payment_result *result;
1067
1068 /* Check if we have an error and need to descend into data to get
1069 * details. */
1070 if (codetok != NULL && datatok != NULL) {
1071 idtok = json_get_member(buffer, datatok, "id");
1072 hashtok = json_get_member(buffer, datatok, "payment_hash");
1073 partidtok = json_get_member(buffer, datatok, "partid");
1074 senttok = json_get_member(buffer, datatok, "amount_sent_msat");
1075 statustok = json_get_member(buffer, datatok, "status");
1076 }
1077
1078 /* Initial sanity checks, all these fields must exist. */
1079 if (idtok == NULL || idtok->type != JSMN_PRIMITIVE ||
1080 hashtok == NULL || hashtok->type != JSMN_STRING ||
1081 senttok == NULL ||
1082 statustok == NULL || statustok->type != JSMN_STRING) {
1083 return NULL;
1084 }
1085
1086 result = tal(ctx, struct payment_result);
1087
1088 if (codetok != NULL)
1089 json_to_u32(buffer, codetok, &result->code);
1090 else
1091 result->code = 0;
1092
1093 /* If the partid is 0 it'd be omitted in waitsendpay, fix this here. */
1094 if (partidtok != NULL)
1095 json_to_u32(buffer, partidtok, &result->partid);
1096 else
1097 result->partid = 0;
1098
1099 json_to_u64(buffer, idtok, &result->id);
1100 json_to_msat(buffer, senttok, &result->amount_sent);
1101 if (json_tok_streq(buffer, statustok, "pending")) {
1102 result->state = PAYMENT_PENDING;
1103 } else if (json_tok_streq(buffer, statustok, "complete")) {
1104 result->state = PAYMENT_COMPLETE;
1105 } else if (json_tok_streq(buffer, statustok, "failed")) {
1106 result->state = PAYMENT_FAILED;
1107 } else {
1108 goto fail;
1109 }

Callers 1

Calls 12

json_get_memberFunction · 0.85
json_tok_streqFunction · 0.85
json_to_preimageFunction · 0.85
json_to_intFunction · 0.85
tal_freeFunction · 0.85
json_to_u32Function · 0.50
json_to_u64Function · 0.50
json_to_msatFunction · 0.50
json_tok_bin_from_hexFunction · 0.50
json_strdupFunction · 0.50
json_to_node_idFunction · 0.50
json_to_short_channel_idFunction · 0.50

Tested by

no test coverage detected