Return tal_arr of htlc indexes. */
| 2482 | |
| 2483 | /* Return tal_arr of htlc indexes. */ |
| 2484 | static const size_t *match_htlc_output(const tal_t *ctx, |
| 2485 | const struct wally_tx_output *out, |
| 2486 | u8 **htlc_scripts) |
| 2487 | { |
| 2488 | size_t *matches = tal_arr(ctx, size_t, 0); |
| 2489 | const u8 *script = tal_dup_arr(tmpctx, u8, out->script, out->script_len, |
| 2490 | 0); |
| 2491 | /* Must be a p2wsh output */ |
| 2492 | if (!is_p2wsh(script, NULL)) |
| 2493 | return matches; |
| 2494 | |
| 2495 | for (size_t i = 0; i < tal_count(htlc_scripts); i++) { |
| 2496 | struct sha256 sha; |
| 2497 | if (!htlc_scripts[i]) |
| 2498 | continue; |
| 2499 | |
| 2500 | sha256(&sha, htlc_scripts[i], tal_count(htlc_scripts[i])); |
| 2501 | if (memeq(script + 2, tal_count(script) - 2, &sha, sizeof(sha))) |
| 2502 | tal_arr_expand(&matches, i); |
| 2503 | } |
| 2504 | return matches; |
| 2505 | } |
| 2506 | |
| 2507 | /* They must all be in the same direction, since the scripts are different for |
| 2508 | * each dir. Unless, of course, they've found a sha256 clash. */ |
no test coverage detected