| 755 | } |
| 756 | |
| 757 | static struct command_result * |
| 758 | decrypt_done(struct command *cmd, |
| 759 | const char *method, |
| 760 | const char *buf, |
| 761 | const jsmntok_t *result, |
| 762 | struct payment *p) |
| 763 | { |
| 764 | const char *err; |
| 765 | u8 *encdata; |
| 766 | struct pubkey next_path_key; |
| 767 | struct tlv_encrypted_data_tlv *enctlv; |
| 768 | const u8 *cursor; |
| 769 | size_t maxlen; |
| 770 | |
| 771 | err = json_scan(tmpctx, buf, result, |
| 772 | "{decryptencrypteddata:{decrypted:%" |
| 773 | ",next_path_key:%}}", |
| 774 | JSON_SCAN_TAL(tmpctx, json_tok_bin_from_hex, &encdata), |
| 775 | JSON_SCAN(json_to_pubkey, &next_path_key)); |
| 776 | if (err) { |
| 777 | return command_fail(cmd, LIGHTNINGD, |
| 778 | "Bad decryptencrypteddata response? %.*s: %s", |
| 779 | json_tok_full_len(result), |
| 780 | json_tok_full(buf, result), |
| 781 | err); |
| 782 | } |
| 783 | |
| 784 | cursor = encdata; |
| 785 | maxlen = tal_bytelen(encdata); |
| 786 | enctlv = fromwire_tlv_encrypted_data_tlv(tmpctx, &cursor, &maxlen); |
| 787 | if (!enctlv) { |
| 788 | return command_fail(cmd, PAY_UNPARSEABLE_ONION, |
| 789 | "Invalid TLV for blinded path: %s", |
| 790 | tal_hex(tmpctx, encdata)); |
| 791 | } |
| 792 | |
| 793 | /* Was this a self-pay? Simply remove blinded path. */ |
| 794 | if (tal_count(p->blindedpath->path) == 1) { |
| 795 | p->blindedpath = tal_free(p->blindedpath); |
| 796 | tal_free(p->pay_destination); |
| 797 | p->pay_destination = tal_dup(p, struct node_id, p->route_destination); |
| 798 | /* self-pay will want secret from inside TLV */ |
| 799 | if (tal_bytelen(enctlv->path_id) == sizeof(*p->payment_secret)) { |
| 800 | p->payment_secret = tal(p, struct secret); |
| 801 | memcpy(p->payment_secret, enctlv->path_id, sizeof(struct secret)); |
| 802 | } |
| 803 | return start_payment(cmd, p); |
| 804 | } |
| 805 | |
| 806 | /* Promote second hop to first hop */ |
| 807 | if (enctlv->next_path_key_override) |
| 808 | p->blindedpath->first_path_key = *enctlv->next_path_key_override; |
| 809 | else |
| 810 | p->blindedpath->first_path_key = next_path_key; |
| 811 | |
| 812 | /* Remove now-decrypted part of path */ |
| 813 | tal_free(p->blindedpath->path[0]); |
| 814 | tal_arr_remove(&p->blindedpath->path, 0); |
nothing calls this directly
no test coverage detected