| 36 | } |
| 37 | |
| 38 | static void json_add_invoice_fields(struct json_stream *response, |
| 39 | const struct invoice_details *inv) |
| 40 | { |
| 41 | json_add_escaped_string(response, "label", inv->label); |
| 42 | if (inv->invstring) |
| 43 | json_add_invstring(response, inv->invstring); |
| 44 | json_add_sha256(response, "payment_hash", &inv->rhash); |
| 45 | if (inv->msat) |
| 46 | json_add_amount_msat_compat(response, *inv->msat, |
| 47 | "msatoshi", "amount_msat"); |
| 48 | json_add_string(response, "status", invoice_status_str(inv)); |
| 49 | if (inv->state == PAID) { |
| 50 | json_add_u64(response, "pay_index", inv->pay_index); |
| 51 | json_add_amount_msat_compat(response, inv->received, |
| 52 | "msatoshi_received", |
| 53 | "amount_received_msat"); |
| 54 | json_add_u64(response, "paid_at", inv->paid_timestamp); |
| 55 | json_add_preimage(response, "payment_preimage", &inv->r); |
| 56 | } |
| 57 | if (inv->description) |
| 58 | json_add_string(response, "description", inv->description); |
| 59 | |
| 60 | json_add_u64(response, "expires_at", inv->expiry_time); |
| 61 | if (inv->local_offer_id) { |
| 62 | char *fail; |
| 63 | struct tlv_invoice *tinv; |
| 64 | |
| 65 | json_add_sha256(response, "local_offer_id", inv->local_offer_id); |
| 66 | |
| 67 | /* Everyone loves seeing their own payer notes! |
| 68 | * Well: they will. Trust me. */ |
| 69 | tinv = invoice_decode(tmpctx, |
| 70 | inv->invstring, strlen(inv->invstring), |
| 71 | NULL, NULL, &fail); |
| 72 | if (tinv && tinv->payer_note) |
| 73 | json_add_stringn(response, "payer_note", |
| 74 | tinv->payer_note, |
| 75 | tal_bytelen(tinv->payer_note)); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | static void json_add_invoice(struct json_stream *response, |
| 80 | const char *fieldname, |
no test coverage detected