Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes signature_form for SIGHASH_SINGLE and SIGHAS_NONE. #163

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions bitcoin/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,24 @@ def signature_form(tx, i, script, hashcode=SIGHASH_ALL):
if hashcode == SIGHASH_NONE:
newtx["outs"] = []
elif hashcode == SIGHASH_SINGLE:
newtx["outs"] = newtx["outs"][:len(newtx["ins"])]
for out in newtx["outs"][:len(newtx["ins"]) - 1]:
out['value'] = 2**64 - 1
out['script'] = ""
if i >= len(newtx["outs"]):
raise Exception("You are trying to use SIGHASH_SINGLE to sign an input that does not have a "
"corresponding output (" + str(i) + "). This could lead to a irreversible lose "
"of funds. Signature process aborted.")
else:
newtx["outs"] = newtx["outs"][:i+1]
for out in newtx["outs"][:i]:
out["value"] = 2**64 - 1
out["script"] = ""
elif hashcode == SIGHASH_ANYONECANPAY:
newtx["ins"] = [newtx["ins"][i]]
else:
pass

if hashcode in [SIGHASH_NONE, SIGHASH_SINGLE]:
for inp in xrange(len(newtx["ins"])):
if inp is not i:
newtx["ins"][inp]['sequence'] = 0
return newtx

# Making the actual signatures
Expand Down