| 63 | } |
| 64 | |
| 65 | static struct command_result *keysend_cb(struct keysend_data *d, struct payment *p) { |
| 66 | struct createonion_hop *last_payload; |
| 67 | size_t hopcount; |
| 68 | |
| 69 | /* On the root payment we perform the featurebit check. */ |
| 70 | if (p->step == PAYMENT_STEP_FAILED) { |
| 71 | /* Now we can look at the error, and the failing node, |
| 72 | and determine whether they didn't like our |
| 73 | attempt. This is required since most nodes don't |
| 74 | explicitly signal support for keysend through the |
| 75 | featurebit method.*/ |
| 76 | |
| 77 | if (p->result != NULL && |
| 78 | node_id_eq(p->route_destination, p->result->erring_node) && |
| 79 | p->result->failcode == WIRE_INVALID_ONION_PAYLOAD) { |
| 80 | return payment_abort( |
| 81 | p, |
| 82 | PAY_DESTINATION_PERM_FAIL, |
| 83 | "Recipient %s reported an invalid payload, this " |
| 84 | "usually means they don't support keysend.", |
| 85 | fmt_node_id(tmpctx, p->route_destination)); |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | if (p->step != PAYMENT_STEP_ONION_PAYLOAD) |
| 90 | return payment_continue(p); |
| 91 | |
| 92 | hopcount = tal_count(p->createonion_request->hops); |
| 93 | last_payload = &p->createonion_request->hops[hopcount - 1]; |
| 94 | tlvstream_set_raw(&last_payload->tlv_payload->fields, PREIMAGE_TLV_TYPE, |
| 95 | &d->preimage, sizeof(struct preimage)); |
| 96 | |
| 97 | if (d->extra_tlvs != NULL) { |
| 98 | for (size_t i = 0; i < tal_count(d->extra_tlvs); i++) { |
| 99 | struct tlv_field *f = &d->extra_tlvs[i]; |
| 100 | tlvstream_set_raw(&last_payload->tlv_payload->fields, |
| 101 | f->numtype, f->value, f->length); |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | return payment_continue(p); |
| 106 | } |
| 107 | |
| 108 | REGISTER_PAYMENT_MODIFIER(keysend, struct keysend_data *, keysend_init, |
| 109 | keysend_cb); |
nothing calls this directly
no test coverage detected