Yep... there is a bug in there somewhere...
Try the following
from bitcoin import *
serialize_script(deserialize_script('ac'))
---
RuntimeError: maximum recursion depth exceeded while calling a Python object
Yeh, I often run scripts on iOS Pythonista, and there's a lot of recursion errors that come up since by default the recursion depth is 256; so setting
sys.setrecursiondepth(512) often works in that environment.
The
pybitcointools bug is strange because the code serializes multisig scripts, but there's a bug with the CHECKMULTISIG; so instead of serializing the 'ae', it just appends 'ae' to the end of the returned string.
I am looking at using this code:
def mk_script(*args):
# lst = ['76', 'a9', '14', 'dd6cce9f255a8cc17bda8ba0373df8e861cb866e', '88', 'ac']
if len(args) == 1 and isinstance(args[0], (list, tuple))
lst = list(args[0])
elif len(args) > 1 and all(map(lambda o: isinstance(o, str), args)):
lst = [args]
else:
lst = [changebase(str(x), 10, 16, 2) if isinstance(x, (int, long)) else x for x in args]
llens = [len(changebase(x, 16, 256, 1)) for x in lst] # byte lengths
lint = map(lambda h: decode(h, 16), lst) # list as ints
asm = 0xff
for i in range(len(lint)):
asm = asm << (8*llens[i]) | lint[i]
asmhex = "0x" + encode(asm, 16, (sum(llens) + 1)*2)
final = asmhex.partition('0xff')[-1]
return final
How would I go about tweaking this code to avoid the manual addition of
push20?
ie. I want to use
mk_script(['76', 'a9', 'dd6cce9f255a8cc17bda8ba0373df8e861cb866e', '88', 'ac'])
... instead of
mk_script(['76', 'a9', '14', 'dd6cce9f255a8cc17bda8ba0373df8e861cb866e', '88', 'ac'])
(note the "14" preceding the pubkeyhash, which acts as
push 20 bytes).
I'd prefer to avoid using the push bytes