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

Function match_htlc_output

onchaind/onchaind.c:2484–2505  ·  view source on GitHub ↗

Return tal_arr of htlc indexes. */

Source from the content-addressed store, hash-verified

2482
2483/* Return tal_arr of htlc indexes. */
2484static 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. */

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