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