bips icon indicating copy to clipboard operation
bips copied to clipboard

BIP69: examples file fixes and update to python3

Open prestoalvarez opened this issue 4 months ago • 9 comments

In bip-0069_examples.py:

  • Fix print_outputs() to use sorted output tuples instead of unsorted
  • Add Python 3 compatibility using functools.cmp_to_key()
  • Convert string hashes to byte arrays in second example
  • Make file executable with shebang for python3
  • Add clearer output formatting with transaction hashes and section headers

prestoalvarez avatar Aug 22 '25 13:08 prestoalvarez

ACK. Could you please make the commit names clearer, and what do you think about adding this diff to the last commit?

 def print_inputs(ordered_input_tuples):
+       print("inputs")
        index = 0
        for prev_tx_hash_byte_arr_little_endian, prev_tx_output_index in ordered_input_tuples:
                prev_tx_hash_hex = binascii.hexlify(bytearray(prev_tx_hash_byte_arr_little_endian))
@@ -57,6 +58,7 @@ def sort_outputs(output_tuples):
        return sorted(output_tuples, key=cmp_to_key(output_cmp))
 
 def print_outputs(ordered_output_tuples):
+       print("outputs")
        index = 0
        for amount, scriptPubKey_byte_arr in ordered_output_tuples:
                scriptPubKey_hex = binascii.hexlify(bytearray(scriptPubKey_byte_arr))
@@ -84,6 +86,7 @@ def main():
                ([0x7d, 0x03, 0x7c, 0xeb, 0x2e, 0xe0, 0xdc, 0x03, 0xe8, 0x2f, 0x17, 0xbe, 0x79, 0x35, 0xd2, 0x38, 0xb3, 0x5d, 0x1d, 0xea, 0xbf, 0x95, 0x3a, 0x89, 0x2a, 0x45, 0x07, 0xbf, 0xbe, 0xeb, 0x3b, 0xa4], 1),
                ([0x6c, 0x1d, 0x56, 0xf3, 0x1b, 0x2d, 0xe4, 0xbf, 0xc6, 0xaa, 0xea, 0x28, 0x39, 0x6b, 0x33, 0x31, 0x02, 0xb1, 0xf6, 0x00, 0xda, 0x9c, 0x6d, 0x61, 0x49, 0xe9, 0x6c, 0xa4, 0x3f, 0x11, 0x02, 0xb1], 1),
                ([0xb4, 0x11, 0x2b, 0x8f, 0x90, 0x0a, 0x7c, 0xa0, 0xc8, 0xb0, 0xe7, 0xc4, 0xdf, 0xad, 0x35, 0xc6, 0xbe, 0x5f, 0x6b, 0xe4, 0x6b, 0x34, 0x58, 0x97, 0x49, 0x88, 0xe1, 0xcd, 0xb2, 0xfa, 0x61, 0xb8], 0)]
+       print("\ntx 0a6a357e2f7796444e02638749d9611c008b253fb55f5dc88b739b230ed0c4c3")
        tx_0a6a_sorted_input_tuples = sort_inputs(tx_0a6a_input_tuples)
        print_inputs(tx_0a6a_sorted_input_tuples)
 
@@ -99,7 +102,7 @@ def main():
                # (prev_tx_hash_byte_arr_little_endian, prev_tx_output_index)
                ([0x55, 0x60, 0x5d, 0xc6, 0x5f, 0x3c, 0xcc, 0x4d, 0xb1, 0xd8, 0x56, 0x4a, 0x28, 0x04, 0x2b, 0xdb, 0x2c, 0x2b, 0xe3, 0x85, 0xea, 0xb2, 0xeb, 0xea, 0x41, 0x19, 0xee, 0x9c, 0x26, 0x8d, 0x28, 0x35], 0),
                ([0x55, 0x60, 0x5d, 0xc6, 0x5f, 0x3c, 0xcc, 0x4d, 0xb1, 0xd8, 0x56, 0x4a, 0x28, 0x04, 0x2b, 0xdb, 0x2c, 0x2b, 0xe3, 0x85, 0xea, 0xb2, 0xeb, 0xea, 0x41, 0x19, 0xee, 0x9c, 0x26, 0x8d, 0x28, 0x35], 1)] #duplicate prev_tx_hash
-
+       print("\ntx 28204cad1d7fc1d199e8ef4fa22f182de6258a3eaafe1bbe56ebdcacd3069a5f")
        tx_2820_sorted_input_tuples = sort_inputs(tx_2820_input_tuples)
        print_inputs(tx_2820_sorted_input_tuples)

jonatack avatar Aug 22 '25 21:08 jonatack

@jonatack updated

prestoalvarez avatar Aug 22 '25 21:08 prestoalvarez

Pinging BIP authors @kristovatlas @dcousens for feedback / sign-off.

jonatack avatar Aug 22 '25 22:08 jonatack

@prestoalvarez it would be good to update the file permissions, e.g. with chmod 755 bip-0069_examples.py, and either squash your commits or give clear naming for each of them.

jonatack avatar Aug 22 '25 23:08 jonatack

@jonatack

prestoalvarez avatar Sep 01 '25 10:09 prestoalvarez

@prestoalvarez the commit message looks good, and thank you for squashing. Would be good if you can update the file permissions, please, e.g. with chmod 755 bip-0069_examples.py, and then would be good to see approval of the change by the BIP authors.

jonatack avatar Sep 01 '25 14:09 jonatack

@jonatack

prestoalvarez avatar Sep 07 '25 20:09 prestoalvarez

@jonatack maybe merge?

prestoalvarez avatar Sep 19 '25 17:09 prestoalvarez

@prestoalvarez we would normally want to see approval of this fix and update by BIP69 authors @kristovatlas @dcousens.

jonatack avatar Sep 19 '25 19:09 jonatack