MCPcopy Create free account
hub / github.com/ElementsProject/lightning / match_htlc_output

Function match_htlc_output

onchaind/onchaind.c:2012–2032  ·  view source on GitHub ↗

Return tal_arr of htlc indexes. */

Source from the content-addressed store, hash-verified

2010
2011/* Return tal_arr of htlc indexes. */
2012static 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. */

Callers 3

handle_our_unilateralFunction · 0.85
handle_their_cheatFunction · 0.85
handle_their_unilateralFunction · 0.85

Calls 3

is_p2wshFunction · 0.85
memeqFunction · 0.85
sha256Class · 0.70

Tested by

no test coverage detected