Skip to content

Commit

Permalink
bitcoin/txn: Safety check: Throw NotImplementedError if segwit transa…
Browse files Browse the repository at this point in the history
…ction data is encountered rather than handling it incorrectly
  • Loading branch information
luke-jr committed Jan 29, 2016
1 parent 39b9b3a commit c7b02df
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
12 changes: 11 additions & 1 deletion bitcoin/txn.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ def __init__(self, data=None, txid=None):
if txid:
self.txid = txid
else:
self.idhash()
try:
self.idhash()
except NotImplementedError:
pass

@classmethod
def new(cls):
Expand All @@ -52,6 +55,9 @@ def addOutput(self, amount, pkScript):
self.outputs.append( (amount, pkScript) )

def disassemble(self, retExtra = False):
if self.data[4:6] == b'\0\1':
raise NotImplementedError

self.version = unpack('<L', self.data[:4])[0]
rc = [4]

Expand Down Expand Up @@ -118,6 +124,10 @@ def assemble(self):
self.idhash()

def idhash(self):
if self.data[4:6] == b'\0\1':
if hasattr(self, 'txid'):
del self.txid
raise NotImplementedError
self.txid = dblsha(self.data)

# Txn tests
Expand Down
1 change: 1 addition & 0 deletions merklemaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ def URI2Access(uri):
def createClearMerkleTree(self, height):
subsidy = self.SubsidyAlgo(height)
cbtxn = self.makeCoinbaseTxn(subsidy, False)
cbtxn.setCoinbase(b'\0\0') # necessary to avoid triggering segwit marker+flags
cbtxn.assemble()
return MerkleTree([cbtxn])

Expand Down

0 comments on commit c7b02df

Please sign in to comment.