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

Function parse_witness_stack

common/psbt_internal.c:39–68  ·  view source on GitHub ↗

If @elements is non-NULL it must hold at least as many slots as the * stack claims. A failure may have written a prefix; ignore it. */

Source from the content-addressed store, hash-verified

37/* If @elements is non-NULL it must hold at least as many slots as the
38 * stack claims. A failure may have written a prefix; ignore it. */
39static bool parse_witness_stack(const u8 *witness, size_t *num_items,
40 struct witness_element *elements)
41{
42 const u8 *cursor = witness;
43 size_t max = tal_bytelen(witness);
44 size_t n, item_len;
45
46 if (!next_size(&cursor, &max, &n))
47 return false;
48
49 for (size_t i = 0; i < n; i++) {
50 if (!next_size(&cursor, &max, &item_len))
51 return false;
52 if (max < item_len)
53 return false;
54 if (elements) {
55 elements[i].data = cursor;
56 elements[i].len = item_len;
57 }
58 cursor += item_len;
59 max -= item_len;
60 }
61
62 /* Encoding ends here; anything left is not a witness. */
63 if (max != 0)
64 return false;
65
66 *num_items = n;
67 return true;
68}
69
70bool witness_stack_items(const u8 *witness, size_t *num_items)
71{

Callers 2

witness_stack_itemsFunction · 0.85
witness_stack_elementsFunction · 0.85

Calls 2

tal_bytelenFunction · 0.85
next_sizeFunction · 0.85

Tested by

no test coverage detected