| 64 | } |
| 65 | |
| 66 | u8 *onion_final_hop(const tal_t *ctx, |
| 67 | struct amount_msat forward, |
| 68 | u32 outgoing_cltv, |
| 69 | struct amount_msat total_msat, |
| 70 | const struct pubkey *blinding, |
| 71 | const u8 *enctlv, |
| 72 | const struct secret *payment_secret, |
| 73 | const u8 *payment_metadata) |
| 74 | { |
| 75 | struct tlv_tlv_payload *tlv = tlv_tlv_payload_new(tmpctx); |
| 76 | struct tlv_tlv_payload_payment_data tlv_pdata; |
| 77 | |
| 78 | /* These go together! */ |
| 79 | if (!payment_secret) |
| 80 | assert(amount_msat_eq(total_msat, forward)); |
| 81 | |
| 82 | /* BOLT #4: |
| 83 | * |
| 84 | * The writer: |
| 85 | *... |
| 86 | * - For every node: |
| 87 | * - MUST include `amt_to_forward` and `outgoing_cltv_value`. |
| 88 | *... |
| 89 | * - For the final node: |
| 90 | * - MUST NOT include `short_channel_id` |
| 91 | * - if the recipient provided `payment_secret`: |
| 92 | * - MUST include `payment_data` |
| 93 | * - MUST set `payment_secret` to the one provided |
| 94 | * - MUST set `total_msat` to the total amount it will send |
| 95 | */ |
| 96 | tlv->amt_to_forward = &forward.millisatoshis; /* Raw: TLV convert */ |
| 97 | tlv->outgoing_cltv_value = &outgoing_cltv; |
| 98 | |
| 99 | if (payment_secret) { |
| 100 | tlv_pdata.payment_secret = *payment_secret; |
| 101 | tlv_pdata.total_msat = total_msat.millisatoshis; /* Raw: TLV convert */ |
| 102 | tlv->payment_data = &tlv_pdata; |
| 103 | } |
| 104 | tlv->payment_metadata = cast_const(u8 *, payment_metadata); |
| 105 | tlv->blinding_point = cast_const(struct pubkey *, blinding); |
| 106 | tlv->encrypted_recipient_data = cast_const(u8 *, enctlv); |
| 107 | return make_tlv_hop(ctx, tlv); |
| 108 | } |
| 109 | |
| 110 | struct onion_payload *onion_decode(const tal_t *ctx, |
| 111 | const struct route_step *rs, |
no test coverage detected