Return tal_arr of htlc indexes. */
| 2010 | |
| 2011 | /* Return tal_arr of htlc indexes. */ |
| 2012 | static const size_t *match_htlc_output(const tal_t *ctx, |
| 2013 | const struct wally_tx_output *out, |
| 2014 | u8 **htlc_scripts) |
| 2015 | { |
| 2016 | size_t *matches = tal_arr(ctx, size_t, 0); |
| 2017 | |
| 2018 | /* Must be a p2wsh output */ |
| 2019 | if (!is_p2wsh(out->script, out->script_len, NULL)) |
| 2020 | return matches; |
| 2021 | |
| 2022 | for (size_t i = 0; i < tal_count(htlc_scripts); i++) { |
| 2023 | struct sha256 sha; |
| 2024 | if (!htlc_scripts[i]) |
| 2025 | continue; |
| 2026 | |
| 2027 | sha256(&sha, htlc_scripts[i], tal_count(htlc_scripts[i])); |
| 2028 | if (memeq(out->script + 2, out->script_len - 2, &sha, sizeof(sha))) |
| 2029 | tal_arr_expand(&matches, i); |
| 2030 | } |
| 2031 | return matches; |
| 2032 | } |
| 2033 | |
| 2034 | /* They must all be in the same direction, since the scripts are different for |
| 2035 | * each dir. Unless, of course, they've found a sha256 clash. */ |
no test coverage detected