diff --git a/genesis.py b/genesis.py index 1eacc15..3e2a8f0 100644 --- a/genesis.py +++ b/genesis.py @@ -54,19 +54,22 @@ def get_algorithm(options): sys.exit("Error: Given algorithm must be one of: " + str(supported_algorithms)) def create_input_script(psz_timestamp): - psz_prefix = "" + timestamp_bytes = psz_timestamp.encode('utf-8') + psz_prefix = '' #use OP_PUSHDATA1 if required - if len(psz_timestamp) > 76: psz_prefix = '4c' + if len(timestamp_bytes) > 76: psz_prefix = '4c' - script_prefix = '04ffff001d0104' + psz_prefix + chr(len(psz_timestamp)).encode('hex') - print (script_prefix + psz_timestamp.encode('hex')) - return (script_prefix + psz_timestamp.encode('hex')).decode('hex') + length_in_hex = hex(len(timestamp_bytes))[2:] + script_prefix = '04ffff001d0104' + psz_prefix + length_in_hex + input_script_hex = script_prefix + timestamp_bytes.hex() + print(input_script_hex) + return bytes.fromhex(input_script_hex) def create_output_script(pubkey): script_len = '41' OP_CHECKSIG = 'ac' - return (script_len + pubkey + OP_CHECKSIG).decode('hex') + return bytes.fromhex(script_len + pubkey + OP_CHECKSIG) def create_transaction(input_script, output_script,options): @@ -84,7 +87,7 @@ def create_transaction(input_script, output_script,options): Bytes('output_script', 0x43), UBInt32('locktime')) - tx = transaction.parse('\x00'*(127 + len(input_script))) + tx = transaction.parse(b'\x00'*(127 + len(input_script))) tx.version = struct.pack('