I'm trying to convert Python 2 script to Python 3 and I'm stuck with Struct()
, what I'm doing wrong?
I think the problem is with Struct()
but I don't see where is the problem.
Error
Traceback (most recent call last):
File "C:\Users\xxx.py", line 206, in <module>
main()
File "C:\Users\xxx.py", line 15, in main
tx = create_transaction(input_script, output_script, options)
File "C:\Users\xxx.py", line 77, in create_transaction
Bytes("version", 4),
TypeError: __init__() takes 2 positional arguments but 3 were given
function
import hashlib, binascii, struct, array, os, time, sys, optparse
import scrypt
from construct import *
def create_transaction(input_script, output_script, options):
transaction = Struct("transaction",
Bytes("version", 4), <-- line 77
Byte("num_inputs"),
StaticField("prev_output", 32),
UBInt32('prev_out_idx'),
Byte('input_script_len'),
Bytes('input_script', len(input_script)),
UBInt32('sequence'),
Byte('num_outputs'),
Bytes('out_value', 8),
Byte('output_script_len'),
Bytes('output_script', 0x43),
UBInt32('locktime'))
tx = transaction.parse(b'\x00'*(127 + len(input_script)))
tx.version = struct.pack('<I', 1)
tx.num_inputs = 1
tx.prev_output = struct.pack('<qqqq', 0,0,0,0)
tx.prev_out_idx = 0xFFFFFFFF
tx.input_script_len = len(input_script)
tx.input_script = input_script
tx.sequence = 0xFFFFFFFF
tx.num_outputs = 1
tx.out_value = struct.pack('<q' ,options.value)#0x000005f5e100)#012a05f200) #50 coins
#tx.out_value = struct.pack('<q' ,0x000000012a05f200) #50 coins
tx.output_script_len = 0x43
tx.output_script = output_script
tx.locktime = 0
return transaction.build(tx)
User contributions licensed under CC BY-SA 3.0