Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
251input_xonly_pubkeys.append(pubkey.hex())252pubkey_index += 1253# len(pubkey) == 0, it's a NUMS_H input - skip without incrementing255out += f" /* ----- {test_vector['comment']} ({test_i + 1}) ----- */\n"256out += " {\n"258outpoint_L = smallest_outpoint(outpoints).hex()259out += gen_key_material(input_plain_seckeys, "input plain seckeys", prepend_count=True)260out += gen_key_material(input_plain_pubkeys, "input plain pubkeys")261out += gen_key_material(input_taproot_seckeys, "input taproot seckeys", prepend_count=True)262out += gen_key_material(input_xonly_pubkeys, "input x-only pubkeys")263out += " /* smallest outpoint */\n"264out += f" {gen_byte_array(outpoint_L)},\n"266# emit recipient pubkeys (address data)267out += gen_recipient_addr_material(test_vector['sending'][0]['given']['recipients'])268# emit recipient outputs269out += gen_sending_outputs(test_vector['sending'][0]['expected']['outputs'], "recipient outputs", prepend_count=True)271assert len(test_vector['receiving']) <= MAX_RECEIVE_SUBTESTS272out += f" {len(test_vector['receiving'])}, /* number of receive subtests */\n"273out += " {\n"274for recv_test in test_vector['receiving']:275out += " {\n"276# emit recipient scan/spend seckeys277recv_test_given = recv_test['given']278recv_test_expected = recv_test['expected']279out += " /* recipient data (scan and spend seckeys) */\n"280out += f" {gen_byte_array(recv_test_given['key_material']['scan_priv_key'])},\n"281out += f" {gen_byte_array(recv_test_given['key_material']['spend_priv_key'])},\n"283# emit recipient to-scan outputs, labels and expected-found outputs284out += gen_outputs(recv_test_given['outputs'], "outputs to scan", prepend_count=True)285out += gen_labels(recv_test_given['labels'])286full_check = 'outputs' in recv_test_expected287out += f" {int(full_check)}, /* full check? */\n"288if full_check:289expected_pubkeys = [o['pub_key'] for o in recv_test_expected['outputs']]290expected_tweaks = [o['priv_key_tweak'] for o in recv_test_expected['outputs']]291expected_signatures = [o['signature'] for o in recv_test_expected['outputs']]292out += " /* expected output data (pubkeys and seckey tweaks) */\n"293else:294expected_pubkeys = []295expected_tweaks = []296expected_signatures = []297out += " /* expected number of outputs */\n"298out += f" {recv_test_expected['n_outputs']},\n"300out += gen_outputs(expected_pubkeys, prepend_count=full_check)301out += gen_outputs(expected_tweaks)302out += gen_outputs(expected_signatures)303out += " },\n"304for _ in range(len(test_vector['receiving']), MAX_RECEIVE_SUBTESTS):305out += ' { "", "", 0, {"",}, 0, {0,}, 0, 0, {"",}, {"",}, {"",} }, /* unused receive subtest entry */\n'306out += " },\n"307out += " },\n\n"308out += "};\n"309return out311def main():312if len(sys.argv) != 2:313print(__doc__)314sys.exit(1)316filename_input = sys.argv[1]317with open(filename_input) as f:318test_vectors = json.load(f)320print(gen_preamble(test_vectors))321print(gen_test_vectors(test_vectors), end="")323if __name__ == "__main__":324main()
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.