| 899 | } |
| 900 | |
| 901 | static struct payment_result *tal_sendpay_result_from_json(const tal_t *ctx, |
| 902 | const char *buffer, |
| 903 | const jsmntok_t *toks) |
| 904 | { |
| 905 | const jsmntok_t *idtok = json_get_member(buffer, toks, "id"); |
| 906 | const jsmntok_t *hashtok = json_get_member(buffer, toks, "payment_hash"); |
| 907 | const jsmntok_t *partidtok = json_get_member(buffer, toks, "partid"); |
| 908 | const jsmntok_t *senttok = json_get_member(buffer, toks, "amount_sent_msat"); |
| 909 | const jsmntok_t *statustok = json_get_member(buffer, toks, "status"); |
| 910 | const jsmntok_t *preimagetok = json_get_member(buffer, toks, "payment_preimage"); |
| 911 | const jsmntok_t *codetok = json_get_member(buffer, toks, "code"); |
| 912 | const jsmntok_t *datatok = json_get_member(buffer, toks, "data"); |
| 913 | const jsmntok_t *erridxtok, *msgtok, *failcodetok, *rawmsgtok, |
| 914 | *failcodenametok, *errchantok, *errnodetok, *errdirtok; |
| 915 | struct payment_result *result; |
| 916 | |
| 917 | /* Check if we have an error and need to descend into data to get |
| 918 | * details. */ |
| 919 | if (codetok != NULL && datatok != NULL) { |
| 920 | idtok = json_get_member(buffer, datatok, "id"); |
| 921 | hashtok = json_get_member(buffer, datatok, "payment_hash"); |
| 922 | partidtok = json_get_member(buffer, datatok, "partid"); |
| 923 | senttok = json_get_member(buffer, datatok, "amount_sent_msat"); |
| 924 | statustok = json_get_member(buffer, datatok, "status"); |
| 925 | } |
| 926 | |
| 927 | /* Initial sanity checks, all these fields must exist. */ |
| 928 | if (idtok == NULL || idtok->type != JSMN_PRIMITIVE || |
| 929 | hashtok == NULL || hashtok->type != JSMN_STRING || |
| 930 | senttok == NULL || |
| 931 | statustok == NULL || statustok->type != JSMN_STRING) { |
| 932 | return NULL; |
| 933 | } |
| 934 | |
| 935 | result = tal(ctx, struct payment_result); |
| 936 | |
| 937 | if (codetok != NULL) |
| 938 | json_to_u32(buffer, codetok, &result->code); |
| 939 | else |
| 940 | result->code = 0; |
| 941 | |
| 942 | /* If the partid is 0 it'd be omitted in waitsendpay, fix this here. */ |
| 943 | if (partidtok != NULL) |
| 944 | json_to_u32(buffer, partidtok, &result->partid); |
| 945 | else |
| 946 | result->partid = 0; |
| 947 | |
| 948 | json_to_u64(buffer, idtok, &result->id); |
| 949 | json_to_msat(buffer, senttok, &result->amount_sent); |
| 950 | if (json_tok_streq(buffer, statustok, "pending")) { |
| 951 | result->state = PAYMENT_PENDING; |
| 952 | } else if (json_tok_streq(buffer, statustok, "complete")) { |
| 953 | result->state = PAYMENT_COMPLETE; |
| 954 | } else if (json_tok_streq(buffer, statustok, "failed")) { |
| 955 | result->state = PAYMENT_FAILED; |
| 956 | } else { |
| 957 | goto fail; |
| 958 | } |
no test coverage detected